Skip to content

[FIX] Validate SCC SMPTE timecodes and handle 29.97 drop-frame - #2477

Open
RohitSutar1823 wants to merge 4 commits into
CCExtractor:masterfrom
RohitSutar1823:fix/scc-smpte-drop-frame-2464
Open

RohitSutar1823 wants to merge 4 commits into
CCExtractor:masterfrom
RohitSutar1823:fix/scc-smpte-drop-frame-2464

Conversation

@RohitSutar1823

@RohitSutar1823 RohitSutar1823 commented Nov 21, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2464.

This PR improves SMPTE timecode parsing and validation in the Rust SCC demuxer.

Changes

  • Validate hours, minutes, seconds, and frame components.
  • Enforce the standard fixed-width HH:MM:SS:FF or HH:MM:SS;FF format.
  • Reject malformed timecodes, invalid separators, non-digit components, and out-of-range values.
  • Distinguish non-drop-frame (:) and drop-frame (;) timecodes.
  • Implement standard 29.97 fps SMPTE drop-frame conversion.
  • Preserve caption commands for unusual but readable drop-frame labels (;00 and ;01) at non-tenth-minute transitions by treating them as the next valid ;02 frame.
  • Preserve existing non-drop-frame conversion behavior.
  • Add compatibility for SccFrameRate::Fps23_976.
  • Support tab- and whitespace-separated SCC timecode and caption data.

Regression Tests

Added tests covering:

  • SMPTE timecode validation and malformed inputs.
  • Valid and unusual drop-frame labels.
  • Drop-frame minute, ten-minute, and hour boundaries.
  • Invalid frame numbers and time components.
  • Fixed-width format and separator validation.
  • 23.976 fps compatibility.
  • SCC parsing with tabs, single spaces, and multiple spaces.
  • The reviewer-provided reproduction sample, verifying caption byte-pair preservation and exact timestamps.

Testing

  • cargo fmt --check passed.
  • cargo test passed (445 tests).
  • git diff --check passed.

Scope

Changes are limited to src/rust/src/demuxer/scc.rs.

This PR improves SMPTE timecode validation, drop-frame conversion handling, and compatibility with existing SCC parsing behavior.

RohitSutar1823 and others added 2 commits November 21, 2026 04:46
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 172/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 32/34

66 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of master — test 9984, commit 24d1e0a:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 66 fail on both, byte for byte the same

Compared with the commit this branch was cut from: the same run as the tip of master (test 9984), so the comparison above already covers it.


No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch.

@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on windows. 172/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 32/34

66 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of master — test 9985, commit 24d1e0a:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 66 fail on both, byte for byte the same

Compared with the commit this branch was cut from: the same run as the tip of master (test 9985), so the comparison above already covers it.


No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch.

@cfsmp3 cfsmp3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Carlos' claude doing the first pass. Before Carlos takes a look, please address these issues.

  1. Rejecting a timecode drops the whole line. When parse_smpte_timecode() returns None, parse_scc() skips the line along with its commands. A drop-frame label that skips ;00/;01 at a minute that isn't a multiple of 10 is not legal SMPTE, but such labels exist. CCExtractor's own SCC writer (ccx_encoders_scc.c) derives the frame from wall-clock milliseconds, so a caption between 60.000 and 60.066 s is written as 00:01:00;00. With this file:

    00:00:58;00	9420 9420 94ae 94ae 9470 9470 c1c1 942f 942f
    00:01:00;00	942c 942c 9420 9420 94ae 94ae 9470 9470 c2c2 942f 942f
    00:01:03;00	942c 942c
    

    master outputs both captions (AA 0–2 s, BB 2–5 s). This branch drops the 00:01:00;00 line, so BB disappears and AA stays on screen until 4.937 s. Please don't throw away lines with an unusual but readable label. For the skipped DF labels, treat them as the next valid frame (or convert them as-is), and keep None for timecodes that really can't be parsed (non-digits, wrong layout).

  2. The drop-frame change is a few milliseconds, not a timing bug fix. DF labels already follow wall-clock time, so the old formula and the new one differ by a few ms (00:01:00;02: 60066 vs 60060). I exported SCC from 14 real 608 samples with master and imported them with master and with this branch. All 14 SRTs are byte-identical, so the importer's frame timing absorbs the difference. That's fine to keep, but please describe it accurately in the PR.

  3. Coordinate with #2452, which adds SccFrameRate::Fps23_976 in the same file. nominal_fps() has no arm for it, so whichever PR merges second won't compile until that's added (24 for 23.976).

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RohitSutar1823

