Skip to content

[IMPROVEMENT] Improve CEA-608 conformance - #2510

Open
dheitmueller wants to merge 18 commits into
CCExtractor:masterfrom
dheitmueller:cea608-conformance
Open

dheitmueller wants to merge 18 commits into
CCExtractor:masterfrom
dheitmueller:cea608-conformance

Conversation

@dheitmueller

Copy link
Copy Markdown

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:

The issues can be reproduced using the conformance stream referenced below, with each patch indicating the specific card that the issue can be seen with.


This patch series addresses a number of issues found when running VLC against the CEA608 Conformance Suite:

https://github.com/dheitmueller/cea608-conformance-suite/

I'm happy to refactor this and/or break this up into multiple PRs if that makes it easier to review. Just let me know.

The SMPTE-TT writer copied caption characters into the XML as they are,
so a caption containing '&' or '<' produced a document that is not
well-formed (XML 1.0, section 2.4: "The ampersand character (&) and the
left angle bracket (<) must not appear in their literal form, except
when used as markup delimiters"). '&' (0x26), '<' (0x3C) and '>' (0x3E)
are part of the CEA-608 basic character set (CTA-608-E, section 6.4.1),
so captions can legitimately contain them.

Add get_decoder_line_encoded_markup(), which takes the markup the row is
written in, and make get_decoder_line_encoded() a wrapper for it with
LINE_MARKUP_HTML, the behaviour it has had, so the other callers are not
touched. The SMPTE-TT writer asks for LINE_MARKUP_HTML_ESCAPED: the same
<i>, <u> and <font> tags, which it converts, and & < > of the text escaped.

Effect on the sample platform: regression test 161 (--out=smptett, sample
c83f765c661595e1bfa4750756a54c006c6f2c697a436bc0726986f71f0706cd) has
">>" in the caption text, which is now written as "&gt;&gt;"; its
expected output has to be updated.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 4 (card C01a, "Basic
characters 1/3", starts at 00:18.00, expected text
!"#$%&'()á+,-./0123456789:;<=>?):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

cc1.ttml fails to parse (expat: "not well-formed (invalid token)" at the
'&' of that caption). With this change it parses and the caption reads
&amp; ... &lt;=&gt;.
When a row contains a styled run (<u>, <i> or <b>), the SMPTE-TT writer
closed it with "<style .../> </span>", that is it emitted a space after
the style element. Everything that follows the run therefore started one
column to the right of where the caption addresses it.

In CEA-608 a mid-row code is a spacing attribute that occupies exactly
one cell, like a displayable character: CTA-608-E Annex C.8 (p.74)
speaks of "Mid-Row codes and the FON command, as spacing attributes",
and C.13 (p.75) of "the character or Mid-Row Code occupying that
location". The decoder already stores that space in the screen memory
(handle_text_attr() calls write_char()), so the additional space in the
writer is spurious. Remove it.

Effect on the sample platform: regression test 161 (--out=smptett, sample
c83f765c661595e1bfa4750756a54c006c6f2c697a436bc0726986f71f0706cd) has
italic runs followed by a space; the space is no longer written inside
the <span> after the <style/> element, so its expected output has to be
updated (together with the change of the commit that escapes &, < and >).

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 28-31 (cards A05a-A05d,
"Mid-row codes", starting at 02:12.00) and test 55 (card D01,
"Paint-on: basic and mid-row", 05:50.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

In cc1.ttml the text that follows an underlined mid-row run in those
captions is placed one column further right than the card specifies.
A foreground colour (from a PAC or a mid-row code) was written to the
SMPTE-TT output with a hard-coded tts:backgroundColor of #FFFF00FF
(opaque yellow), so every coloured run was rendered on a yellow box
whatever the caption specified. The writer uses #000000FF for all the
other runs.

Without a background attribute code the caption's background is opaque
black: CTA-608-E section 6.2 (p.16) "opaque background should be the
default", and "If the code for a non-implemented background color is
received, the decoder should default to a black background". Writing
the foreground colour must therefore not change the background.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 19 and 20 (cards A02a and
A02b, "PAC colors", starting at 01:35.00 and 01:39.00) and tests 28-30
(cards A05a-A05c, "Mid-row codes", 02:12.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

The coloured spans in cc1.ttml carry tts:backgroundColor="#FFFF00FF".
The foreground colour of a coloured run was written as
tts:color="00ff00", without the leading '#'. In TTML a hexadecimal
<color> value is "#rrggbb" (or "#rrggbbaa"); a bare "00ff00" is not a
valid colour expression (W3C TTML1, section 8.2.2, "tts:color", and
section 8.3.2 for the <color> syntax), and a consumer treats it as
unspecified. The other colour attributes the writer emits
(tts:backgroundColor="#000000FF") already carry the '#'.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 19 and 20 (cards A02a and
A02b, "PAC colors", starting at 01:35.00 and 01:39.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

The coloured spans in cc1.ttml have tts:color without the '#'.
Two of the optional extended characters were mapped to the wrong glyph:

* 0x12 0x26 is the opening single quote (CTA-608-E 6.4.2, Table 5,
  p.20, with NOTE 3: "The curled opening single quote is the mirror
  image of the standard curled apostrophe"). It was output as the ASCII
  apostrophe, which is the closing quote of that pair. It is now U+2018
  in UTF-8 and UCS-2. Latin-1 has no such character, so it still falls
  back to the apostrophe, as does the SCC writer's backspace-fallback
  character.

* 0x13 0x2E is the pipe (Table 8, p.23: "| pipe ASCII"). It was output
  as U+00A6 (broken bar) in UTF-8 and 0xA6 in Latin-1. It is now the
  ASCII '|'.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 8 (card C03a,
"International characters - Spanish", starts at 00:38.00), test 9
(C03b, "Miscellaneous symbols", 00:44.00, which also uses the opening
quote in its sample phrase) and test 11 (C03d, "International
characters - Portuguese", 00:56.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 -utf8 --out=srt -o cc1.srt

The cards show the opening quote (U+2018) and, in C03d, the pipe '|';
the SRT has an apostrophe and U+00A6 in their places.
…racters

The extended characters that are meant for drawing boxes were rendered as
unrelated glyphs:

* 0x13 0x37 is the vertical bar (CTA-608-E 6.4.2, Table 9, p.24, NOTE 8:
  it extends over the whole height of its cell so that two of them one
  above the other appear connected). It was output as the ASCII '|',
  which is also what 0x13 0x2E (the ASCII pipe, Table 8) now maps to, so
  the two distinct characters could not be told apart.

* 0x13 0x3C-0x3F are the upper/lower left/right corners (Table 10, p.25,
  NOTE 9: "designed to be used with the em dash and vertical bar for
  drawing boxes"). UTF-8 and UCS-2 output used U+231C-U+231F (the
  corner marks used for quotation, which do not join up with anything).

Use the box-drawing characters U+2502 (vertical bar) and U+250C, U+2510,
U+2514, U+2518 (corners), which connect as the note describes. The
specification itself shows U+23D0 and U+23A1/U+23A4/U+23A3/U+23A6 for
these cells; the box-drawing set was chosen because it is available in
practically every font. Latin-1 has neither, so the vertical bar stays
'|' and the corners '?' there. The SCC writer's backspace-fallback
character for the vertical bar is now a space instead of '|'.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 12 (card C03e,
"International characters - German", starts at 01:02.00) for the vertical
bar and test 13 (C03f, "International characters - Danish", 01:08.00)
for the corners:

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 -utf8 --out=srt -o cc1.srt
lib_ccxr/src/util/encoding.rs carries a copy of the CEA-608 character
tables (line21_to_latin1(), line21_to_utf8(), line21_to_ucs2()) that the
Rust g608 writer and the text helpers use. Apply the changes made to
the C tables (src/lib_ccx/ccx_common_char_encoding.c) so that both give
the same output:

* 0x12 0x26 (opening single quote, CTA-608-E 6.4.2 Table 5, p.20) is
  U+2018 in UTF-8 and UCS-2 and no longer the apostrophe;
* 0x13 0x2E (pipe, Table 8, p.23) is the ASCII '|' and no longer U+00A6
  or 0xA6;
* 0x13 0x37 (vertical bar, Table 9, p.24) and 0x13 0x3C-0x3F (corners,
  Table 10, p.25) are the box-drawing characters U+2502, U+250C,
  U+2510, U+2514 and U+2518 in UTF-8 and UCS-2, instead of '|' and
  U+231C-U+231F.

The inverse mapping from UCS-2 is updated to match.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 8, 11, 12 and 13 (cards
C03a, C03d, C03e and C03f, starting at 00:38.00, 00:56.00, 01:02.00 and
01:08.00) with the g608 output:

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 -utf8 --out=g608 -o cc1.g608

lib_ccxr/src/util/encoding.rs gets unit tests for these characters in UTF-8, UCS-2 and Latin-1 and for the
inverse mapping from UCS-2; they fail on the previous tables.
After a Carriage Return in roll-up mode the decoder kept the colour and
underline/italics of the previous row, so a new row that is not preceded
by a PAC (or a mid-row code) inherited, for example, the yellow
underlined style of the row above.

CTA-608-E C.14 (p.75, "Special Cases Regarding Attributes (Normative)")
says: "It is also possible for a roll-up row, having been created by a
CR, to receive characters with no PAC used to set attributes. In these
cases, and in any other case where no explicit attributes have been
assigned, the display shall be white, non-underlined, non-italicized,
and non-flashing."

Reset the colour and font at the CR in roll-up mode.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 34 (card A08, "Default
attributes after CR", starts at 02:42.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=srt -o cc1.srt

The card writes a yellow underlined first row, sends CR and writes a
second row without a PAC; the second row must be white and not
underlined, but the SRT has it in yellow and underlined as well.
…se row

When a PAC for a different row arrived during roll-up captioning,
handle_pac() deleted every row below the PAC's row. With the caption at
base row 15 and a PAC for base row 8, that is the whole caption, so only
text received after the PAC survived.

CTA-608-E C.7 (p.73, Regulatory/Preferred): "A major exception is the
receipt of a PAC during roll-up captioning. In that case, if the base row
designated in the PAC is not the same as the current base row, the
display shall be moved immediately to the new base row." B.8.1 (p.65):
"To relocate the roll-up display immediately, send a PAC which implies
the new base row."

Move the rows of the displayed caption to the new base row instead. The
caption as it was before the move is written out first, with its old
position and end time, and the moved one is a new caption starting at the
PAC, like a roll-up caption that scrolls.

This is done only for the output formats that carry the position of a
caption (SMPTE-TT, spupng, WebVTT, ASS/SSA, SCC, CCD, MCC and the g608
dump). SRT, SAMI and the transcript formats have no position, so a move
does not make a different caption there, and a second entry for the same
text would only change their output: streams whose encoder sends a PAC for
another row after the first row of a roll-up (sample platform tests 22,
31, 89 and others) would get one caption split in two. Those formats keep
their previous handling.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 50 (card R07, "PAC moves a
displayed roll-up", starts at 05:04.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

The card shows three rows at base row 15, moves the block to base row 8
at +6 s with a PAC and continues there. cc1.ttml contains only the last
row ("Now at base row 8"); the three earlier rows are lost.
If the PAC of a roll-up caption addressed a row above the number of
roll-up rows (for example RU3 and a PAC for row 2), the caption cannot
be shown on the rows above the base row. handle_pac() then cleared the
rows below the PAC, i.e. the whole caption, and no text was output at all.

CTA-608-E C.4 (p.72, Roll-Up Row/Base Row Conflicts, Preferred): the FCC
allows decoders to resolve such a conflict "by giving precedence to the
caption depth (2, 3, or 4 rows) or to the base row. It is recommended
that decoders give precedence to the caption depth when the PAC received
is for a row number less than the number of roll-up rows. This method of
conflict resolution shall assure that no caption text is lost
inadvertently." The same recommendation is in B.5 (p.63-64).

Give precedence to the depth: when the PAC's row is smaller than the
number of roll-up rows, use the depth as the base row (row 3 for a
3-row roll-up and a PAC for row 2), which moves the caption there with
the previous commit.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 51 (card R08, "Roll-up
depth vs base-row conflict", starts at 05:16.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

The card shows a 3-row roll-up at base row 15 and then sends a PAC for
row 2. The preferred result keeps all three rows (base row 3). cc1.ttml
has no caption for the card at all.
…rames

A caption stayed on the screen, and was only ended by the next caption or
the end of the file, however long the line 21 data was missing or
invalid.

CTA-608-E C.21 (p.76-77, Regulatory): "Decoders also should
automatically disable the display and erase memory in response to loss of
valid data on line 21. After the display has been enabled, it shall not
be disabled until 45 consecutive frames have been received in which no
data are detected or in which at least one data byte has even parity.
If, while accumulating the 45 frames, a frame occurs in which both data
bytes have odd parity, the count of consecutive frames shall be reset to
zero." CEA-CEB-10-A 25.2.1 (p.39-40) and 20.2.4 (p.35) say that
cc_valid=0 for a line 21 field means that no waveform was present.

Check each field of every cc_data block that process_cc_data() handles
and erase both memories of a field (writing the displayed caption out,
as EDM does) when it has had no valid data for 45 frames. A valid pair
has cc_valid set and odd parity in both bytes (all-zero cc_valid=0 pairs
count as valid when fix_padding is on, as do_cb() treats them). The
fields are independent. The 45 frames are measured as 45 x 1001/30 ms of
stream time and not as a number of cc_data blocks, because a video
picture is not always a line 21 frame: with 59.94 Hz video a field's
pair comes only in every other picture.

Only the paths through process_cc_data() (MPEG-2 and H.264 in TS/PS/ES,
etc.) are affected; SCC, raw and DVD raw input do not carry the notion of
a frame without data. A stream whose encoder signals idle line 21 time
with cc_valid=0 instead of null pairs now has a caption erased after 1.5
seconds without data, as the specification requires.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 66-68 (cards S03, S04 and
S05, "Loss of data erases captions; recovery", "Field 2 loss only" and
"Invalid (even) parity data", starting at 07:54.00, 08:08.00 and
08:20.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=srt -o cc1.srt
  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -2 --out=srt -o cc3.srt

In S03 "Caption A: before data loss" must be erased 45 frames after the
cc_valid=0 gap starts at 07:57.00, but it lasts until 08:02.01 when
Caption B replaces it. S04 erases CC3 only (CC1 keeps its caption), and
S05 erases the caption 1.5 s after the even-parity data starts.

A small MPEG-2 transport stream made with the conformance suite's caption encoder (a pop-on caption, 2.5 s of
cc_valid=0 pairs in both fields, a second caption, 90 KB) shows the same.
eia608_to_str() joins the rows of a caption with newlines into the
string that spupng renders and copies into the XML. It added the newline
to the buffer and then incremented str_len a second time ("count the
newline even if truncated"), which is only meant for the case where the
newline did not fit. The next row was therefore copied one byte too far
and a NUL byte was left after the newline, so every row after the first
was cut off: both the PNG and the <!-- --> text of the XML held only the
first row of a multi-row caption.

Only count the newline when it was not stored.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 15 (card A01a, "PAC rows 1-4", four rows, starts at 01:19.00) or test 3
(card G02, "Safe caption area and 32x15 grid", rows at the corners, 00:12.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=spupng \
      -font <ttf> -italics <ttf> -o out

The spu entry of A01a has "Row 1" only, and sub0013.png shows one line.
With this change the entry lists Row 1 to Row 4 and the image has four
rows.
In the writer's table of preamble address codes the entry for indent 28
of every row had the second byte of the underlined PAC (0x5F, or 0x7F
for the rows that use the 0x60 range) instead of 0x5E / 0x7E. A caption
whose row started at column 29, or was addressed with an indent-28 PAC
and a Tab Offset, was therefore written underlined.

CTA-608-E Table 53 (p.101): "Indent 28" is 5E (rows 1, 3, 5, 7, 9, 11,
12, 14) and 7E (rows 2, 4, 6, 8, 10, 13, 15); "Indent 28 Underline" is
5F / 7F. All 120 entries of the table (15 rows, 8 indents) now agree
with the table, for both data channels (checked against Table 53).

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 24 (card A03b, "PAC
indents 16-28", starts at 01:55.00; the numbers 16, 20, 24 and 28 are
not underlined):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=scc -o cc1.scc

The line for the card has the PAC 10 5F (underlined, ignoring the parity
bits) before the "28"; decoded again, the "28" is underlined.
The writer remembered the font of the last character it wrote and only
wrote an underline code when the font changed. But a PAC puts the
attributes back to white, not underlined, not italic, so after moving to
another column or row the underline was lost: in a caption with several
underlined words on different rows only the first one stayed underlined
when the SCC was decoded again.

CTA-608-E C.7 (p.73): "An indenting PAC carries the attributes of white,
non-italicized, and it sets underlining on or off. Tab Offset commands do
not change these attributes. If an indenting PAC with underline ON is
received followed by a Tab Offset and by text, the text shall be
underlined."

After a change of position, compare the cell with white regular text, not
with the previous cell. White underlined text is written with the
underlined indent PAC (Table 53, "Indent N Underline", second byte
0x51 + 2 * indent / 4, or 0x71 + ... on the rows that use that range)
and a Tab Offset if the column is not a multiple of 4. No mid-row code
is needed, which would take a cell of its own. Other styles keep using
the styled PAC at column 0 or a mid-row code.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 25 (card A03c, "PAC indents
0-12 underlined", starts at 01:59.00; every number is underlined):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=scc -o cc1.scc

Only the first PAC of the card's SCC line has the underline (0x41); the
indent 4, 8 and 12 PACs are 0x52, 0x54 and 0x56 and the numbers come back
plain when the file is decoded again.
… later

get_color_events() closes a colour after the last character that has it
(it stores the closing event at index i - 1, where i is the first
character with the next colour). get_font_events() did the same thing for
the font (underline, italics) but stored the event at index i, so the
closing tag was written after the first character that is no longer
underlined or italic: "The<u> White UL </u>Mid-Row" instead of
"The<u> White UL</u> Mid-Row", with the next cell underlined. The mid-row
code that ends the run is a cell with the new, plain attributes
(CTA-608-E Table 51, p.99; C.8 p.74, a mid-row code is a spacing
attribute that occupies a cell), so that cell must not be underlined.

Store the closing event of a font at i - 1, as for the colours.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 28-31 (cards A05a-A05d,
"Mid-row codes", start at 02:12.00) and test 55 (card D01, "Paint-on:
basic and mid-row", 05:50.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=webvtt-full -o cc1.vtt

For the underlined rows of those cards the </u> comes one cell late:
The<u> White UL </u>Mid-Row Code (the space after "UL" is underlined),
where --out=srt has <u> White UL</u> Mid-Row Code.
The start time of a Dialogue line was written with "%01u" for the
centiseconds, so 12.013 s was "0:00:12.1" and 12.100 s was "0:00:12.10".
The format is H:MM:SS.cc (two digits of centiseconds, as the end time
already was); a parser that reads the digits after the point as a
decimal fraction, as many do, reads 12.1 for the first and puts the
caption up to 0.09 s late for a one digit value below 10 centiseconds.

Use "%02u" in the three places that write the Dialogue header.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 3 (card G02, "Safe caption
area and 32x15 grid", starts at 00:12.00):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=ass -o cc1.ass

The Dialogue line of the card starts at 0:00:12.1, which is 12.013 s as
centiseconds (01) but 12.1 s as a decimal.
The ASS/SSA writer used the same text as SubRip: <font color="...">, <u>
and <i>. ASS does not know those tags, so a renderer prints them: with
libass (ffmpeg's ass filter) a caption with a coloured or underlined run
showed <font color="#0000ff"> and <u> in the picture. And '{' (the
extended character 0x13 0x29, and '}' 0x13 0x2A) opens an override block
in ASS, so a renderer dropped the braces and everything between them.

In the override syntax of ASS the colour is {\c&Hbbggrr&}, underline
{\u1} and {\u0}, italics {\i1} and {\i0}, and a literal brace is \{ or \}.
get_decoder_line_encoded_markup() takes the markup as an argument and
LINE_MARKUP_ASS makes it, and close_tag(), write the ASS tags and escape
the braces. The ASS writer passes it; the other callers keep using
get_decoder_line_encoded(), which stays the HTML wrapper. Closing a colour goes back to white, the colour of the default
style.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, test 29 (card A05b, "Mid-row
codes 2/4", starts at 02:16.00) for the tags and test 11 (card C03d,
"International characters - Portuguese", 00:56.00) for the braces:

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=ass -o cc1.ass

A05b rendered with libass shows the tags as text (<font
color="#0000ff"> Blue</font> ...), and in C03d the "{ }" of the row is
gone.
write_cc_buffer_as_smptett() looked for the first <i>, then the first
<b>, then the first <u> in the text of a row, turned that one run into a
<span> with a <style/> and copied the rest unchanged. A row with a second
styled run, or with a coloured run that was also underlined, therefore
kept raw <font>, <u> and <i> elements in the TTML. They are not TTML, so
a renderer ignores them and the colour or underline is lost (and the
document no longer validates).

Replace that string handling with one pass over the text that tracks the
colour, underline and italics and writes a <span>text<style .../></span>
for every run that has any of them. A run with several attributes gets
them all in one <style/>; the output for a row with a single run is
unchanged. A row can have any number of runs.

The problem was found with the CEA-608 Conformance Suite
(https://github.com/dheitmueller/cea608-conformance-suite). To reproduce,
use its stream
CEA608-conformance-v1.2-720p59-h264.ts, tests 21 and 22 (cards A02c and
A02d, "PAC colors" with underline, start at 01:43.00 and 01:47.00), tests
28-31 (A05a-A05d, "Mid-row codes", 02:12.00) and test 34 (A08):

  ccextractor CEA608-conformance-v1.2-720p59-h264.ts -1 --out=smptett -o cc1.ttml

Rows such as "Green UL" or "The Blue Mid-Row Code" with a second run have
<font color="#00ff00"><u>...</u></font> in cc1.ttml.
@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 170/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 31/34

68 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:

  • 1 pass there and fail here
  • 0 fail there and pass here
  • 2 fail on both, with different output
  • 65 fail on both, byte for byte the same

Pass there, fail here:

  • ccextractor --autoprogram --out=smptett --latin1 --ucla e274a73653...

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


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.


This branch changes the behaviour of 3 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 windows. 170/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 31/34

68 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 10179, commit f56427e:

  • 1 pass there and fail here
  • 0 fail there and pass here
  • 2 fail on both, with different output
  • 65 fail on both, byte for byte the same

Pass there, fail here:

  • ccextractor --autoprogram --out=smptett --latin1 --ucla e274a73653...

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


Compared with the commit this branch was cut from — test 10181, commit 2c1c1c6:

  • 1 pass there and fail here
  • 0 fail there and pass here
  • 2 fail on both, with different output
  • 65 fail on both, byte for byte the same

Pass there, fail here:

  • ccextractor --autoprogram --out=smptett --latin1 --ucla e274a73653...

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


This branch changes the behaviour of 3 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.

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