[PR #1971] [FEATURE] Add --scc-accurate-timing option for bandwidth-aware SCC output (fixes #1221) #2775

Open
opened 2026-01-29 17:23:50 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1971

State: closed
Merged: Yes


In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Summary

This PR implements bandwidth-aware timing for SCC (Scenarist Closed Caption) output to ensure YouTube and broadcast compliance, addressing issue #1221.

Problem

SCC files generated by CCExtractor were being rejected by YouTube due to timing violations. The EIA-608 standard specifies a transmission bandwidth of 2 bytes per frame, but CCExtractor was not accounting for the time required to transmit captions before their display time, causing overlapping transmissions and compliance issues.

Solution

Added a new --scc-accurate-timing command-line option that implements:

  1. Byte counting: Calculates the exact byte size of each caption including control codes, preambles, mid-row codes, text, and padding
  2. Pre-roll calculation: Determines when caption transmission must start based on byte size and frame rate to ensure it completes before display time
  3. Collision detection & resolution: Detects overlapping caption transmissions and shifts captions forward to resolve conflicts
  4. Frame-perfect EOC timing: Ensures End-of-Caption codes are sent one frame before display time

Changes Made

C Code

  • ccx_common_option.h/c: Added scc_accurate_timing option (default: off)
  • ccx_encoders_common.h/c: Added timing state tracking (scc_last_transmission_end, scc_last_display_end)
  • [ccx_encoders_scc.c]: Implemented core timing logic:
    • [calculate_caption_bytes()]: Byte counting
    • [calculate_preroll_time()]: Pre-roll timing calculation
    • [resolve_collision()]: Collision detection and resolution
    • Modified [write_cc_buffer_as_scenarist()]: Integrated accurate timing when flag is enabled

Rust Code

  • [args.rs]: Added --scc-accurate-timing CLI argument
  • [parser.rs]: Added argument parsing logic
  • [options.rs]: Added field to Options struct
  • [common.rs]: Updated C/Rust FFI bindings

Usage

ccextractor input.ts -out=scc --scc-accurate-timing -o output.scc
**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1971 **State:** closed **Merged:** Yes --- **In raising this pull request, I confirm the following (please check boxes):** - [x] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [x] I have checked that another pull request for this purpose does not exist. - [x] I have considered, and confirmed that this submission will be valuable to others. - [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [x] I give this submission freely, and claim no ownership to its content. - [x] I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT). **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [x] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [ ] I am an active contributor to CCExtractor. --- ## Summary This PR implements bandwidth-aware timing for SCC (Scenarist Closed Caption) output to ensure YouTube and broadcast compliance, addressing issue #1221. ## Problem SCC files generated by CCExtractor were being rejected by YouTube due to timing violations. The EIA-608 standard specifies a transmission bandwidth of 2 bytes per frame, but CCExtractor was not accounting for the time required to transmit captions before their display time, causing overlapping transmissions and compliance issues. ## Solution Added a new `--scc-accurate-timing` command-line option that implements: 1. **Byte counting**: Calculates the exact byte size of each caption including control codes, preambles, mid-row codes, text, and padding 2. **Pre-roll calculation**: Determines when caption transmission must start based on byte size and frame rate to ensure it completes before display time 3. **Collision detection & resolution**: Detects overlapping caption transmissions and shifts captions forward to resolve conflicts 4. **Frame-perfect EOC timing**: Ensures End-of-Caption codes are sent one frame before display time ## Changes Made ### C Code - `ccx_common_option.h/c`: Added `scc_accurate_timing` option (default: off) - `ccx_encoders_common.h/c`: Added timing state tracking (`scc_last_transmission_end`, `scc_last_display_end`) - [ccx_encoders_scc.c]: Implemented core timing logic: - [calculate_caption_bytes()]: Byte counting - [calculate_preroll_time()]: Pre-roll timing calculation - [resolve_collision()]: Collision detection and resolution - Modified [write_cc_buffer_as_scenarist()]: Integrated accurate timing when flag is enabled ### Rust Code - [args.rs]: Added `--scc-accurate-timing` CLI argument - [parser.rs]: Added argument parsing logic - [options.rs]: Added field to Options struct - [common.rs]: Updated C/Rust FFI bindings ## Usage ```bash ccextractor input.ts -out=scc --scc-accurate-timing -o output.scc
claunia added the pull-request label 2026-01-29 17:23:50 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2775