Skip to content

feat(onscreen): sample, classify and group on-screen text - #19

Open
anthony-hermes[bot] wants to merge 8 commits into
masterfrom
wt/onscreen-core
Open

anthony-hermes[bot] wants to merge 8 commits into
masterfrom
wt/onscreen-core

Conversation

@anthony-hermes

@anthony-hermes anthony-hermes Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Lane 10, the part that needs no model: sampling, classification, grouping and the engine seam.

  • OcrEngine protocol with a provider property, and a fake in the tests.
  • Sampling at 1 fps from zero to the last whole second of the duration, never past it.
  • Classification: a fragment whose normalised text equals recognised speech in the same second is a dialogue caption and is discarded; a fragment whose words merely appear inside a longer segment is a card of its own. A caption the recogniser split across two segments still matches, because the segments of the second are joined and compared as well.
  • Grouping: identical text on consecutive frames is one card, first frame to last, held 2200 to 8000 ms. Every card stops 100 ms before the next card that starts later; cards that share a start frame are not clamped against each other, and all of them stop before that later card.
  • Attribution cards open with a credit label: one to three credit words in sequence (Photo Credit, Image Source, 자료 출처, 사진제공), an optional plural s on the Latin ones, leading decoration ignored. The label only counts when a separator, by, the end of the card, or (for a Hangul label ending in 출처 or 제공) a space and the credited party follows. They are kept with kind = attribution, excluded from translation, and counted in QA; a caption that merely contains a credit word (Resource Center, Photo Zone, Video Zone) stays a graphic.
  • Atomic onscreen.json writer, and an off engine that writes an empty list plus a QA note.

Scope. git diff --name-only origin/master...HEAD is seven src/subsmith/onscreen/ files and three tests/onscreen/ files, and nothing else. The pipeline test-suite trim that travelled on this branch has moved out of this PR to #23 (test/behavior-only); every tests/pipeline/ file here is master's copy.

Merged master. git merge origin/master (c732ff2) resolved tests/pipeline/test_cues.py, test_prompt.py and test_speakers.py by taking master's copy, which restores the MAX_DIALOGUE_LINES assertions master added and the glossary-blocked test. No conflict markers remain and git merge-tree --write-tree origin/master HEAD reports no conflict.

Review pass 1 findings, fixed on this branch.

  • PR-001 Attribution was a substring test over the whole card, so Resource Center and Photo Zone were treated as credits and left untranslated. It is now a compiled pattern anchored at the start of the card with a required separator, by, or end.
  • PR-002 The collision clamp compared each card only with the next card in the list, so with two fragments on frame 0 and one at 1000, one same-frame card fell to 900 ms and the other overlapped the later card. Each card is now clamped against the next start time strictly greater than its own, found by bisect over the distinct start times.
  • PR-003 Dialogue classification used containment, so a nameplate Kim was dropped during a second whose speech was Kim arrived at the station. It compares for equality now, against each segment and against the joined segments of the second.

Each fix carries a test that fails on the old behaviour: test_a_caption_that_only_contains_a_credit_word_is_a_graphic, test_same_frame_cards_each_stop_before_a_later_card, test_a_graphic_whose_text_occurs_inside_speech_is_kept, and test_a_caption_split_across_two_segments_matches_the_joined_speech.

Review pass 2 finding, fixed on this branch.

  • PR-004 The anchored rule was the false-negative edge of the PR-001 fix: Photo Credit: Jane Doe, Image Source: Unsplash, Credit Photo: Kim, Photos: MBC, 자료 출처: MBC, 자료출처: MBC, 사진제공: MBC, 출처 MBC 뉴스 and • 출처: MBC classified as graphics, entered the translated set and dropped out of qa.attribution, which OS10.9 forbids. A label is now a chain of up to three credit words (ATTRIBUTION_WORDS), Latin plurals are accepted, leading decoration is ignored, and a Hangul label ending in 출처 or 제공 takes the credited party after a space, because Korean credit lines omit the colon. Everything from PR-001 still holds: the separator requirement is unchanged, and Resource Center, Photo Zone, Photography Class, Credit card accepted, Video Zone, Source of the Nile and 사진 잘 찍었네 remain graphics.
    Tests: test_a_credit_label_with_a_qualifier_or_decoration_is_an_attribution, the extended test_a_caption_that_only_contains_a_credit_word_is_a_graphic, and test_compound_credit_lines_leave_the_translated_set, which drives run_onscreen() and asserts both compound credits are kind = attribution, absent from translated_cards() and present in qa.attribution, while Photo Zone stays a graphic.

Residual tradeoff, stated rather than hidden: a Korean card that opens with 출처 or 제공 and continues after a space is read as a credit, so a caption like 출처 표기 방법 would not be translated. The alternative, requiring a colon, drops real Korean credits, which is the failure OS10.9 forbids.