Copy link
Copy Markdown
Author

Thanks for the detailed review and for providing the reproduction sample.

I've addressed the requested changes:

  1. Unusual drop-frame labels: Instead of rejecting ;00 and ;01 at non-tenth-minute transitions, the parser now treats them as the next valid ;02 frame. This prevents readable SCC lines and their caption commands from being discarded.

  2. Regression coverage: Added a test using your exact reproduction sample. It verifies that all three SCC lines and their caption byte pairs are preserved, along with their expected timestamps.

  3. Whitespace handling: Added support for tab-separated, single-space, and multiple-space separators between timecodes and caption data.

  4. 23.976 fps compatibility: Added the missing Fps23_976 handling, including nominal FPS and frame-duration conversion, to maintain compatibility with the changes from [FIX] Honor 23.976 fps when importing SCC #2452.

  5. Timing explanation: Updated the technical description to clarify the standard drop-frame conversion without claiming a demonstrated real-world timing drift fix.

Validation:

  • cargo fmt --check passed.
  • cargo test passed (445 tests).
  • git diff --check passed.

Thanks again for the helpful feedback. I've updated the implementation and regression tests for another review.

@cfsmp3 cfsmp3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Carlos' claude doing the first pass. Before Carlos takes a look, please address these issues.

Thanks. The ;00/;01 mapping fixes the case I reported: my three-line file now keeps BB. The branch also merges cleanly onto current master (which now has #2452), and all 39 SCC tests pass on the merged tree. The same class of problem remains, though: any timecode the new validation rejects still drops the whole line and its commands.

  1. Drop-frame labels at any rate other than 29.97 now lose every caption. parse_smpte_timecode() returns None for a ; separator when fps != Fps29_97, and parse_scc() then skips the line. Most SCC files in the wild use ; labels. Take this file:

    Scenarist_SCC V1.0
    
    00:00:01;00	9420 9420 94ae 94ae 9470 9470 c1c1 942f 942f
    
    00:00:03;00	942c 942c 9420 9420 94ae 94ae 9470 9470 c2c2 942f 942f
    
    00:00:05;00	942c 942c
    
    --scc-framerate master this branch (merged onto master)
    29.97 2 cues 2 cues
    30 / 25 / 24 / 23.976 2 cues 0 cues, exit code 10

    The f >= nominal_fps and h > 23 rejections behave the same way: a frame number that's out of range for the selected rate silently deletes that caption. Master converted these lines. A wrong label shouldn't cost the caption. Please convert these labels instead of dropping the line. Treat ; as non-drop-frame at rates without drop-frame, and keep None only for strings that can't be parsed (wrong layout, non-digits). If you want to flag a bad label, a warning is fine.

  2. Validation is done twice. After the fixed-layout check (bytes.len() == 11 with separators at 2, 5 and 8), the loop that collects separator_indices and the checks after it (scc.rs:152 and :158) can't find anything new. The separators are already known to be at 2, 5 and 8, so every other byte only needs to be a digit. Please reduce it to one check (layout plus is_ascii_digit() on the eight digit positions) and slice at the fixed offsets.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RohitSutar1823

Copy link
Copy Markdown
Author

Updated the PR to address the review feedback:

  • Preserve SCC caption data when timecodes contain unusual drop-frame labels.
  • Treat semicolon-separated timecodes as non-drop-frame for frame rates other than 29.97 fps.
  • Accept numerically out-of-range timecode components without discarding valid caption data.
  • Keep strict fixed-width and digit validation for malformed timecode formats.
  • Added regression tests covering the reported cases across supported frame rates.

The changes are pushed to the existing PR branch. Thank you for the feedback!

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.

[BUG] Rust SCC demuxer parse_smpte_timecode in scc.rs lacks frame bounds checks and causes drift on drop-frame NTSC captions

3 participants