Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#11591 closed defect (fixed)

[Regression] Closed Captions encoding garbled

Reported by: Jacob Lifshay Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: mpeg12enc
Cc: Jacob Lifshay, MasterQuestionable Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes

Description

Summary of the bug:
I discovered that closed captions side data gets corrupted by the mpeg2 encoder, I was able to bisect it to:
6e225123d8583f avcodec/mpeg12enc: Simplify writing bits
https://git.ffmpeg.org/gitweb/ffmpeg.git/commitdiff/6e225123d8583f

How to reproduce:
Download the Closedcaption_rollup.m2v file from ffmpeg's rsync server to ~/Downloads/Closedcaption_rollup.m2v
Install ffmpeg 7:5.1.6-0+deb12u1 from Debian 12

./configure --assert-level=2 --disable-vulkan --disable-stripping --optflags=-Og
make -j$(nproc)
ffmpeg -y -i ~/Downloads/Closedcaption_rollup.m2v cc_rollup-good.mxf
./ffmpeg -y -i ~/Downloads/Closedcaption_rollup.m2v cc_rollup-test.mxf
./ffmpeg -y -f lavfi -i "movie=cc_rollup-good.mxf[out+subcc]" -map 0:s -c:s copy -f rcwt cc_rollup-good.mxf.rcwt
./ffmpeg -y -f lavfi -i "movie=cc_rollup-test.mxf[out+subcc]" -map 0:s -c:s copy -f rcwt cc_rollup-test.mxf.rcwt
diff -y <(hexdump -C cc_rollup-good.mxf.rcwt) <(hexdump -C cc_rollup-test.mxf.rcwt)

the first closed caption chunk on the good one is just:

fc 80 80  fd 80 80

but on the bad commit it is:

fc 80 80  fd 80 80  0f f0 00  23 f8 75  94 88 b2
d4 68 52  e3 45 a1  8b 2d 46  85 22 2c  b5 1a 14
d4 85 22  2c d1 a1  8b 2d 06  a5 22 2c  b5 1a 14
d4 68 47

that is far from the only one that's bad.

Change History (3)

comment:1 by mkver, 14 months ago

Keywords: regression mpeg2video added
Resolution: fixed
Status: newclosed

Fixed in 45daaf2caaa3dc8bf8c505a9fc61a61b989721dc. Thanks for the report and sorry for the inconvenience.

comment:2 by MasterQuestionable, 14 months ago

Analyzed by developer: set
Cc: MasterQuestionable added
Keywords: mpeg12enc added; regression mpeg2video removed
Summary: closed captions side data gets corrupted by mpeg2 encoder[Regression] Closed Captions extraction garbled

͏    @ 2025-05-16T10:20:18Z
͏    avcodec/mpeg12enc: Fix writing closed captions
https://github.com/FFmpeg/FFmpeg/commit/45daaf2caaa3dc8bf8c505a9fc61a61b989721dc
͏    “"ff_copy_bits" expects the amount of bits, not bytes to write.
͏    And because it relies on the buffer to be padded: using `side_data->size * 8` is not possible.
͏    So partially revert said commit.”

͏    ----

͏    @ 2025-03-07T14:19:03Z
͏    avcodec/mpeg12enc: Simplify writing bits
͏    https://github.com/FFmpeg/FFmpeg/commit/6e225123d8583fdce55037b85eaef5453f201959
͏    .
͏    Looks like unintended change caused.

͏    For reference:
͏    https://trac.ffmpeg.org/ticket/11263#comment:12
͏    (probably not much related)

comment:3 by Jacob Lifshay, 14 months ago

Summary: [Regression] Closed Captions extraction garbled[Regression] Closed Captions encoding garbled

this is an issue with encoding closed captions, not extracting them. I did verify that the bad captions are in a hex dump of the final mpeg2 file.

Note: See TracTickets for help on using tickets.