Skip to main content
Glama
README.md
# reframe360

An MCP server and CLI for reframing raw Insta360 X6/X5/X4 360° footage (`.lrv` proxies and 8K `.insv` originals) directly from dual-fisheye video—with 1000 Hz IMU horizon lock, rolling-shutter compensation, and DaVinci Resolve Fusion export.

Built so AI agents (or scripts) can inspect a 360° sphere visually, choose camera moves, render stabilized 16:9 or 9:16 shots, and hand keyframes to DaVinci Resolve without clicking through Insta360 Studio.

## Demo

[![reframe360 before and after demo](docs/demo-preview.gif)](https://github.com/joshp123/reframe360/releases/download/v0.2.0/reframe360-demo-before-after.mp4)

*Click the preview for the full 1080p 25fps video with audio ([docs/demo-before-after.mp4](docs/demo-before-after.mp4) · [release download](https://github.com/joshp123/reframe360/releases/download/v0.2.0/reframe360-demo-before-after.mp4)).*

**What you are seeing:** raw dual-fisheye `.lrv` clips straight off an Insta360 X6 swinging on a selfie stick (top left, flat I-Log, tilting sideways), converted in real time into a horizon-locked 360° sphere with an animated rectilinear viewport box gliding across the `±90°` dual-lens seam (bottom left), and raycast in one pass into a stabilized, LUT-graded 16:9 shot (right).

### Before vs After (same raw frame)

![Before vs After coastal waves](docs/before-after.jpg)

Exact same frame from a raw Insta360 X6 `.lrv` file: an unstabilized stitch with a tilted horizon, hard seam, and flat I-Log on the left; `reframe360` with 1000 Hz IMU horizon lock, MEI dual-fisheye Laplacian blending, and Rec.709 LUT on the right.

### 3-stage pipeline

![reframe360 3-stage pipeline](docs/pipeline.jpg)

### How an agent picks camera angles (`inspect_sphere`)

![reframe360 inspect_sphere contact sheet](docs/inspect-sphere.jpg)

Instead of guessing yaw and pitch numbers blind, an agent calls `inspect_sphere` over MCP. The tool returns this horizon-locked equirectangular contact sheet inline as a JPEG—with yaw/pitch lines, red `±90°` dual-lens seam markers, and the exact yellow rectilinear viewport crop box for proposed keyframes. Once the framing looks right, the agent renders the final clip with `reframe_clip` or exports Bezier keyframes to DaVinci Resolve with `export_resolve_fusion`.

## What it does

- **Factory MEI dual-fisheye stitching (`insta360_meta.py`):** Reads the Insta360 v3 binary trailer (`offset_v3`), extracts both lenses' 56-token MEI calibration and extrinsics, and raycasts rectilinear frames straight from both fisheye sensors in one pass. Uses symmetric overlap gain matching and 3-level Laplacian pyramid blending to avoid hard stitch seams.
- **1000 Hz IMU horizon lock + rolling shutter:** Reads the embedded 1000 Hz 6-DOF IMU stream (Record `0x03`), exact per-frame exposure timestamps (Records `0x04` and `0x0c`), and vertical readout time (protobuf field 25). Uses centrifugal-gated zero-phase gravity leveling (resistant to fast selfie-stick swings) and 8-band per-row rolling shutter compensation. Supports `world` (locked heading) and `follow` (smooth yaw glide) modes.
- **Visual sphere scouting (`inspect_sphere`):** Renders a horizon-locked equirectangular contact sheet with yaw, pitch, and dual-lens seam overlays, plus an optional rectilinear crop-box preview of proposed keyframes. Over MCP, returns the contact sheet inline as an image.
- **Keyframed reframing (`reframe_clip`):** Smooth camera moves using C2 smootherstep (2 keyframes) or monotone cubic PCHIP with optional Gaussian trajectory smoothing (3+ keyframes). Supports `.cube` 3D LUTs (such as Insta360's official `I-Log` to Rec.709 LUT) or a built-in Rec.2020-aware I-Log preview grade.
- **DaVinci Resolve Fusion export (`export_resolve_fusion`):** Writes a Resolve Fusion `.setting` macro (`SphereMap` → `Shape3D` → `Camera3D` → `Renderer3D` with `BezierSpline` keyframes) for GPU-accelerated finishing.
- **0.1-second cut QC (`inspect_cuts`):** Generates 10 fps filmstrips (`-0.3s` to `+0.3s`) around cut boundaries and checks EBU R128 loudness (`ebur128`).

## Requirements

- Python 3.10+
- `ffmpeg` and `ffprobe` on `PATH` (or set `FFMPEG` / `FFPROBE` environment variables)

## MCP setup

Run directly with `uvx` (zero manual install):

```json
{
  "mcpServers": {
    "reframe360": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/joshp123/reframe360",
        "reframe360-mcp"
      ]
    }
  }
}
```

Or install into a Python environment and point your MCP client at `reframe360-mcp`:

```bash
pip install git+https://github.com/joshp123/reframe360
```

### MCP tools

| Tool | Purpose |
| --- | --- |
| `inspect_clip_metadata` | Camera model, resolution, layout (`side_by_side` / `dual_track`), fps, duration, IMU rate, rolling shutter ms |
| `inspect_sphere` | Horizon-locked equirectangular contact sheet with yaw/pitch/seam grid + optional keyframe crop box (returns inline JPEG) |
| `reframe_clip` | Render stabilized rectilinear 16:9 or 9:16 MP4 directly from `.lrv` or `.insv` |
| `export_resolve_fusion` | Export a DaVinci Resolve Fusion `.setting` macro with `BezierSpline` camera keyframes |
| `inspect_cuts` | Render 0.1s cut-boundary strips and EBU R128 loudness summary (returns inline JPEGs) |

## CLI usage

```bash
# 1. Read clip metadata and IMU/calibration info
reframe360 clip-info clip.lrv

# 2. Render a horizon-locked 360° sphere sheet with yaw/pitch/seam grid
reframe360 inspect-sphere clip.lrv sphere.jpg --count 6

# 3. Preview proposed keyframes as a rectilinear crop box on the sphere
reframe360 inspect-sphere clip.lrv sphere_check.jpg \
  --keyframes '[{"t":1.0,"yaw":118,"pitch":-4,"fov":86},{"t":7.0,"yaw":148,"pitch":2,"fov":78}]'

# 4. Render a seamless 16:9 (or 9:16) stabilized clip
reframe360 reframe clip.lrv out.mp4 \
  --keyframes '[{"t":1.0,"yaw":118,"pitch":-4,"fov":86},{"t":7.0,"yaw":148,"pitch":2,"fov":78}]' \
  --width 1280 --height 720 --mode world --lut X6_I-Log_To_Rec.709.cube

# 5. Export a DaVinci Resolve Fusion comp
reframe360 export-resolve \
  '[{"t":1.0,"yaw":118,"pitch":-4,"fov":86},{"t":7.0,"yaw":148,"pitch":2,"fov":78}]' \
  move.setting --fps 25 --width 1920 --height 1080

# 6. Inspect cut boundaries at 0.1s resolution + EBU R128 loudness
reframe360 inspect-cuts final.mp4 qc_dir/
```

## License

MIT

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool targets a clearly distinct artifact or stage: metadata inspection, visual sphere preview, video reframing, Resolve macro export, and cut/loudness inspection. Even the three inspect_* tools are separated by their output type and purpose, so an agent can select among them without meaningful ambiguity.

Naming Consistency4/5

All names use snake_case and begin with an action verb, producing a predictable verb_object pattern. The object phrases vary in compoundness, especially inspect_clip_metadata and export_resolve_fusion, but the convention remains readable and consistent overall.

Tool Count5/5

Five tools is well scoped for a focused Insta360 reframing pipeline, with each tool corresponding to a meaningful stage or deliverable. There is no obvious bloat or missing basic operation that would suggest a count mismatch.

Completeness4/5

The surface covers the core workflow: inspect source metadata, preview sphere angles, render a keyframed reframe, export to Resolve, and review cuts with loudness checks. Minor gaps remain, such as explicit keyframe-management or batch-processing operations and audio correction rather than only loudness inspection, but these are workable gaps.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues