Skip to content

[FIX] Honor --lf in CEA-708 SRT, SAMI and transcript output - #2497

Open
kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-honor-lf
Open

kaihere14 wants to merge 1 commit into
CCExtractor:masterfrom
kaihere14:fix/708-honor-lf

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 --lf -o out.srt
tr -cd '\r' < out.srt | wc -c              # 608 file
tr -cd '\r' < out.p1.svc01.srt | wc -c     # 708 file

CR bytes in the files written with --lf:

file master 604dad8e this PR
608 out.srt 0 0 (unchanged)
708 out.p1.svc01.srt 24 0
708 --out=sami 36 0
708 --out=ttxt 4 0

With --out=ttxt it is mixed on master: the last row of a caption ends in \n (from encoded_end_frame), the rows before it in \r\n.


Problem

--lf ("Use LF (UNIX) instead of CRLF (DOS, Windows) as line terminator") is ignored by the CEA-708 writer. In the same run the 608 file uses LF and the 708 file uses CRLF.

Root cause

The Rust 708 writer (tv_screen.rs) has "\r\n" hardcoded in write_srt, write_transcript, write_sami and write_sami_header. The C writer (ccx_decoders_708_output.c) uses encoder->encoded_crlf in all of them, which is "\n" with --lf.

Fix

Writer gets a crlf field, set to "\n" when ccx_options.enc_cfg.line_terminator_lf is on and "\r\n" otherwise (the Rust WebVTT header code reads the same option). The SRT, SAMI and transcript writers use it instead of "\r\n". SCC is unchanged (it uses \n in both the C and the Rust writer).

I didn't use encoded_crlf itself because with --unicode it is UTF-16, and the 708 text isn't. Switching to it would change 708 --unicode output, which is a separate issue (#2450).

Tests

  • New unit test test_708_text_formats_honor_lf: writes SRT, SAMI and transcript without --lf (checks the exact CRLF output) and with --lf (checks there is no CR left). It can't pass on master, where the 708 writer always writes \r\n; it passes with the fix.
  • cargo test: 449 passed (src/rust), 101 passed (lib_ccxr). cargo fmt --check and cargo clippy -- -D warnings are clean in both crates.
  • On the sample, without --lf the 708 srt, sami, txt and scc files are byte-identical to master. With --lf they equal master's output with the CRs removed. The 608 file is identical to master.

Note: #2484 (mine) and #2486 also edit tv_screen.rs (write_row). Whichever is merged later may need a small rebase.

@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 Small fix: --lf was ignored by the CEA-708 writer, so in one run the 608 file used LF and the 708 file CRLF (and the 708 transcript mixed both). Repro and before/after counts are in the description. 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 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.

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

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