[Fix](608): restore current_visible_start_ms set-on-first-char for rollup#2268
Conversation
|
What sample did you use to test it? I haven't been able to repro with any of the ones I have locally |
|
here is the sample i used. * File: c4dd893cb9d67be50f88bdbd2368111e16b9d1887741d66932ff2732969d9478.ts
Command: On master:
This PR: 1
Diff (only the start timestamp changes; caption text, end time, and cue count remain identical):
|
cfsmp3
left a comment
There was a problem hiding this comment.
Deep Review — Regressions Found
The rollup timing fix works on your sample (c4dd893cb9d6): start time corrects from 00:00:00,000 to 00:00:13,913. That bug is real.
However, the broad revert of commits bc5d6055/54df50f4 (slice_header, do_cb, sequencing changes) introduces timing regressions on multiple other samples. We tested against reference files we have on disk:
| Sample | Format | Master (matches reference) | This PR | Delta |
|---|---|---|---|---|
0069dffd2180.mpg |
MPG CEA-608 | 00:00:03,603 |
00:00:00,766 |
-2.8s |
5cbb21adb6e0.dvr-ms |
DVR-MS CEA-608 | 00:00:00,534 |
00:00:00,734 |
+200ms |
6395b281adf0.asf |
ASF CEA-608 | 00:00:02,436 |
00:00:01,068 |
-1.4s |
8849331ddae9.mp4 |
MP4 c608 | 00:00:03,771 |
00:00:04,738 |
+1s |
132d7df7e993.mov |
MOV CEA-608 | 00:00:12,812 |
00:00:13,980 |
+1.2s |
b22260d065ab.ts |
TS CEA-608 | 00:00:04,838 |
00:00:02,635 |
-2.2s |
These are seconds-level shifts, not rounding. Master matches the reference files; this PR does not.
Root cause
The reverted commits were fixing real timing issues across container formats:
- slice_header IDR-only flush — flushing on every reference frame (as this PR restores) causes reordering problems in I/P-only streams
- do_cb field counting guards — the H.264/PES guards on
cb_field1++prevent double-counting in container formats where PTS already represents the correct timestamp - sequencing.c PES reset — removing PES from
reset_cbbreaks timing for MPEG-2 PES streams
What needs to happen
The rollup 00:00:00,000 bug is real and should be fixed, but with a narrower fix that only addresses the rollup_from_popon edge case. Specifically:
- Keep the slice_header changes (IDR-only flush, large PTS gap handling) — do NOT revert
- Keep the do_cb field counting guards — do NOT revert
- Keep the sequencing.c PES reset — do NOT revert
- Keep the
get_visible_start/get_visible_endRust calls — do NOT revert - Fix ONLY the
rollup_from_poponlogic so it handles the case where no CR fires before EOF
The bug is that rollup_from_popon never clears when the stream ends with fewer lines than the roll-up window requires. A targeted fix would be to clear rollup_from_popon and set current_visible_start_ms during the end-of-stream flush path, not by reverting the entire mechanism.
Test commands
# The bug (should NOT be 00:00:00,000):
ccextractor c4dd893cb9d6...ts -o out.srt
# Regressions (should match reference):
ccextractor 0069dffd2180...mpg -o out.srt # expect 00:00:03,603
ccextractor 5cbb21adb6e0...dvr-ms -o out.srt # expect 00:00:00,534
ccextractor 6395b281adf0...asf -o out.srt # expect 00:00:02,436When a stream switches from pop-on to roll-up mode and ends before check_roll_up() reports changes=1 (fewer lines than the roll-up window requires), the CR handler never runs the backfill at line 836 and current_visible_start_ms is still zero when flush_608_context fires EraseDisplayedMemory. Result: the first emitted caption is timestamped at 00:00:00,000. Capture the FTS of the first character after the transition in a new field ts_first_char_rollup_transition. Unlike ts_start_of_current_line, this field is not overwritten by intermediate changes=0 CRs, so the first-char time survives to the end-of-stream flush path. write_cc_buffer uses it to backfill current_visible_start_ms when rollup_from_popon is still set at emit time, and clears it together with the flag. The normal popon->roll-up flow (where a scrolling CR eventually fires) and every other caption path are unchanged. Verified on c4dd893cb9d6...ts: first subtitle now starts at 00:00:13,913 (was 00:00:00,000). Regression tested against six master samples the mentor flagged (0069dffd.mpg 03,603; 5cbb21ad.dvr-ms 00,534; 132d7df7.mov 12,812; 6395b281.asf 02,436; 8849331d.mp4 03,771; b22260d0.ts 04,838) - all match the reference timings unchanged.
c6647a6 to
1d22517
Compare
|
Thanks for your time :-) I restored all three commits I had reverted. I added a precise fix just for the EOF edge case. Reshaped the branch to a single commit (1d22517). FixAdded a new field, ts_first_char_rollup_transition, that captures the first-char FTS right after the popon→rollup switch. Unlike ts_start_of_current_line, it doesn't get clobbered by changes=0 CRs in between, so it survives to the end-of-stream flush. write_cc_buffer uses it to backfill current_visible_start_ms when rollup_from_popon is still set at emit time. The normal CR path is untouched. c4dd893c still fixed: first caption at 00:00:13.913 (was 00:00:00.000). Ran all six regression samples you listed = every one matches the master exactly: |
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 283bfd9...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 283bfd9...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
This is essential. We will not merge ANY PR that doesn't come with detailed instructions, including a sample. We don't want
"fixes" for theoretical issues that an AI agent found, without context. If you can't reproduce the bug, don't send a PR.
Creating PRs with AI is very quick, but we still have humans (even if AI assisted) going over each.
Be mindful of reviewers' time.
## Summary
Fixes an issue where CEA-608 roll-up captions were emitted with a start time of `00:00:00,000 " instead of the actual first-character FTS.
This occurs in roll-up mode streams where fewer than the required number of lines are written before EOF (or more generally, when no CR event results in
changes == true).Before:
00:00:00,000 --> ... " **After:**00:00:13,913 --> ...` (matches first-character FTS)## Root cause
Commits
bc5d6055/54df50f4introduced arollup_from_poponflag inccx_decoder_608_contextto delay settingcurrent_visible_start_msuntil a CR event triggered scrolling.However, in cases where:
changes == true, orthe flag is never cleared. As a result,
current_visible_start_msremains0, and captions are emitted starting at00:00:00,000.In contrast, commit
042716ad(pre-change) setcurrent_visible_start_msimmediately when the first character was written to an empty buffer (in non-POPON mode), which correctly handles these cases.Fix
Remove the
rollup_from_poponmechanism and restore the previous behaviour of setting the start time on the first character.Changes
src/lib_ccx/ccx_decoders_608.crollup_from_poponguard from character handlersrc/lib_ccx/ccx_decoders_608.hrollup_from_poponfieldCleanup:
dbg_print,printf) from:ccx_decoders_common.csequencing.cavc_functions.cTest plan
cmake --build .) with no new warnings00:00:13,913vs00:00:00,000)bc5d6055behaviour.