Verification at f127499 (on forge, project venv on PATH): make check exit 0, ruff format, ruff check and mypy clean, 393 passed, 7 deselected. No model, no network, no ffmpeg in any test.

The ONNX engine is the next PR in the stack, based on this branch.

Lane 10's core rules, tests first, on top of the pipeline types:

- sample_times is one frame per whole second inside the duration (OS10.1)
- is_dialogue_caption compares normalised text with speech in the same second
  and drops a match, keeping everything else (OS10.3)
- group_cards joins identical text on consecutive frames, holds a card to at
  least 2200 ms, caps it at 8000 ms and stops 100 ms before a later card
  (OS10.2, OS10.4); cards that start on the same frame stay side by side
- attribution cards keep kind = attribution, leave the translated set and are
  named in the QA block (OS10.9)
- run_onscreen writes onscreen.json atomically; engine = off writes [] and a
  note that names the omission (OS10.5)
- OcrEngine is a protocol reporting its execution provider (OS10.6); the lane
  runs end to end on FakeEngine and FakeFrameSource with no model, no network
  and no ffmpeg (OS10.8, OS10.10)
@anthony-hermes

anthony-hermes Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Trimmed the onscreen tests to observable cards and QA output.

  • Removed a duplicate sampling-property test (the exact-time table already covers it), the frame-source call-shape test, the normalise helper test (the dialogue-caption match test exercises it end to end), the every-field onscreen.json dict comparison, the "engine without a seam" guard, and the test that only exercises the fake engine.
  • Kept: sampling times, dialogue caption vs same-second speech, grouping of jittered text, hold 2200 / cap 8000 / 100 ms gap, attribution cards left untranslated, engine off note, and the no-text frame.

215 tests, make check exit 0, CI green.

Resolved tests/pipeline/test_cues.py, test_prompt.py and test_speakers.py by taking
master's copy for every pipeline test file. The suite trim lives in #23, so this
branch carries no pipeline test change after the merge; its own diff is the ten
onscreen files.
read_once and frames_once lost their only caller when the internal shape checks
were cut, and the OS10.8 section header they lived under was left dangling.
Card.duration_ms and Card.is_attribution had no caller either.

The redundant `second.start_ms - first.end_ms == 100` assertion was implied by the
two absolute bounds asserted above it.
@anthony-hermes

anthony-hermes Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Hermes PR Review

Reviewed commit: f1274998a4c50bed7218a0e938af0aaa5c7c0675

Review status: Pass 3 of 3 complete. PR-001 to PR-004 are verified fixed. One new Low finding, PR-005, is open and recorded as a forced tradeoff, not a blocker. No Critical or High finding is unresolved. This is not an approval; the merge decision is the repository owner's.

Executive summary

PR #19 adds lane 10's on-screen-text core as ten new files: seven under src/subsmith/onscreen/ and three under tests/onscreen/. The pass-3 focus diff 1be6671..f1274998 is the final remediation for PR-004: four files, 118 insertions, 22 deletions, confined to the attribution rule, its word list, its export and its tests. grouping.py, run.py, sampling.py and engine.py were not touched by the remediation.

make check exits 0 on a detached worktree at the reviewed head (393 passed, 7 deselected), and CI run 47575771301 on that head is completed / success.

Every previous finding is verified fixed by direct probes on the reviewed tree, not by reading fix notes:

  • PR-004: all 18 credit forms re-checked, including Photo Credit: Jane Doe, Image Source: Unsplash, Credit Photo: Kim, Photos: MBC, 자료 출처: MBC, 자료출처: MBC, 사진제공: MBC, 사진제공 MBC, 출처 MBC 뉴스, • 출처: MBC, and the pass-1 forms. All classify as kind = attribution, leave translated_cards() and appear in qa.attribution; Photo Zone stays a graphic and remains translated.
  • PR-001: all 11 graphic forms stay False, including the three Korean ones.
  • PR-002: two cards on frame 0 and one at 1000 give (0, 900), (0, 900), (1000, 3200).
  • PR-003: Kim against Kim arrived at the station. is False and survives; the split Korean caption still matches the joined speech.

One new Low finding, PR-005, is the known cost of the colon-less Korean branch added for PR-004: a card that opens with 출처 or 제공 followed by a space is read as a credit, so 출처 표기 방법 is not translated. The implementer disclosed this tradeoff in the PR body. The suggested correction would reintroduce a Medium false negative (see the finding), so the branch is left as documented and the residual class is the owner's call.

Findings

PR-005 (Low, confidence medium, confirmed, open, correction disputed): Space-separated Korean credit rule drops ordinary informational cards from translation

