How vveicao/freeorbit4d works
1. What this repository is
FreeOrbit4D is a multi-stage pipeline for turning a single monocular video into a foreground-complete 4D reconstruction and then re-rendering that scene from new camera trajectories. The top-level product is an output video under outputs/.../rendering/.../inference/output_video.mp4, plus optional interactive 4D visualization artifacts.
2. Top-level orchestration boundary
The main entrypoint is run_pipeline.py, which dispatches into pipeline/full_pipeline.py or stage-specific pipeline modules in pipeline/. This is the primary architecture boundary: the repo is organized as a pipeline controller above a set of processing/rendering subsystems.
3. Pipeline stages
The pipeline is explicitly split into:
- stage_0_pipeline.py: initial video/data preparation
- stage_1_pipeline.py: reconstruction
- stage_1a_pointcloud_pipeline.py: point-cloud-centric processing
- stage_1b_rendering_pipeline.py: view synthesis / rendering
- stage_2_pipeline.py: final generation/refinement
This division mirrors the repo’s scripts (scripts/0_*, scripts/1_*, scripts/2_*) and makes the data flow easy to diagram as a left-to-right multi-stage DAG.
4. Input preparation and scene configuration
Inputs are either bundled demos under demo/ or user videos configured through YAML files in configs/. Scene configs describe the input media, masks, trajectory settings, and output naming. For custom videos, scripts/prep_interactive_mask.py provides a Gradio-based annotation tool to create the foreground mask and a scene config in configs/user/.
5. Stage 0: multiview generation and data preparation
The scripts/0_0_gen_multiviews.py and scripts/0_1_data_preparation.py steps, together with core/data_processor.py and core/multiview.py, handle the conversion from raw video to structured frame data suitable for later geometry processing. This is where the repo likely establishes per-frame image sets, masks, and any multi-view or pseudo-view inputs needed by downstream models.
6. Stage 1: reconstruction core
The reconstruction subsystem is centered in core/:
- core/alignment.py aligns estimated geometry/camera outputs
- core/pointcloud.py manages 3D/4D point cloud representation
- core/rendering.py handles image synthesis from reconstructed geometry
- core/data_processor.py and core/multiview.py feed the reconstruction logic
This is the main geometry boundary: raw video/masks in, aligned 4D proxy out.
7. Foreground/background separation
The repo makes the foreground a first-class component. Scripts 1_0_run_foreground.py and 1_1_run_background.py indicate that reconstruction is split into foreground and background tracks, likely because the method is designed around a single fully visible foreground subject. The README’s input constraints reinforce that this is a major architectural assumption, not just a usage detail.
8. Alignment and point-cloud fusion
scripts/1_2_align.py, scripts/1_2_visualization.py, and core/alignment.py suggest a dedicated stage for consolidating estimated poses/structure into a coherent scene representation. The architecture here is: model outputs → geometric alignment → fused point cloud / 4D proxy → visualization or rendering. The visualization script provides an inspection boundary between reconstruction and downstream synthesis.
9. Trajectory authoring and rendering
Camera redirection is handled by scripts/1_3_cam_traj.py and scripts/1_4_rendering.py. The trajectory editor is interactive and produces JSON camera paths that are later consumed by the rendering stage. This cleanly separates:
- trajectory design
- reconstruction reuse
- final video rendering
So re-rendering can skip reconstruction entirely via --resume_from render.
10. Stage 2: generative refinement
scripts/2_0_Wan2.2-VACE-Fun-A14B.py and the vendored generative-models/ directory indicate a later synthesis/refinement step that uses external generative video tooling. Architecturally, this is an optional downstream generation layer sitting on top of the reconstructed/rendered scene, not part of the core geometric reconstruction path.
11. Model implementation stack
The page-4d/ subtree contains a substantial VGGT-based model implementation, duplicated in two variants:
- page-4d/vggt/
- page-4d/vggt_t_mask_mlp_fin10/
These include transformer layers, tracking heads, camera heads, depth heads, aggregators, and geometry utilities. This subtree is the learned-model boundary of the system: backbone, task heads, and tracking/camera estimation are encapsulated here rather than in the pipeline code.
12. External dependencies and vendored components
The repository includes submodules and vendored code for major external systems:
- DiffSynth-Studio/
- generative-models/
- page-4d/vggt/dependency/
These are used to avoid depending on live upstream APIs during execution. The README also references pretrained checkpoints for VGGT/SAM2/Wan2.2-VACE and other model dependencies, so checkpoint availability is part of the runtime architecture.
13. Shared utilities
utils/ contains cross-cutting infrastructure: config loading, camera math, depth utilities, video/image I/O, point-cloud helpers, logging, seeding, and trajectory helpers. These are not a distinct stage, but they define the common data contracts passed between pipeline modules and scripts.
14. Repository structure for reproducibility
The configs/scenes/ folder, demo/ inputs, assets/ visuals, docs/ usage guides, and download_checkpoints.sh together form the operational layer of the architecture. They are what make the pipeline reproducible: the code expects a prepared scene directory, specific checkpoints, and well-formed config files to move data cleanly from raw input to reconstruction to rerendered output.
Main entry points: stage_1_pipeline.py Stage 1 · full_pipeline.py Full pipeline · stage_0_pipeline.py Stage 0 · run_pipeline.py Run pipeline
Components 24
Orchestration
Top-level entrypoints and pipeline dispatch.
- Run pipeline · Main command-line entry for selecting the full or stage-specific pipeline.
run_pipeline.py - Full pipeline · Coordinates the end-to-end multi-stage processing flow.
pipeline/full_pipeline.py
Pipeline stages
Stage-by-stage video-to-4D processing and rendering.
- Stage 0 · Initial video and data preparation stage.
pipeline/stage_0_pipeline.py - Stage 1 · Primary reconstruction stage.
pipeline/stage_1_pipeline.py - Pointcloud stage · Point-cloud-centric reconstruction and fusion stage.
pipeline/stage_1a_pointcloud_pipeline.py - Rendering stage · View synthesis and rendering stage.
pipeline/stage_1b_rendering_pipeline.py - Stage 2 · Final generative refinement or downstream synthesis stage.
pipeline/stage_2_pipeline.py - Mask prep · Gradio-based tool for interactive mask creation and scene config setup.
scripts/prep_interactive_mask.py - Camera traj · Interactive camera-path authoring for rerendering.
scripts/1_3_cam_traj.py - Render run · Consumes trajectories and reconstructed scene data to generate the output video.
scripts/1_4_rendering.py
Geometry core
Shared reconstruction, alignment, and rendering logic.
- Data proc · Converts raw video and masks into structured frame-level inputs.
core/data_processor.py - Multiview · Builds multiview or pseudo-view inputs for downstream geometry estimation.
core/multiview.py - Alignment · Aligns model outputs into a coherent scene representation.
core/alignment.py - Point cloud · Represents the reconstructed 3D/4D proxy geometry.
core/pointcloud.py - Core render · Renders images from the reconstructed geometry and camera state.
core/rendering.py
Learned models
VGGT-based model implementations used by reconstruction.
- VGGT model · Main learned reconstruction model wrapper.
page-4d/vggt/models/vggt.py - Track head · Predicts feature tracks used for geometry recovery.
page-4d/vggt/heads/track_head.py - Camera head · Estimates camera parameters and pose-related outputs.
page-4d/vggt/heads/camera_head.py - ViT layers · Transformer and attention layers used by the VGGT stack.
page-4d/vggt/layers/vision_transformer.py
External stacks
Vendored or external components used downstream or as dependencies.
- DiffSynth · Vendored external synthesis stack used for downstream generation.
DiffSynth-Studio - Gen models · Bundled generative video tooling for refinement or synthesis.
generative-models
Support code
Shared config, camera, and trajectory utilities.
- Config · Loads and interprets scene and pipeline configuration.
utils/config.py - Camera utils · Camera and projection helpers shared across stages.
utils/camera.py - Trajectory utils · Helpers for camera trajectory representation and conversion.
utils/trajectory.py
Connections 32
- Run pipeline → Full pipeline: dispatches · Entry point selects and launches the full pipeline.
- Run pipeline → Stage 0: dispatches · Entry point can invoke stage-specific execution.
- Run pipeline → Stage 1: dispatches · Entry point can invoke stage-specific execution.
- Run pipeline → Rendering stage: dispatches · Entry point can invoke stage-specific execution.
- Full pipeline → Stage 0: runs · Full pipeline begins with data preparation.
- Full pipeline → Stage 1: runs · Full pipeline proceeds into reconstruction.
- Full pipeline → Pointcloud stage: runs · Full pipeline includes point-cloud-centric processing.
- Full pipeline → Rendering stage: runs · Full pipeline includes rendering synthesis.
- Full pipeline → Stage 2: runs · Full pipeline can continue into refinement.
- Stage 0 → Mask prep: uses · Stage 0 depends on prepared masks and scene setup for custom videos.
- Stage 0 → Data proc: uses · Stage 0 prepares frame data and masks.
- Stage 0 → Multiview: uses · Stage 0 constructs multiview inputs.
- Stage 1 → VGGT model: uses · Reconstruction is driven by the learned VGGT model.
- Stage 1 → Track head: uses · Model predicts tracks as part of reconstruction.
- Stage 1 → Camera head: uses · Model estimates camera outputs for geometry recovery.
- Stage 1 → ViT layers: uses · Transformer backbone underpins the model stack.
- Stage 1 → Alignment: feeds · Raw model outputs are aligned into a coherent scene.
- Pointcloud stage → Point cloud: updates · Point-cloud stage manages the scene proxy representation.
- Pointcloud stage → Alignment: feeds · Alignment consolidates foreground and background geometry.
- Rendering stage → Core render: uses · Rendering stage synthesizes output views from reconstructed data.
- Camera traj → Trajectory utils: uses · Interactive editor produces camera path data.
- Camera traj → Config: uses · Trajectory authoring is scene-config driven.
- Render run → Core render: uses · Rendering script calls shared synthesis logic.
- Render run → Camera utils: uses · Rendering consumes camera trajectory and projection helpers.
- Core render → Point cloud: reads · Renderer consumes the fused scene proxy.
- Alignment → Point cloud: produces · Alignment fuses estimates into the point-cloud representation.
- Data proc → Camera utils: uses · Scene preparation relies on camera and projection utilities.
- VGGT model → Track head: contains · VGGT bundles tracking outputs.
- VGGT model → Camera head: contains · VGGT bundles pose and camera estimation outputs.
- VGGT model → ViT layers: built on · VGGT is implemented on transformer backbone layers.
- Stage 2 → Gen models: uses · Final refinement relies on bundled generative tooling.
- Stage 2 → DiffSynth: uses · Downstream synthesis may call into the vendored external stack.