feat(layouts): dashboard layout selector, layouts=none, ranges survive a fast recut

- Advanced options gain "vertical layout": auto (server default, AI picks
  per video), two speakers stacked, screen over presenter, or single crop
  only. Only a deliberate choice travels as `layouts`; remembered in
  localStorage like the hook settings.
- `layouts=none` switches the picker off for one job even though the
  deployment runs AUTO_LAYOUT=1.
- The fast rerender (cut without reframe) wrote no layout sidecar, so a
  stacked clip fell back to bottom captions after a trim. It now carries the
  canonical clip's ranges through the new cut (layout_ranges.remap).
This commit is contained in:
juancarlos.cavero 2026-08-25 15:45:19 +02:00
parent b308f6e00e
commit fd0e39862c
7 changed files with 114 additions and 4 deletions

View file

@ -87,9 +87,13 @@ answers describe the paid product as free.
### Cómo se elige el layout
`POST /api/process` acepta `layouts`: una lista (JSON) o cadena separada por
comas con `auto`, `split`, `screencast`, `speaker_cut`, `punch_in`. Cada nombre
enciende su variable de entorno para **ese** trabajo (`app.py:layout_env`); sin
`layouts` el pipeline se comporta exactamente como antes.
comas con `auto`, `split`, `screencast`, `speaker_cut`, `punch_in` y `none`.
Cada nombre enciende su variable de entorno para **ese** trabajo
(`app.py:layout_env`); `none` apaga el picker aunque prod corra con
`AUTO_LAYOUT=1` (recorte simple y nada más). Sin `layouts` manda el env del
despliegue, que desde el 25-ago-2026 es `AUTO_LAYOUT=1`. El dashboard lo expone
en opciones avanzadas ("vertical layout": auto / split / screencast / none,
`MediaInput.jsx`, recordado en `localStorage.os_layout`).
`auto` activa `layout_picker.py`: **una** llamada a Gemini por vídeo de origen
(no por clip) que elige entre `none` / `screencast` / `split`. Medido sobre el
@ -131,7 +135,9 @@ se desactiva porque el modelo diga `none`.
`subtitles.generate_ass`), the one place they cover nobody; the render
records which stretches are stacked in a `<clip>.layout.json` sidecar
(`layout_ranges.py`) and every metadata writer copies it into the clip's
`layout_ranges`, so `/api/subtitle` finds it after a restyle too. Only the
`layout_ranges`, so `/api/subtitle` finds it after a restyle too. The fast
rerender (cut without reframe) carries the canonical clip's ranges through
the new cut (`layout_ranges.remap`, in `recut.perform_recut`). Only the
ASS path can do this; SRT burns keep one alignment for the whole file.
- **SCREENCAST / WIDE Modes** (`screencast_layout.py`, `SCREENCAST_LAYOUT=1`):
for scenes whose meaning lives outside the centre. Gemini reports each range's

6
app.py
View file

@ -1899,6 +1899,9 @@ def layout_env(requested):
The special value "auto" hands the choice to Gemini (one call per video).
It composes with explicit picks: layout_picker only ever adds, so asking for
"auto,punch_in" means "decide the layout yourself, and punch in regardless".
"none" is the opposite: it switches the picker OFF for this job even when
the deployment runs with AUTO_LAYOUT=1, for the user who wants the plain
single crop and nothing clever.
"""
env = {}
for name in requested or []:
@ -1906,6 +1909,9 @@ def layout_env(requested):
if key == "auto":
env["AUTO_LAYOUT"] = "1"
continue
if key == "none":
env["AUTO_LAYOUT"] = "0"
continue
var = LAYOUT_ENV.get(key)
if not var:
continue

View file

@ -779,6 +779,8 @@ function App() {
// but the dashboard always states the user's choice.
auto_hook: data.autoHook ? '1' : '0',
auto_hook_style: data.autoHook ? (data.autoHookStyle || 'classic') : null,
// 'auto' is the server default, so only a deliberate choice travels.
layouts: data.layout && data.layout !== 'auto' ? data.layout : null,
};
if (data.type === 'url') {

View file

@ -30,6 +30,12 @@ export default function MediaInput({ onProcess, isProcessing }) {
const [autoHookStyle, setAutoHookStyle] = useState(() => {
try { return localStorage.getItem('os_auto_hook_style') || 'classic'; } catch { return 'classic'; }
});
// Layout: 'auto' lets the AI pick per video (server default); the others
// force one on so a podcast host who knows what they uploaded doesn't
// depend on the detector, and 'none' keeps the plain single crop.
const [layout, setLayout] = useState(() => {
try { return localStorage.getItem('os_layout') || 'auto'; } catch { return 'auto'; }
});
const infoRef = useRef(null);
// Close the compatibility popover on any outside click.
@ -78,10 +84,12 @@ export default function MediaInput({ onProcess, isProcessing }) {
clipMaxSeconds: clipMaxSeconds || null,
autoHook,
autoHookStyle,
layout,
};
try {
localStorage.setItem('os_auto_hook', autoHook ? '1' : '0');
localStorage.setItem('os_auto_hook_style', autoHookStyle);
localStorage.setItem('os_layout', layout);
} catch { /* ignore */ }
if (mode === 'url' && url) {
onProcess({ type: 'url', payload: url, acknowledged: true, outputFormat, ...advanced });
@ -286,6 +294,20 @@ export default function MediaInput({ onProcess, isProcessing }) {
Targets, not guarantees: the AI returns fewer clips when the
material doesn't hold them. Leave blank to let it decide.
</p>
<div className="col-span-1 sm:col-span-3 flex flex-wrap items-center justify-between gap-3 pt-3 sm:pt-1 border-t border-rule">
<span className="text-xs text-ink2">vertical layout</span>
<select
value={layout}
onChange={(e) => setLayout(e.target.value)}
className="input-field !w-auto text-xs py-1.5"
aria-label="vertical layout"
>
<option value="auto">Auto (AI picks per video)</option>
<option value="split">Two speakers stacked</option>
<option value="screencast">Screen over presenter</option>
<option value="none">Single crop only</option>
</select>
</div>
<div className="col-span-1 sm:col-span-3 flex flex-wrap items-center justify-between gap-3 pt-3 sm:pt-1 border-t border-rule">
<label className="flex items-center gap-2 text-xs text-ink2 cursor-pointer select-none">
<input

View file

@ -73,3 +73,29 @@ def split_ranges(ranges):
def in_split(t, splits):
return any(s <= t < e for s, e in splits or [])
def remap(ranges, segments):
"""Carry ranges across a cut-and-concat. ``segments`` are the kept
stretches of the SOURCE file in order ({"start", "end"}); the output is
those segments back to back, so each range is clipped to every segment it
overlaps and shifted to where that segment landed. This is what the fast
rerender needs: it never reframes, so the only layout information it can
have is the canonical clip's, seen through the new cut."""
out = []
offset = 0.0
for seg in segments or []:
try:
seg_s, seg_e = float(seg["start"]), float(seg["end"])
except (KeyError, TypeError, ValueError):
continue
if seg_e <= seg_s:
continue
for r in normalise(ranges):
s, e = max(r["start"], seg_s), min(r["end"], seg_e)
if e > s:
out.append({"start": round(s - seg_s + offset, 3),
"end": round(e - seg_s + offset, 3),
"layout": r["layout"]})
offset += seg_e - seg_s
return out

