From 9c220efddb1a5f42bff246e7c23ca844d58e0ab3 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Wed, 19 Aug 2026 01:06:48 +0200 Subject: [PATCH] feat(editor): manual framing override (auto / full frame / track subject) The scene classifier only counts faces, so a screencast-style video with a presenter in frame gets TRACK and the crop eats the slide (the SCREENCAST/ WIDE detectors sit behind the opt-in layouts=auto flag). The clip editor now has a framing selector that pins every scene's layout: 'full' renders the whole source frame (WIDE: no side-crop, blurred bands), 'track' forces the subject-tracking crop, 'auto' returns to the classifier. Plumbed as force_strategy through reframe_v2.render -> render_clip -> perform_recut -> /api/clip/rerender (and the recut_clip MCP tool). A non-auto choice always re-reframes from the retained source (409 without it) and persists in the clip's recipe, so later plain trims inherit the look instead of silently reverting; an explicit 'auto' resets it. Verified live: framing=full on a TRACK-cropped clip re-rendered with the full frame visible edge to edge (125s source path), and the editor reopens with the persisted choice preselected. --- app.py | 31 ++++++++++++-- dashboard/src/components/ClipEditor.jsx | 56 +++++++++++++++++++++++-- main.py | 18 +++++--- mcp_server.py | 10 ++++- recut.py | 11 ++++- reframe_v2.py | 15 ++++++- tests/test_rerender_endpoint.py | 49 ++++++++++++++++++++++ 7 files changed, 173 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index a0f84e5..b525f18 100644 --- a/app.py +++ b/app.py @@ -2267,6 +2267,7 @@ async def get_clip_edl(job_id: str, clip_index: int, request: Request): "clip_index": clip_index, "title": clip.get('video_title_for_youtube_short') or '', "segments": segments, + "framing": (clip.get('recipe') or {}).get('framing') or 'auto', "canonical_range": canonical_range, "duration": total, "current_file": current_file, @@ -2299,6 +2300,15 @@ class RerenderRequest(BaseModel): segments: List[RerenderSegment] snap_to_words: bool = False reapply_captions: bool = True + # None = inherit the recipe's framing (so plain trims keep the look); + # 'auto' resets to the classifier; 'full'/'track' force a layout. + framing: Optional[str] = None + + +# Manual framing -> reframe-engine strategy. 'full' shows the whole source +# frame (WIDE: no side-cropping, blurred filler bands); 'track' forces the +# subject-tracking crop. Anything non-auto needs the retained source video. +_FRAMING_STRATEGIES = {"auto": None, "full": "WIDE", "track": "TRACK"} # One lock per job (same pattern as _restore_locks): rerenders on the same job @@ -2356,6 +2366,12 @@ async def _rerender_locked(req: RerenderRequest, request: Request, job): source_path = _locate_source(req.job_id) source_duration = _source_duration_seconds(source_path) if source_path else None + framing = req.framing or (clip.get('recipe') or {}).get('framing') or 'auto' + if framing not in _FRAMING_STRATEGIES: + raise HTTPException(status_code=400, + detail="framing must be one of: auto, full, track") + force_strategy = _FRAMING_STRATEGIES[framing] + try: segments = recut.normalize_segments( [{"start": s.start, "end": s.end} for s in req.segments], @@ -2379,14 +2395,19 @@ async def _rerender_locked(req: RerenderRequest, request: Request, job): except recut.RecutError as e: raise HTTPException(status_code=400, detail=str(e)) - fast = (os.path.exists(canonical_path) + # A framing override always re-reframes from the source: the canonical file + # has the old layout baked into its pixels. + fast = (force_strategy is None + and os.path.exists(canonical_path) and recut.within_range(segments, canonical_range['start'], canonical_range['end'])) if not fast and not source_path: raise HTTPException( status_code=409, - detail="The source video is no longer on the server, so segments " - "must stay within the original clip range.") + detail=("The source video is no longer on the server; changing the " + "framing needs it." if force_strategy is not None else + "The source video is no longer on the server, so segments " + "must stay within the original clip range.")) total = recut.total_duration(segments) rerender_minutes = (max(1, math.ceil(total / 60.0)) @@ -2410,6 +2431,7 @@ async def _rerender_locked(req: RerenderRequest, request: Request, job): output_dir=output_dir, clean_name=clean_name, reframe=True, output_format=data.get('output_format', 'auto'), watermark=bool(job.get('watermark')), + force_strategy=force_strategy, captions_transcript=v_transcript) try: @@ -2419,6 +2441,8 @@ async def _rerender_locked(req: RerenderRequest, request: Request, job): new_video_url = f"/videos/{req.job_id}/{served_name}" new_recipe = {"v": 1, "segments": segments, "canonical_range": canonical_range} + if framing != 'auto': + new_recipe["framing"] = framing # Covering range, deliberately not segments[0]/segments[-1]: segments # may legally be out of source order, and downstream consumers only # need a sane positive window (the recipe is the real timeline). @@ -2442,6 +2466,7 @@ async def _rerender_locked(req: RerenderRequest, request: Request, job): "success": True, "new_video_url": new_video_url, "recipe": new_recipe, + "framing": framing, "start": new_start, "end": new_end, "duration": total, diff --git a/dashboard/src/components/ClipEditor.jsx b/dashboard/src/components/ClipEditor.jsx index 1fa057b..ba6b70f 100644 --- a/dashboard/src/components/ClipEditor.jsx +++ b/dashboard/src/components/ClipEditor.jsx @@ -92,6 +92,9 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const [snapToWords, setSnapToWords] = useState(true); const [reapplyCaptions, setReapplyCaptions] = useState(true); + // Framing override: 'auto' (classifier) | 'full' (whole frame) | 'track'. + const [framing, setFraming] = useState('auto'); + const [renderedFraming, setRenderedFraming] = useState('auto'); // The recipe of the currently RENDERED preview (playhead maps onto it). const [renderedSegments, setRenderedSegments] = useState(null); const [previewUrl, setPreviewUrl] = useState(null); @@ -120,6 +123,8 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer setEdl(data); dispatch({ type: 'init', segments: data.segments.map((s) => ({ ...s })) }); setRenderedSegments(data.segments.map((s) => ({ ...s }))); + setFraming(data.framing || 'auto'); + setRenderedFraming(data.framing || 'auto'); setReapplyCaptions(true); setPreviewUrl(getApiUrl(`/videos/${jobId}/${data.current_file}`)); } catch (e) { @@ -139,8 +144,9 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const total = totalOf(segments); const dirty = useMemo(() => { if (!renderedSegments) return false; - return JSON.stringify(segments) !== JSON.stringify(renderedSegments); - }, [segments, renderedSegments]); + return JSON.stringify(segments) !== JSON.stringify(renderedSegments) + || framing !== renderedFraming; + }, [segments, renderedSegments, framing, renderedFraming]); // Trim bounds: with the source gone, cuts must stay inside the range the // canonical file was rendered from. @@ -152,11 +158,13 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer (seg) => !sourceAvailable && (seg.start < canonical.start - 0.05 || seg.end > canonical.end + 0.05), [sourceAvailable, canonical], ); - const needsSourcePath = segments.some((s) => s.start < canonical.start - 0.05 || s.end > canonical.end + 0.05); + const needsSourcePath = framing !== 'auto' + || segments.some((s) => s.start < canonical.start - 0.05 || s.end > canonical.end + 0.05); const invalidSegments = segments.some(outOfRange); const overCaps = segments.length > limits.max_segments || total > limits.max_total_seconds; const canRender = !rendering && segments.length > 0 && !invalidSegments && !overCaps - && segments.every((s) => s.end - s.start >= minSeg); + && segments.every((s) => s.end - s.start >= minSeg) + && (framing === 'auto' || sourceAvailable); // ---- helpers ------------------------------------------------------------ const snapEdge = useCallback((t, kind) => { @@ -367,6 +375,7 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer segments: segments.map((s) => ({ start: s.start, end: s.end })), snap_to_words: false, // boundaries are already word-snapped client-side reapply_captions: reapplyCaptions, + framing, }), }); if (!res.ok) { @@ -376,6 +385,8 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer } const data = await res.json(); setRenderedSegments(data.recipe.segments.map((s) => ({ ...s }))); + setRenderedFraming(data.framing || 'auto'); + setFraming(data.framing || 'auto'); dispatch({ type: 'init', segments: data.recipe.segments.map((s) => ({ ...s })) }); setPreviewUrl(`${getApiUrl(data.new_video_url)}?t=${Date.now()}`); onRerendered?.(clipIndex, data); @@ -550,6 +561,43 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer + {/* framing override */} +
+

Framing

+
+ {[ + { value: 'auto', label: 'auto', hint: 'AI decides per scene' }, + { value: 'full', label: 'full frame', hint: 'whole shot, no side-crop' }, + { value: 'track', label: 'track subject', hint: 'crop follows the person' }, + ].map((f) => ( + + ))} +
+ {!sourceAvailable && ( +

+ framing changes need the source video, which is no longer on the server +

+ )} + {framing !== renderedFraming && ( +

+ changing the framing re-runs the reframe engine (slower than a fast recut) +

+ )} +
+ {/* toggles */}