Skip to content

[FIX] Write the CEA-708 SCC header before the first caption - #2479

Open
kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-scc-header
Open

kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-scc-header

Conversation

@kaihere14

Copy link
Copy Markdown
Contributor

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

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

Sample: c83f765c…06cd.ts (has CEA-708 service 1).

./ccextractor sample.ts --service 1 --out=scc -o out.scc
head -4 out.p1.svc01.scc
./ccextractor out.p1.svc01.scc -o back.srt

On master 604dad8e:

00:00:00;25	942c 942c 94ae 94ae 9420 9420 94e0 94e0 a820 e5f8 70ec ef73 e9ef 6e20 2980 942f 942f

Scenarist_SCC V1.0

Reading that file back with CCExtractor prints No captions were found in input., because SCC input is only detected when the file starts with Scenarist_SCC V1.0 (stream_functions.c / stream_functions.rs).

With this PR:

Scenarist_SCC V1.0

00:00:00;25	942c 942c 94ae 94ae 9420 9420 94e0 94e0 a820 e5f8 70ec ef73 e9ef 6e20 2980 942f 942f

and reading it back gives Detected SCC (Scenarist Closed Caption) format and the captions (( explosion ) at 00:00:00,835, ...).


Problem

CEA-708 SCC output writes the Scenarist_SCC V1.0 header after the first caption instead of as the first line. The file is not a valid SCC file, and CCExtractor itself can't read it back.

Root cause

write_scc writes the header when cc_count == 2. cc_count is increased once per printed screen, right before the write, so it is 1 for the first caption and 2 for the second. The C writer (dtvcc_write_scc) has the same check.

Fix

Write the header when cc_count == 1, and do it before the "screen is empty" and "starts before zero" early returns, so it is still the first line if the first printed screen happens to be empty. Same change in the Rust writer and in the C writer.

Tests

  • 3 new unit tests in tv_screen.rs: header comes first on the first screen, is not repeated on the second, and is written even when the first screen is empty. All 3 fail on master and pass with the fix.
  • cargo test: 444 passed (src/rust), 101 passed (lib_ccxr). cargo fmt --check and cargo clippy -- -D warnings are clean in both crates.
  • On the sample, the SCC file differs from master only by the header moving to the top. The 708 srt, sami, txt and ttxt files and the 608 SCC file are byte-identical to master.

Note: #2466 (mine, --delay for 708) touches the lines right below the header check in write_scc. Whichever is merged second needs a small rebase, which I'll do.

@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 Small fix: the CEA-708 SCC header was written after the first caption, so CCExtractor couldn't read its own 708 SCC files back. Repro and before/after output are in the description. Could you take a look when you have time? Thanks!

@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.

The fix is correct. I ran 34 of our samples with 708 captions through --service all --out=scc on master and on this branch:

  • 31 SCC files differ only in that the header moved to the top.
  • 5 files already started with the header and are unchanged.
  • No new or missing files. In particular, no header-only files appear for services whose first screen is empty.
  • Reading the files back: all 36 of this branch's 708 SCC files give captions, against 5 of master's.

One thing to fix:

  1. Braces. The new if (tv->cc_count == 1) in dtvcc_write_scc() (src/lib_ccx/ccx_decoders_708_output.c:525) needs { } around dtvcc_write_scc_header(tv, encoder);. The project requires braces on every if body.

@kaihere14

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Updated in fff242e:

cargo test passes (451 in src/rust, 101 in lib_ccxr), and fmt and clippy are clean. On the sample, the 708 SCC file starts with the header with --delay 0 and --delay 2000, and reading it back gives captions.

@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 I've addressed the first-pass review (braces added, rebased on master after #2466). Could you take another look when you have time? Thanks!

@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 171/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 68/86
Teletext 0/21
WTV 12/13
XDS 32/34

67 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 10124, commit 034fdbc:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 67 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 10124), 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. 171/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 68/86
Teletext 0/21
WTV 12/13
XDS 32/34

67 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 10125, commit 034fdbc:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 67 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 10125), 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.

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.

3 participants