Skip to content

[FIX] Accept iconv charset names like CP949 in CEA-708 output - #2484

Open
kaihere14 wants to merge 2 commits into
CCExtractor:masterfrom
kaihere14:fix/708-iconv-charset-names
Open

kaihere14 wants to merge 2 commits into
CCExtractor:masterfrom
kaihere14:fix/708-iconv-charset-names

Conversation

@kaihere14

@kaihere14 kaihere14 commented Nov 23, 2026 •

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[CP949]" -o out.srt
head -7 out.p1.svc01.srt

On master 604dad8e, every caption has its timing but no text, and nothing is printed:

1
00:00:00,900 --> 00:00:02,402


2
00:00:02,403 --> 00:00:04,537

With this PR:

1
00:00:00,900 --> 00:00:02,402
(<i> explosion</i> )

2
00:00:02,403 --> 00:00:04,537
(<i> explosion</i> )

Caption text lines in out.p1.svc01.srt (9 is the full file):

charset master this PR
EUC-KR, GBK, BIG5, SHIFT_JIS, ISO-8859-1 9 9 (byte-identical to master)
CP949, UHC, EUCKR 0 9 (identical to EUC-KR)
CP936, WINDOWS-936, MS936 0 9 (identical to GBK)
CP950 0 9 (identical to BIG5)
EUCJP 0 9 (identical to EUC-JP)
CP932 0 9 (identical to SHIFT_JIS)
CP874 0 9 (identical to WINDOWS-874)
JOHAB 0 9 (unconverted, with a notice)

Problem

The --service charset name is checked in two places that don't agree:

  1. dtvcc_writer_init() (C) checks it with iconv_open() and exits if iconv doesn't know it.
  2. write_row() in tv_screen.rs converts with encoding_rs (since fix: replace iconv with encoding_rs #1698), using Encoding::for_label().

A name that iconv accepts but that isn't an encoding_rs label gets past step 1. Then for_label() returns None in step 2, and the row is never written. CP949 is the usual Windows name for Korean (the code comment right above even lists it as a supported charset), and it produces a file with empty captions and no error.

Fix

  • find_charset_encoding() in output.rs: try Encoding::for_label() first, then map the iconv names of encodings that encoding_rs does have (CP949/UHC/EUCKR → EUC-KR, CP936/WINDOWS-936/MS936 → GBK, CP950 → Big5, EUCJP → EUC-JP, CP932 → Shift_JIS, CP874 → windows-874). All of these got empty captions on master.
  • If the name is still unknown (e.g. JOHAB, which encoding_rs can't convert), write the text unconverted, as with no charset, and print one notice, instead of dropping it.

Names that already worked go through the same code path as before.

Tests

  • 3 new unit tests: the name mapping, write_row turning EUC-KR bytes for 가 into UTF-8 with EUC-KR, CP949, UHC and EUCKR, and JOHAB keeping the text. All 3 fail on master and pass with the fix.
  • cargo test: 451 passed (src/rust), 101 passed (lib_ccxr). cargo fmt --check and cargo clippy -- -D warnings are clean in both crates.
  • On the sample, output with no charset (srt, sami, txt, scc) and with the charsets that already worked is byte-identical to master.

#2454 also edits write_row() (how the symbol bytes are built). It doesn't touch the charset lookup, but if both get merged, whichever comes second may need a small rebase.

@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 Small fix: with --service "1[CP949]" (also UHC, EUCKR, CP936, CP950, EUCJP), the Rust 708 writer wrote every caption with empty text, because iconv accepts the name but encoding_rs doesn't. Repro and before/after output are in the description. Could you take a look when you have time? Thanks!

@kaihere14
kaihere14 force-pushed the fix/708-iconv-charset-names branch from b60f41e to cb94b43 Compare November 23, 2026 06:33
@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 10057, commit abdd8d6:

  • 1 pass there and fail here
  • 43 fail there and pass here
  • 14 fail on both, with different output
  • 52 fail on both, byte for byte the same

Pass there, fail here:

Fail on both but produce different output — behaviour moved even though the verdict did not:

  • ccextractor --out=srt --latin1 611b4a9235...
  • ccextractor --autoprogram --out=ttxt --latin1 1020459a86...
  • ccextractor --autoprogram --out=srt --latin1 f1422b8bfe...
  • ccextractor --datapid 5603 --autoprogram --out=srt --latin1 --teletext 85c7fc1ad7...
  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --autoprogram --out=ttxt --latin1 --datets dcada745de...
  • ccextractor --autoprogram --out=srt --latin1 --tpage 398 5d5838bde9...
  • ccextractor --autoprogram --out=srt --latin1 --tpage 299 44c45593fb...
  • ccextractor --autoprogram --out=srt --latin1 --tpage 299 b8c55aa2e9...
  • ccextractor --autoprogram --out=srt --latin1 --teletext --tpage 398 3b276ad8bf...
  • ccextractor --autoprogram --out=ttxt --latin1 b236a0590b...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --codec dvbsub --out=spupng 85271be4d2...

Fail there, pass here:


Compared with the commit this branch was cut from: the same run as the tip of master (test 10057), so the comparison above already covers it.


This branch changes the behaviour of 15 test(s) relative to the tip of master. Those are the ones worth looking at; anything else in the list fails the same way on both sides.

@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 10068, commit 604dad8:

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

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

Your table reproduces on c83f765c…06cd.ts:

  • CP949, UHC, EUCKR, CP936, CP950 and EUCJP go from 0 to 9 caption lines.
  • EUC-KR, GBK, BIG5, SHIFT_JIS, EUC-JP and ISO-8859-1 are byte-identical to master.

One thing is left:

  1. The alias table misses iconv names that encoding_rs can decode. These are accepted by iconv_open() (glibc), so they get past dtvcc_writer_init(). They aren't encoding_rs labels and aren't in find_charset_encoding(), so they end up in the "can't convert" path and are written unconverted:

    • CP932 is the Windows name for Japanese, the counterpart of CP949. It should map to SHIFT_JIS (encoding_rs's Shift_JIS is windows-31j, i.e. CP932). On the sample, --service "1[CP932]" prints the notice and writes the raw bytes.
    • WINDOWS-936 and MS936 should map to GBK.
    • CP874 should map to WINDOWS_874.

    Please add them to the table and to test_find_charset_encoding_iconv_names. Names encoding_rs really can't decode, like JOHAB, can keep the notice and the unconverted fallback.

Also note that #2486 rewrites the same write_row() charset branch and output.rs, so whichever of the two merges second will need a rebase.

@kaihere14
kaihere14 force-pushed the fix/708-iconv-charset-names branch from cb94b43 to 68515e8 Compare November 24, 2026 03:15
@kaihere14

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Updated in 68515e8 (also rebased on master):

  • Added CP932 → SHIFT_JIS, WINDOWS-936 and MS936 → GBK, and CP874 → WINDOWS_874 to find_charset_encoding(), plus test cases for them in test_find_charset_encoding_iconv_names.
  • JOHAB still takes the notice and the unconverted fallback.

On the sample, each of the new names now gives the same file as its encoding_rs name (CP932 = SHIFT_JIS, MS936 = GBK, CP874 = WINDOWS-874), with no notice. On master they give 0 caption lines. I updated the table in the description too. cargo test passes (451), and fmt and clippy are clean.

Noted on #2486. I'll rebase if it goes in first.

@kaihere14

Copy link
Copy Markdown
Contributor Author

@cfsmp3 I've addressed the first-pass review (added CP932, WINDOWS-936, MS936 and CP874, rebased on master). Could you take another look when you have time? Thanks!

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