Media Depth
Context: $ARGUMENTS
Monocular depth estimation — estimate a per-pixel depth map from a single RGB image or video, no stereo rig or LiDAR required. Two actively maintained open-source model families with commercial-safe licenses: Depth-Anything v2 (Apache 2.0, current SOTA, 2024) and MiDaS v3.1 (MIT, Intel ISL, long-standing baseline).
Quick start
- Depth map from a photo (PNG): → Step 3 (
depth.py image --model depthanything-v2) - Depth sequence from a video: → Step 4 (
depth.py video) - 2D photo → side-by-side stereo 3D pair: → Step 5 (
depth.py stereo --baseline 6.5) - Animate a 2.5D parallax / Ken Burns shot from a still: → Step 6 (
depth.py parallax --frames 30) - Pre-download model weights: → Step 2 (
depth.py install <model>)
When to use
- Need a Z-depth pass to hand to Blender, Nuke, Fusion, After Effects, or Unreal (compositing, DoF, fog).
- Converting flat 2D footage to side-by-side / over-under stereo 3D without reshooting.
- Producing parallax / 2.5D / "Ken Burns" motion from stills for social reels or lyric videos.
- Building a pseudo-LiDAR point cloud for photogrammetry, volumetric capture prep, or robotics dev.
- Any workflow where "metric depth in meters" is not required — both default models here return relative / inverse depth normalized 0–1. For metric depth, read
references/models.mdon Depth-Anything v2 metric fine-tunes. - Not for real-time (<10 ms) embedded use — pick MiDaS-small for the fastest CPU path but even that is ~50 ms on a modern laptop at 384 px.
Step 1 — Install PyTorch + transformers
Depth-Anything v2 is distributed via HuggingFace transformers using the pipeline("depth-estimation", ...) API — no custom model code required. MiDaS also works through transformers (using the DPTForDepthEstimation class).
PEP 723 header in scripts/depth.py declares the full dependency set. Running via uv run handles an ephemeral venv. Manual install:
pip install torch transformers opencv-python numpy pillow
On Apple Silicon, PyTorch picks MPS automatically when you set device="mps". On NVIDIA, device="cuda". The helper auto-selects.
Verify the runtime:
uv run ${CLAUDE_SKILL_DIR}/scripts/depth.py install depthanything-v2 --size small
Downloads the depth-anything/Depth-Anything-V2-Small-hf weights (~100 MB) into ~/.cache/huggingface/hub/.
Step 2 — Pick a model
| Model | License | Variants | Relative/Metric | Notes |
|-----------------------------|---------------|-----------------------------------|-----------------|--------------------------------------------------|
| depthanything-v2 (default)| Apache 2.0 | small / base / large | Relative (inverse depth) | SOTA 2024, crisper edges than v1; metric fine-tunes exist for indoor/outdoor |
| midas | MIT | dpt-swinv2-tiny-256 / dpt-beit-large-512 | Relative | Intel ISL v3.1, older, still robust |
Pick by size vs accuracy:
depthanything-v2 --size small— ~25 M params, ~40 fps 1080p on a 3090depthanything-v2 --size base— ~97 M params, ~20 fpsdepthanything-v2 --size large— ~335 M params, ~8 fps, sharpest edges
Full per-model speed, VRAM, and license matrix in references/models.md. Read it when picking a model for batch video or embedded deployment.
Step 3 — Depth map from a single image
uv run ${CLAUDE_SKILL_DIR}/scripts/depth.py image \
--model depthanything-v2 --size small \
--in photo.jpg --out depth.png
Outputs a 16-bit single-channel PNG where 0 = far, 65535 = near (the HuggingFace pipeline yields "inverse depth", higher = closer). Also writes depth_preview.png — a turbo-colormap 8-bit visualization for human inspection.
Useful flags:
--out-format npy— rawfloat32numpy.npy(best fidelity for VFX tools)--out-format exr— 32-bit EXR (requiresopencv-pythonbuilt with OpenEXR; otherwise installpip install OpenEXR imathor use the.npypath and convert withvfx-oiio/ffmpeg-ocio-colorpro)--invert— flip so that0= near,65535= far (Blender / most DCCs expect this)
Step 4 — Per-frame depth for video
uv run ${CLAUDE_SKILL_DIR}/scripts/depth.py video \
--model depthanything-v2 --size small \
--in input.mp4 --out depth.mp4
Writes a grayscale H.264 MP4 at the source fps where each pixel encodes depth (8-bit). For compositing fidelity prefer:
--out-format png-seq --out depth_frames/ # 16-bit PNG sequence, frame_%06d.png
--out-format exr-seq --out depth_exr/ # 32-bit EXR sequence (best for Nuke)
Gotcha: per-frame monocular depth is temporally unstable — the depth of a static object can flicker frame-to-frame. Use --smooth temporal for a light 3-tap EMA across frames, or hand the output to ffmpeg-denoise-restore (hqdn3d on the grayscale depth track) before consuming it downstream.
Step 5 — 2D → stereo 3D (depth-driven parallax)
uv run ${CLAUDE_SKILL_DIR}/scripts/depth.py stereo \
--model depthanything-v2 --size base \
--in photo.jpg \
--out-left left.png --out-right right.png \
--baseline 6.5
--baseline is the interpupillary-distance shift in pixels (or millimeters at 96 dpi — it's an opinionated single scalar). Typical values:
3.0— subtle parallax for phone viewing6.5— the physical human IPD in mm; gives a natural "window" look12.0— exaggerated for VR / anaglyph
The occlusion-aware parallax math (forward-warp with depth-sorted Z-buffer, then inpaint revealed background) is documented in references/parallax-math.md — read it when you need to tune the quality / hole-filling trade-off.
Pack side-by-side for a 3D TV / Meta Quest:
ffmpeg -i left.png -i right.png -filter_complex hstack sbs.png
Step 6 — Animate a 2.5D parallax shot (Ken Burns style)
uv run ${CLAUDE_SKILL_DIR}/scripts/depth.py parallax \
--image photo.jpg --depth depth.png \
--out parallax.mp4 \
--frames 120 --fps 30 \
--motion orbit --amplitude 40
--motion presets:
orbit— smooth circular camera orbit (best default)zoom— dolly in toward the nearest planepan-left/pan-right— horizontal slide with depth-correct parallaxken-burns— slow zoom + slight pan
--amplitude is the max pixel shift of the nearest foreground. Values 20–80 work well for 1080p stills. Hole-fill is done via OpenCV INPAINT_TELEA on the revealed background — the reference doc covers why TELEA beats NS for this specific use case.
If you have both the --image and --depth already, parallax is a pure post-process (no model inference). Chain it after Step 3.
Available scripts
scripts/depth.py— subcommands:image,video,stereo,parallax,install. Each supports--dry-run,--verbose,--device {auto,cpu,cuda,mps}.