Skip to content

[FIX] Don't leave an empty CEA-708 file for output formats it can't write - #2513

Open
kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-no-empty-file-unsupported-format
Open

kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-no-empty-file-unsupported-format

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-608 and CEA-708 service 1).

./ccextractor sample.ts --out=webvtt -o out.vtt
ls -la out*
master 2c1c1c6f this PR
out.vtt (608) 648 bytes 648 bytes (byte-identical)
out.p1.svc01.vtt (708) 0 bytes not created
message none [CEA-708] This output format is not supported for CEA-708 captions, so they are not written. Use srt, sami, ttxt, txt or scc for them.

The same 0-byte file is left for smptett, ssa, g608, ccd, dvdraw, bin and spupng. With --bom it is a 3-byte file that holds only the BOM.


The problem, simply

CCExtractor writes CEA-708 captions in their own file next to the main one, like out.p1.svc01.srt. But the CEA-708 writer only knows four formats: srt, sami, transcript (ttxt/txt) and scc.

When you ask for another format, like WebVTT, it does things in the wrong order. It first makes the file, then looks at the format, sees it can't write it, and stops. So you get an empty file and no captions. It's like putting an empty box on the shelf with a label on it: it looks like your CEA-708 captions are there, but the box is empty, and nobody tells you why.

Since 708 decoding is on by default, this happens on every run with one of those formats when the input has CEA-708 captions.

Root cause

dtvcc_tv_screen::writer_output() (src/rust/src/decoder/tv_screen.rs) creates the per-service file on its first call. It then calls write(), which handles only CCX_OF_SRT, CCX_OF_SAMI, CCX_OF_TRANSCRIPT and CCX_OF_SCC. For anything else it returns Err("Unsupported write format"), which goes to warn! and isn't shown to the user. Nothing is ever written to the file.

#1877 fixed the same 0-byte symptom for the 608 files in dinit_write(), but the CEA-708 files are closed in dtvcc_writer_cleanup(), so that fix doesn't cover them.

Fix

At the start of writer_output(), check the format first. If the CEA-708 writer can't write it:

  • don't create the file,
  • print one notice per run saying CEA-708 captions are not written in this format, and which formats work,
  • still call write_debug(), as write() did for these formats, so the 708 debug output doesn't change.

The four supported formats take exactly the same path as before.

Tests

On the sample, master vs. this PR:

  • webvtt, smptett, ssa, g608, ccd, dvdraw, bin and spupng: the main output file is byte-identical. The only differences are the missing 0-byte .p1.svc01.* file and the one notice.
  • srt, sami, ttxt, txt, scc, raw and mcc: all output files are byte-identical, and there is no notice.
  • --bom: the 3-byte .p1.svc01.vtt is gone.
  • -1 (608 only) and -quiet: no notice. With -quiet, nothing is printed, as before.
  • Two inputs in one run: one notice, and the main file is identical.
  • -svc 1 --out=srt gives identical files.

The exit codes are the same everywhere. -svc 1 --out=webvtt ends with Error: writing to file (exit 1) on both master and this PR. That comes from somewhere else and isn't changed here.

Unit test: test_writer_output_unsupported_format_creates_no_file calls writer_output() with CCX_OF_WEBVTT and checks that no file is created. It fails on master. cargo test passes (449 in src/rust, all in lib_ccxr), and cargo fmt --check and cargo clippy -- -D warnings are clean.

Notes:

The CEA-708 writer only writes srt, sami, transcript (ttxt/txt) and scc.
For any other --out format (webvtt, smptett, ssa, g608, ccd, dvdraw, bin,
spupng) writer_output() still created the .pN.svcNN file before finding
out it had nothing to write, so every run left a 0-byte file (3 bytes
with --bom) and the CEA-708 captions were dropped without a word.

Check the format first: don't create the file, and say once that CEA-708
captions are not written in this format.
@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 Small fix: with --out=webvtt (and smptett, ssa, g608, ccd, dvdraw, bin, spupng), every run leaves an empty .p1.svc01.* file and drops the CEA-708 captions without a word, because the 708 writer creates the file before checking it can write that format. This checks the format first and prints one notice instead. Could you take a 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 10180, commit 2c1c1c6:

  • 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 10180), 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.

2 participants