Skip to content

[FIX] Don't write to stdin when only CEA-708 services are extracted (-svc) - #2517

Open
kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-only-no-stdin-writes
Open

kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-only-no-stdin-writes

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 -svc 1 --out=sami -o out.smi -quiet

On master, even with -quiet, this prints the SAMI header and footer on the terminal:

<SAMI>
<HEAD>
...
<BODY>
</BODY></SAMI>

And when stdin isn't writable (scripts, cron, CI):

./ccextractor sample.ts -svc 1 --out=webvtt -o out.vtt < /dev/null
Error: writing to file        (exit code 1)

The problem

-svc 1 alone means "CEA-708 only", so CCExtractor doesn't open the main (608) output file. But the main output's file handle was left at 0, not -1. 0 is stdin.

So everything meant for the main file went to stdin:

  • the file header and footer (sami, smptett, webvtt, ssa, scc, ccd, simple-xml, --bom),
  • and for raw, bin, dvdraw and mcc, the caption data itself.

On a terminal it shows up as junk on the screen. In a script, the write fails. For webvtt and mcc that failure stops the run with Error: writing to file (exit 1).

Fix

src/lib_ccx/ccx_encoders_common.c:

  • start every main output at fh = -1 (no file), not 0,
  • skip the header and footer for an output with no file. -sendto still gets its RCWT header, which is sent over the network.

src/lib_ccx/ccx_encoders_mcc.c:

  • skip writing when there is no file. It still records that captions were seen, so the exit code doesn't change.

Tests

The sample was run with stdin opened read-write, so anything written to it is caught. Master vs. this PR:

master this PR
-svc 1, all 18 --out formats: bytes written to stdin up to 12,638 0
-svc 1 --out=webvtt or mcc, stdin not writable exit 1, Error: writing to file exit 0
-svc 1: the .p1.svc01.* files byte-identical
normal runs (no -svc), all 17 formats byte-identical, same exit code and messages
-12, --stdout, -1 -svc 1, --koc byte-identical

One extra change: -svc 1 --out=spupng crashed on master (exit 139, or exit 5 with Cannot open (null)). It now runs to the end.

Not changed here: -svc 1 with a format the CEA-708 writer can't write (webvtt, spupng, …) still leaves an empty .p1.svc01.* file. #2513 fixes that.

No open PR touches these two files. The -sendto path keeps its old behaviour by design, but I couldn't test it locally.

With -svc and no -1/-2/-12, no main output file is opened. init_output_ctx()
zeroed the output struct, so its fh stayed 0, which is stdin. The file
header and footer, and the data of the raw, bin, dvdraw and mcc formats,
were then written to stdin: printed on the terminal (even with -quiet),
or failing when stdin is not writable. For webvtt and mcc that failure
ended the run with "Error: writing to file" (exit 1).

Start unopened outputs at fh -1, skip the header and footer for them
(except the -sendto RCWT header, which goes over the network), and have
the MCC encoder skip writing when there is no file.
@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 Small fix: with -svc 1 (CEA-708 only), the unopened main output was left on fd 0 (stdin), so headers, footers and raw/bin/mcc data went to stdin. That shows up as SAMI/WebVTT text on the terminal, even with -quiet. When stdin isn't writable, webvtt and mcc runs end with "Error: writing to file" (exit 1). Normal runs are byte-identical. 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