diff --git a/pipeline.py b/pipeline.py
index d025054..4f6b7cd 100644
--- a/pipeline.py
+++ b/pipeline.py
@@ -2,16 +2,10 @@
"""
End-to-end pipeline for converting 2D videos to spatial 3D videos.
-Pipeline stages:
-1. Downscale input video to 1080p @ 24fps
-2. Generate depth maps using Depth Anything V2
-3. Create side-by-side stereoscopic video
-4. Convert to MV-HEVC spatial video using spatial CLI
-
Usage:
- python pipeline.py input_video.mp4 -o output_spatial.mov
- python pipeline.py input_video.mp4 --encoder vitb --max-disparity 40
- python pipeline.py /path/to/folder # Process all videos in folder
+ spatial-maker video.mp4
+ spatial-maker /path/to/folder
+ spatial-maker video.mp4 --encoder l --max-disparity 40
"""
import argparse
@@ -23,21 +17,14 @@ import shutil
from scripts.downscale_video import downscale_to_1080p24
from scripts.depth_to_stereo import process_video_to_sbs
-# Video formats to process when given a folder
VIDEO_EXTENSIONS = {".mp4", ".mov", ".avi", ".mkv", ".m4v", ".webm", ".wmv", ".flv"}
-
-# Encoder name mapping (CLI shorthand -> model name)
ENCODER_MAP = {"s": "vits", "m": "vitb", "l": "vitl"}
def check_spatial_cli():
"""Check if the spatial CLI is available."""
try:
- result = subprocess.run(
- ["spatial", "--version"],
- capture_output=True,
- text=True,
- )
+ result = subprocess.run(["spatial", "--version"], capture_output=True, text=True)
return result.returncode == 0
except FileNotFoundError:
return False
@@ -60,66 +47,35 @@ def run_pipeline(
keep_intermediate: bool = False,
skip_downscale: bool = False,
duration: float = None,
- quiet: bool = False,
):
- """
- Run the full 2D to spatial video conversion pipeline.
-
- Args:
- input_video: Path to input 2D video
- output_path: Path for output spatial video (default: input_spatial.mov)
- encoder: Depth Anything V2 encoder (vits, vitb, vitl)
- max_disparity: Maximum pixel disparity for 3D effect (20-50 for 1080p)
- keep_intermediate: Keep intermediate files (depth frames, SBS video)
- skip_downscale: Skip downscaling if input is already 1080p24
- duration: Optional duration limit in seconds
- quiet: Suppress stage headers (for batch processing)
-
- Returns:
- Path to the output spatial video
- """
+ """Run the full 2D to spatial video conversion pipeline."""
input_path = Path(input_video)
if not input_path.exists():
raise FileNotFoundError(f"Input video not found: {input_video}")
- # Set up output paths
if output_path is None:
output_path = Path("output") / f"{input_path.stem}_spatial.mov"
else:
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
-
- # Create working directory for intermediate files
work_dir = output_path.parent / f"{output_path.stem}_work"
work_dir.mkdir(exist_ok=True)
- def print_stage(msg):
- if not quiet:
- print(msg)
-
try:
- # Stage 1: Downscale to 1080p @ 24fps
- print_stage("\n" + "=" * 60)
- print_stage("Stage 1: Preparing input video (1080p @ 24fps)")
- print_stage("=" * 60)
-
+ # Stage 1: Downscale
if skip_downscale:
prepared_video = str(input_path)
- print_stage(f" Skipping downscale, using: {prepared_video}")
else:
+ print("↓ Downscaling to 1080p24...")
prepared_video = downscale_to_1080p24(
str(input_path),
output_path=str(work_dir / f"{input_path.stem}_1080p.mp4") if duration else None,
duration=duration,
)
- print_stage(f" Prepared video: {prepared_video}")
-
- # Stage 2: Generate depth and create SBS stereoscopic video
- print_stage("\n" + "=" * 60)
- print_stage(f"Stage 2: Depth estimation + SBS stereo (encoder: {encoder}, disparity: {max_disparity})")
- print_stage("=" * 60)
+ # Stage 2: Depth + SBS
+ print(f"◐ Generating depth & stereo (encoder={encoder[-1]}, disparity={max_disparity})...")
sbs_video = work_dir / f"{input_path.stem}_sbs.mp4"
max_frames = int(duration * 24) if duration else None
sbs_result = process_video_to_sbs(
@@ -130,53 +86,30 @@ def run_pipeline(
fps=24,
max_frames=max_frames,
)
- print_stage(f" Processed {sbs_result['frames_processed']} frames")
- print_stage(f" SBS video: {sbs_result['output_path']}")
-
- # Stage 3: Convert to spatial video using spatial CLI
- print_stage("\n" + "=" * 60)
- print_stage("Stage 3: Converting to MV-HEVC spatial video")
- print_stage("=" * 60)
+ # Stage 3: Spatial video
+ print("◉ Creating spatial video...")
if not check_spatial_cli():
- print(" WARNING: 'spatial' CLI not found!")
- print(" Install from: https://blog.mikeswanson.com/spatial")
- print(f" SBS video ready at: {sbs_result}")
- print(" Run manually: spatial make --sbs -o