videogen/docs/reelforge/editing-suite/videogen_to_wolfcut.py
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

181 lines
6.1 KiB
Python

#!/usr/bin/env python3
"""Adapter STUB: videogen/ReelForge generated clip -> WolfCut timeline project.
Phase-1 proof-of-direction for EDITING-SUITE-PLAN.md. This is the smallest
possible seam between videogen's AI *generation* and WolfCut's *edit* engine:
it wraps one finished job clip (an R2 URL / local path + probe metadata) into a
minimal ``wolfcut.json`` document that the WolfCut engine (``wolfcut-project``)
already round-trips.
STATUS: documented stub, deliberately NOT wired into any build, worker, or the
FastAPI app. Stdlib only. It does not delete or mutate anything. When the suite
gains an "Open in editor" action, call ``build_wolfcut_project(...)`` on job
completion and hand the result to the WolfCut engine's project-load path
(not the CLI).
Schema source of truth (do not drift from these):
videogen/wolfcut/engine/crates/wolfcut-project/src/model.rs (serde camelCase)
videogen/wolfcut/engine/crates/wolfcut-project/src/doc.rs (top-level shape)
Top-level document (doc.rs): media, tracks, clips, fonts, timelines, settings.
Note the engine writes BOTH the active timeline's tracks/clips at the top level
AND the full timelines[] array; we mirror that so the document loads meaningfully.
"""
from __future__ import annotations
import argparse
import json
import os
from dataclasses import dataclass
@dataclass(frozen=True)
class GeneratedClip:
"""A finished videogen job output, as the API/worker would describe it.
``src`` is an R2 URL or absolute local path; the rest is probe metadata
videogen already has from the compose stage (it renders 1080x1920 MP4).
"""
src: str
width: int = 1080
height: int = 1920
fps: float = 30.0
duration: float | None = None
name: str = "Generated reel"
has_audio: bool = True
video_codec: str = "h264"
audio_codec: str | None = "aac"
def _media_item(clip: GeneratedClip, media_id: str) -> dict:
"""One entry in the WolfCut media bin (model.rs::MediaItem)."""
return {
"id": media_id,
"path": clip.src, # engine treats path as the source ref (URL or disk)
"name": clip.name,
"duration": clip.duration,
"kind": "video", # MediaKind::Video
"width": clip.width,
"height": clip.height,
"frameRate": clip.fps,
"frameRateFraction": None,
"videoCodec": clip.video_codec,
"audioCodec": clip.audio_codec,
"hasAudio": clip.has_audio,
# `placeholder` omitted: skip_serializing_if=false keeps it byte-clean.
}
def _video_track(track_id: str) -> dict:
"""A single video lane (model.rs::Track)."""
return {"id": track_id, "name": "Video 1", "visible": True, "muted": False}
def _clip(clip: GeneratedClip, clip_id: str, track_id: str, media_id: str) -> dict:
"""One placed clip filling its media (model.rs::Clip). All edit knobs at
their unity/neutral defaults so the clip renders exactly as generated."""
duration = clip.duration if clip.duration is not None else 0.0
return {
"id": clip_id,
"trackId": track_id,
"mediaId": media_id,
"name": clip.name,
"kind": "video", # ClipKind::Video
"start": 0.0,
"duration": duration,
"sourceStart": 0.0,
"volume": 1.0,
"fadeIn": 0.0,
"fadeOut": 0.0,
"scale": 1.0,
"offsetX": 0.0,
"offsetY": 0.0,
"rotation": 0.0,
"opacity": 1.0,
"speed": 1.0,
"preservePitch": True,
"filters": [],
"videoEffects": [],
# Optional fields (muted/detachedFrom/transitionIn/text) omitted:
# skip_serializing_if=Option::is_none keeps the doc minimal.
}
def build_wolfcut_project(clip: GeneratedClip) -> dict:
"""Wrap one generated clip into a minimal, load-ready WolfCut document.
Returns a dict matching the doc.rs top-level shape: one media item, one
video track, one clip, and one active timeline (plus mirrored top-level
tracks/clips, as the engine writes them).
"""
media_id, track_id, clip_id, timeline_id = "m1", "T1", "c1", "TL1"
media = [_media_item(clip, media_id)]
tracks = [_video_track(track_id)]
clips = [_clip(clip, clip_id, track_id, media_id)]
timeline = {
"id": timeline_id,
"name": "Timeline 1",
"tracks": tracks,
"clips": clips,
}
return {
"media": media,
"tracks": tracks, # top-level mirror of the active timeline (doc.rs)
"clips": clips, # top-level mirror of the active timeline (doc.rs)
"fonts": [],
"timelines": [timeline],
"settings": {
"width": clip.width,
"height": clip.height,
"frameRate": clip.fps,
},
}
def _parse_args(argv: list[str] | None = None) -> argparse.Namespace:
p = argparse.ArgumentParser(
description="Wrap a videogen generated clip into a WolfCut project (stub).",
)
p.add_argument("--url", "--src", dest="src", required=True,
help="R2 URL or absolute local path to the generated clip")
p.add_argument("--width", type=int, default=1080)
p.add_argument("--height", type=int, default=1920)
p.add_argument("--fps", type=float, default=30.0)
p.add_argument("--duration", type=float, default=None)
p.add_argument("--name", default="Generated reel")
p.add_argument("--out", default="-",
help="output .wolfcut.json path, or '-' for stdout")
return p.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = _parse_args(argv)
clip = GeneratedClip(
src=args.src,
width=args.width,
height=args.height,
fps=args.fps,
duration=args.duration,
name=args.name,
)
project = build_wolfcut_project(clip)
text = json.dumps(project, indent=2)
if args.out == "-":
print(text)
else:
# Explicit, additive write only to the caller-chosen path.
with open(os.path.abspath(args.out), "w", encoding="utf-8") as fh:
fh.write(text + "\n")
print(f"wrote {os.path.abspath(args.out)}")
return 0
if __name__ == "__main__":
raise SystemExit(main())