feat(reframe): chain the camera-inset layout behind the screen decision
Tried first as a fourth option for the classifier, and it does not work: on the 5 corpus clips that have a composited webcam, Gemini answered "screencast" on all 5, in both runs, and overall accuracy fell from 92% to 85% and 83%. 3 options 44/48 92% screen preserved 17/20 none intact 27/28 4 options c1 41/48 85% 18/20 28/28 4 options c2 40/48 83% 18/20 28/28 Read that carefully: the fourth option did no HARM (zero regressions across the 28 that must not be touched, and it actually preserved the screen on one more). It simply never got the new class right. Whether a webcam rectangle is present is a geometric question, and the detector answers it 5 of 5 with no false positives. So the split is: Gemini decides what the video is, geometry decides the framing. If the decision is "screencast" and camera_inset finds a rectangle, that layout is used; otherwise full width. Verified end to end: figma -> screencast + inset on 4 scenes; excel (presenter composited full-screen, no rectangle) -> full width, as before.
This commit is contained in:
parent
9ed025d1c6
commit
f88d843fda
4 changed files with 59 additions and 9 deletions
10
CLAUDE.md
10
CLAUDE.md
|
|
@ -135,6 +135,16 @@ se desactiva porque el modelo diga `none`.
|
|||
content, so SCREENCAST stacks it over the presenter. Above 0.85 the presenter
|
||||
is composited **on top of** the content and stacking would show it twice, so
|
||||
those scenes get WIDE: the GENERAL layout with side-cropping disabled.
|
||||
- **INSET Mode** (`camera_inset.py`): pantalla a ancho completo arriba, el
|
||||
recuadro de la webcam ampliado abajo. Para el caso de una sola fuente con la
|
||||
cámara compuesta en una esquina (OBS, VOD de stream). Se encadena detrás de
|
||||
la decisión `screencast`, **no** se le pregunta a Gemini: ofrecido como cuarta
|
||||
opción respondió `screencast` en los 5 clips que tienen recuadro, en dos
|
||||
pasadas, y la exactitud global cayó de 92% a 83-85%. El detector geométrico
|
||||
encuentra esos 5 sin falsos positivos. Los tres filtros que hacen falta, cada
|
||||
uno pagado con una iteración: sujeto **pequeño**, **descentrado en
|
||||
horizontal** (una cara de talking head está centrada aunque esté alta), y
|
||||
**quieto entre muestras** (3-11px frente a 316px de una persona real).
|
||||
- **ALTERNATE Mode** (`active_speaker.py`, `SPEAKER_SIGNAL=1` + `SPEAKER_CUT=1`):
|
||||
hard cuts to whoever is talking, rendered through the TRACK path as a
|
||||
trajectory with jumps. `SPEAKER_SIGNAL=1` alone just gates SPLIT on both people
|
||||
|
|
|
|||
|
|
@ -30,7 +30,15 @@ CORNER_MARGIN = 0.20 # a subject this far from an edge (as a fraction of the
|
|||
# thrown out. Measured on four real clips, these two properties separate the
|
||||
# cases where "touching a corner" did not.
|
||||
MAX_SUBJECT_HEIGHT = 0.35 # fraction of frame height
|
||||
MIN_OFFSET = 0.18 # centre-to-centre distance, fraction of frame
|
||||
|
||||
# Horizontal offset from centre, as a fraction of frame width. HORIZONTAL
|
||||
# specifically: a composited camera is pinned to the left or right side, while a
|
||||
# talking head is centred left-to-right even when their face sits high in the
|
||||
# shot. Accepting offset on either axis let four talking heads through, all of
|
||||
# them with a face near the top edge. Measured on those nine candidates the two
|
||||
# groups do not overlap: real insets sat 0.37-0.43 from centre, the talking
|
||||
# heads 0.01-0.12.
|
||||
MIN_OFFSET = 0.18
|
||||
|
||||
# How much bigger than the detected head/upper body the inset is assumed to be.
|
||||
# A webcam frames head and shoulders, and detectors return the head or the upper
|
||||
|
|
@ -78,8 +86,7 @@ def is_cornered(box, frame_w, frame_h, margin=CORNER_MARGIN):
|
|||
return False
|
||||
|
||||
cx = (x + w / 2.0) / frame_w
|
||||
cy = (y + h / 2.0) / frame_h
|
||||
off_centre = abs(cx - 0.5) >= MIN_OFFSET or abs(cy - 0.5) >= MIN_OFFSET
|
||||
off_centre = abs(cx - 0.5) >= MIN_OFFSET
|
||||
|
||||
near_edge = (x <= frame_w * margin or (x + w) >= frame_w * (1 - margin)
|
||||
or y <= frame_h * margin or (y + h) >= frame_h * (1 - margin))
|
||||
|
|
|
|||
|
|
@ -103,10 +103,16 @@ Pick ONE layout:
|
|||
music, and any footage whose meaning survives a centre crop. Corner logos,
|
||||
score bugs, subscriber counters, lower-thirds and burned-in subtitles do NOT
|
||||
change this: they are decoration, and losing them costs nothing.
|
||||
- "screencast": put the screen content on top and the presenter below. ONLY when
|
||||
the video is built around a screen recording, slides, a spreadsheet, a chart
|
||||
or a map that the viewer must read to follow it. If you cannot read words or
|
||||
numbers off the screen that matter to the point being made, it is not this.
|
||||
- "screencast": keep the screen. ONLY when the video is built around a screen
|
||||
recording, slides, a spreadsheet, a chart or a map that the viewer must read
|
||||
to follow it. If you cannot read words or numbers off the screen that matter
|
||||
to the point being made, it is not this.
|
||||
(A "camera_inset" option was added here and removed on 31-jul-2026. Whether a
|
||||
webcam is composited into a corner of that screen is not something the model
|
||||
can see: on the five clips that have one it answered "screencast" every time,
|
||||
in both runs, while overall accuracy fell from 92% to 83-85%. camera_inset.py
|
||||
finds the same five geometrically with no false positives, so that question is
|
||||
answered downstream instead of being asked here.)
|
||||
- "split": stack two people. ONLY when two people are visible IN THE SAME SHOT
|
||||
at the same time in most frames, talking to each other. Frames that alternate
|
||||
between one-person close-ups are NOT this, however many people appear.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import subprocess
|
|||
import tempfile
|
||||
|
||||
import active_speaker
|
||||
import camera_inset
|
||||
import punch_in
|
||||
import screencast_layout
|
||||
import split_layout
|
||||
|
|
@ -190,7 +191,7 @@ def _analyze_trajectory(input_video, scenes_boundaries, scene_strategies,
|
|||
# whole scene), so like GENERAL they need no camera trajectory.
|
||||
# ALTERNATE gets one written in after this pass.
|
||||
if strategy in ('GENERAL', 'SPLIT', 'SCREENCAST', 'WIDE',
|
||||
'ALTERNATE'):
|
||||
'INSET', 'ALTERNATE'):
|
||||
cameraman.current_center_x = orig_w / 2
|
||||
cameraman.target_center_x = orig_w / 2
|
||||
xs.append(None)
|
||||
|
|
@ -298,22 +299,45 @@ def render(input_video, final_output_video, aspect_ratio, content_ranges=None):
|
|||
# SCREENCAST wins over SPLIT on the rare scene that qualifies for both: two
|
||||
# faces beside a chart still means the chart is what the shot is about, and
|
||||
# stacking the two speakers would crop it away entirely.
|
||||
# A screen with a webcam composited into a corner gets its own layout, and
|
||||
# the question "is there an inset" is settled geometrically rather than by
|
||||
# asking Gemini: offered as a fourth choice it answered "screencast" on all
|
||||
# five clips that had one, while camera_inset.detect finds all five with no
|
||||
# false positives. The box is fixed for the whole video, so it is found once.
|
||||
inset = None
|
||||
if content_ranges and screencast_layout.ENABLED:
|
||||
try:
|
||||
inset = camera_inset.detect(input_video)
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Inset check failed ({e}) — using the screen layouts.")
|
||||
if inset:
|
||||
print(f" 📹 Webcam inset at {inset}")
|
||||
|
||||
screencasts = {}
|
||||
wide_count = 0
|
||||
inset_count = 0
|
||||
if content_ranges:
|
||||
for scene_idx, (plan, centre) in screencast_layout.detect_screencast_scenes(
|
||||
input_video, scenes, strategies, content_ranges).items():
|
||||
# An inset beats both screen plans: it is the only one that can show
|
||||
# the screen whole AND the person at a readable size.
|
||||
if inset:
|
||||
plan, centre = 'INSET', None
|
||||
strategies[scene_idx] = plan
|
||||
start_f = scene_boundaries[scene_idx][0]
|
||||
splits.pop(start_f, None)
|
||||
if plan == 'SCREENCAST':
|
||||
screencasts[start_f] = centre
|
||||
elif plan == 'INSET':
|
||||
inset_count += 1
|
||||
else:
|
||||
wide_count += 1
|
||||
if screencasts:
|
||||
print(f" 🖥️ SCREENCAST layout on {len(screencasts)} scene(s)")
|
||||
if wide_count:
|
||||
print(f" 📐 Full-width layout on {wide_count} scene(s)")
|
||||
if inset_count:
|
||||
print(f" 📹 Camera-inset layout on {inset_count} scene(s)")
|
||||
|
||||
# The crop geometry comes from the SOURCE dims only — SmoothedCameraman
|
||||
# derives crop_width/crop_height from video_width/video_height and never
|
||||
|
|
@ -359,7 +383,10 @@ def render(input_video, final_output_video, aspect_ratio, content_ranges=None):
|
|||
ss = start_f / fps
|
||||
dur = (end_f - start_f) / fps
|
||||
|
||||
if strategy == 'SCREENCAST':
|
||||
if strategy == 'INSET':
|
||||
graph = camera_inset.inset_filtergraph(
|
||||
orig_w, orig_h, out_w, out_h, inset)
|
||||
elif strategy == 'SCREENCAST':
|
||||
graph = screencast_layout.screencast_filtergraph(
|
||||
orig_w, orig_h, out_w, out_h, screencasts[start_f])
|
||||
elif strategy == 'WIDE':
|
||||
|
|
|
|||
Loading…
Reference in a new issue