File: src/subsmith/onscreen/classify.py:113, with _SPACE_SEPARATED_LABELS at line 52 and _LABEL at line 41.

Problem: is_attribution() returns True when the matched label ends in 출처 or 제공 and the next character is whitespace. The branch does not inspect what follows the space, so a card whose first word is a credit noun but whose message is ordinary content is classified as a credit.

Evidence, reproduced by the coordinator: on the reviewed tree, is_attribution() is True for 출처 표기 방법, 제공 표기 방법, 자료 출처 표기 방법, 영상 제공 방법 and 출처 불명, and False for all 11 graphic cases in the existing table. A full run_onscreen() with 출처 표기 방법 at 6000 ms produces kind = attribution, leaves it out of translated_cards() and lists it in qa.attribution. The deciding line is return rest[0].isspace() and label.group().endswith(_SPACE_SEPARATED_LABELS).

Impact: one class of Korean informational card is written to onscreen.json but never translated, and qa.json over-reports attribution. Nothing raises or logs, so the omission is silent. The class is narrow: the card must open with 출처 or 제공, then a space, then non-credit text.

Coordinator ruling, correction disputed: the suggested correction is to require a Latin or digit token, or a name-like remainder, after the space. That would drop Korean credited parties written in Hangul, for example 출처 문화방송, which is a real credit line. Requiring a colon instead drops 출처 MBC 뉴스, which is the OS10.9 failure PR-004 was filed for. Both alternatives trade this Low for a Medium false negative on genuine credits. The branch is therefore left as it is, with the tradeoff stated in the PR body and recorded on the card. If the owner decides this class matters for his content, the fix needs a rule that separates a credited party from a descriptor without a lexicon, which is a design change, not a patch.

Previously reported findings

ID Finding Pass 1 Pass 2 Pass 3
PR-001 Attribution markers match substrings inside unrelated words Confirmed Fixed Fixed
PR-002 Collision clamp skips all but the last same-frame card Confirmed Fixed Fixed
PR-003 Substring of speech is treated as a matching dialogue caption Confirmed Fixed Fixed
PR-004 Anchored attribution regex rejects compound and decorated credit lines n/a Confirmed Fixed

Verification

Command Exit Result
cd .../pass-3/tree && PATH=/home/hermes/.hermes/work/subsmith/.venv/bin:$PATH make check 0 ruff format: 58 files already formatted; ruff check: all checks passed; mypy: no issues in 58 source files; pytest all pass; check: pass
PATH=... python -m pytest (no extra -q) 0 393 passed, 7 deselected in 1.07s
PYTHONPATH=<tree>/src:<tree> <venv>/bin/python pass-3/probe_coordinator.py 0 PR-001, PR-002, PR-003 and PR-004 outcomes reproduced; PR-005 reproduced by function and end to end
git diff --name-status c732ff25..f1274998 0 ten added files only, no instruction file, spec file, CI config, workflow, Makefile or dependency manifest
ghb api repositories/1482763054/actions/runs?branch=wt/onscreen-core 0 run 47575771301 on f1274998 is completed / success, job check success
ghb api repositories/1482763054/pulls/19, re-read before publishing 0 head f1274998, base c732ff25, state open, mergeable: true, mergeable_state: blocked

The reviewer child could not read the PR description: its api.github.com/repos/anthonyma94/subsmit lookup returned 404, the known name-resolution failure for this repository. The coordinator read the body with the numeric repository id, and it matches the spec and the remediation notes used here.

Implementation walkthrough

Overview. Lane 10 turns sampled video frames into onscreen.json records. It is pure and fake-driven: OcrEngine and FrameSource are protocols, and classification and grouping are plain functions. The final commit changes only which card texts count as credits.

Execution flow. run_onscreen() validates engine. With engine="off" it writes an empty list and a QA note naming the omission (OS10.5), without reading a frame. Otherwise it requires ocr and frames, gets whole-second sample times from sample_times() (OS10.1), checks each Frame.time_ms against the requested time, and calls ocr.read(frame). Each returned Fragment goes through is_dialogue_caption(): normalise() removes case, spaces and punctuation, and speech_in_second() gathers segments overlapping the sampled second; only equality against a segment, or against the joined segments of the second, discards a fragment (OS10.3). Survivors become FrameRead values for group_cards(), which keys fragments by normalised text, opens one card per text, extends it over consecutive samples, applies the 2200 ms floor and 8000 ms cap, and clamps each card 100 ms before the next strictly later distinct start (OS10.2, OS10.4). Each Card gets kind from is_attribution(): leading decoration is stripped, a chain of up to three ATTRIBUTION_WORDS is matched (Latin labels may take a plural s), and the remainder must open with a separator, by, end-of-card, or, for a Korean label ending in 출처 or 제공, a space (OS10.9). _write_onscreen() serialises through a .part sibling and os.replace(). OnscreenQa counts frames, fragments, discarded dialogue and cards, and lists attribution texts for the later qa.json merge; provider comes from ocr.provider (OS10.6).