View file

@ -313,6 +313,13 @@ def perform_recut(*, input_path, segments, output_dir, clean_name,
raise RuntimeError("reframe failed on the recut clip")
else:
shutil.move(work_path, out_path)
# No reframe means no fresh layout sidecar; the captions would fall
# back to the bottom on a stacked clip. Carry the input's layout
# ranges through the cut instead (empty when the input has none).
import layout_ranges
layout_ranges.write(out_path, [
(r["start"], r["end"], r["layout"])
for r in layout_ranges.remap(layout_ranges.read(input_path), segments)])
if watermark:
(watermarker or _main_attr("apply_watermark"))(out_path)

View file

@ -90,3 +90,44 @@ class TestCaptionerReadsSidecar:
monkeypatch.setattr(subtitles, "generate_ass", fake_generate_ass)
main.auto_caption_clip(clip, _transcript([(" a", 0.0, 0.5)]), 0.0, 3.0)
assert seen["split_ranges"] == [(0.0, 3.0)]
class TestRemapAcrossCut:
def test_ranges_follow_the_kept_segments(self):
ranges = [(0, 10, "split"), (10, 20, "track"), (20, 30, "split")]
# Keep 5-12 and 22-30 of the source: output is 0-7 then 7-15.
segs = [{"start": 5, "end": 12}, {"start": 22, "end": 30}]
got = layout_ranges.remap(ranges, segs)
assert got == [
{"start": 0.0, "end": 5.0, "layout": "split"},
{"start": 5.0, "end": 7.0, "layout": "track"},
{"start": 7.0, "end": 15.0, "layout": "split"},
]
assert layout_ranges.split_ranges(got) == [(0.0, 5.0), (7.0, 15.0)]
def test_no_input_ranges_means_none(self):
assert layout_ranges.remap([], [{"start": 0, "end": 5}]) == []
def test_fast_recut_carries_the_sidecar(self, tmp_path, monkeypatch):
import shutil
import recut
src = tmp_path / "canon.mp4"
src.write_bytes(b"x")
layout_ranges.write(str(src), [(0, 4, "SPLIT"), (4, 8, "TRACK")])
# Stand in for ffmpeg: the "cut" is a copy.
monkeypatch.setattr(recut, "run_cut_concat",
lambda i, segs, out, wd, runner=None: shutil.copy(i, out))
served, clean = recut.perform_recut(
input_path=str(src), segments=[{"start": 2, "end": 6}],
output_dir=str(tmp_path), clean_name="c.mp4", reframe=False)
assert layout_ranges.read(str(tmp_path / clean)) == [
{"start": 0.0, "end": 2.0, "layout": "split"},
{"start": 2.0, "end": 4.0, "layout": "track"}]
class TestLayoutEnvNone:
def test_none_switches_the_picker_off_for_the_job(self):
app_module = pytest.importorskip("app")
assert app_module.layout_env(["none"]) == {"AUTO_LAYOUT": "0"}
assert app_module.layout_env(["auto"]) == {"AUTO_LAYOUT": "1"}
assert app_module.layout_env(["split"])["SPLIT_LAYOUT"] == "1"