Decisions. Equality rather than containment for speech matching; anchored credit labels with a separator requirement, so Photo Zone and Resource Center stay graphics; a chain, plural and decoration extension plus a colon-less Korean branch to recover real credits (PR-004); same-frame cards clamped against the next later start, never against each other. PR-005 is the residual cost of the colon-less branch.

Assumptions. Text must appear on consecutive one-second samples to form one card. The hold rules and the 100 ms gap define the timeline. Non-credit cards are the translation set. qa.json is not written by this slice; OnscreenQa is returned for a later merge. All evidence comes from protocol fakes: no model, network, GPU or ffmpeg runs in this lane's tests.

Changed files

File Role
src/subsmith/onscreen/classify.py _DECORATION, _credit_word, _CREDIT, _LABEL, _SEPARATOR, _SPACE_SEPARATED_LABELS; is_attribution() rewritten around them
src/subsmith/onscreen/types.py ATTRIBUTION_MARKERS renamed to ATTRIBUTION_WORDS, expanded from 5 to 11 words
src/subsmith/onscreen/__init__.py public export renamed to match
tests/onscreen/test_onscreen.py 10-case compound and decorated credit table, 11-case graphic table, compound-credit end-to-end test, word-level case test
src/subsmith/onscreen/grouping.py unchanged in this pass; the bisect_right clamp from PR-002 is still in place
src/subsmith/onscreen/run.py, sampling.py, engine.py, tests/onscreen/fakes.py unchanged; read to trace the flow and build probes

Assumptions and risks

  • Renaming the exported ATTRIBUTION_MARKERS is a public API change inside a new module. No in-repository caller uses the old name and the module has no outside consumer yet, so it is noted rather than filed.
  • docs/spec/10-onscreen.md still names Video: while the tuple stores Video and the separator carries the colon. Behaviour for Video: MBC is unchanged; the spec wording is the maintainer's to adjust if wanted.
  • PR-005 is Low because the affected card class is narrow and its frequency in real Korean video cannot be measured from a fakes-only slice.
  • No real OCR engine, vision endpoint or ffmpeg extractor exists in this slice, so no claim is made about model accuracy or frame extraction.

Recommended human review order

  1. src/subsmith/onscreen/classify.py:97-113 with OS10.9 open: decide whether the space-separated Korean branch needs a tighter credited-party rule (PR-005) or whether the documented tradeoff stands.
  2. tests/onscreen/test_onscreen.py:294-351: confirm the compound-credit table and the end-to-end test pin the PR-004 fix without reopening the PR-001 graphic cases.
  3. src/subsmith/onscreen/grouping.py:111-122: confirm the bisect_right clamp still handles same-frame cards before a later start (PR-002).
  4. src/subsmith/onscreen/run.py:73-164: confirm classification still drives the translated set and QA as OS10.9 requires.
  5. Run make check at the head and confirm the ten added files are the whole diff. Merging stays with the repository owner.

This is not an approval, and no formal review event was submitted on the forge.

Attribution is now the label that opens a card, followed by a separator,
`by`, or the end of the text, so `Resource Center` and `Photo Zone` stay
graphics instead of being dropped from translation (PR-001).

A dialogue caption must equal the normalised speech, not sit inside it, so
a nameplate `Kim` survives the second where someone says "Kim arrived at
the station." (PR-003). A caption split across two segments still matches,
because the segments of the second are joined and compared as well.

Every card is clamped against the next card that starts later, not merely
the next card in the list, so all same-frame cards stop 100 ms before a
later card instead of one of them dropping below the 2200 ms hold (PR-002).

make check: exit 0. python -m pytest: 375 passed, 7 deselected.
OS10.9 false-negative edge of the anchored attribution rule: `Photo
Credit: Jane Doe`, `Image Source: Unsplash`, `Credit Photo: Kim`,
`Photos: MBC`, `자료 출처: MBC`, `자료출처: MBC`, `사진제공: MBC` and
`• 출처: MBC` were graphics, so they reached the translated set.

A label is now up to three credit words in sequence with an optional
plural `s` on the Latin ones, leading decoration is ignored, and a
Hangul label ending in `출처` or `제공` counts when the credited party
follows a space, because Korean credit lines omit the colon. The
separator, `by` and end-of-card rule that keeps `Photo Zone`,
`Resource Center` and `Video Zone` graphics is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants