Log in

View Full Version : DVD EIA-608 Closed Captions timing source


Earthnuker
4th November 2021, 22:53
Hello everyone,

i am currently working on a tool to extract EIA-608 closed captions from MPEG2 streams demuxed from VOB files. Mainly as a learning excercise but also because ffmpeg's extractor doesn't work properly for me and neither does CCExtractor.

The decoding of the text itself works fine, but from the information i could find (EIA-608 Wikipedia article, VLC source code, ffmpeg source code, mencoder source code) it is not really clear to me where the timestamps for when to display the captions come from, when i use the PTS of the packet containing the "Display Buffer" control command the captions are delayed by a factor of about 12 (i.e. they run 12 times slower than they should).

VLC displays the caption without issue and with proper timing.

i hope someone can point me in the right direction.

(the end goal is to wrap this and some other tooling i wrote up in a script as a headless (maybe i'll add a GUI when everything works), cross-platform alternative to MakeMKV that's aimed at preparing DVDs for filtering using Vapoursynth or AVISynth)

Best regards,

Earthnuker

Emulgator
4th November 2021, 23:36
http://www.theneitherworld.com/mcpoodle/SCC_TOOLS/DOCS/SCC_TOOLS.HTML
https://www.zilog.com/docs/tv/z86229.pdf

Earthnuker
5th November 2021, 00:51
http://www.theneitherworld.com/mcpoodle/SCC_TOOLS/DOCS/SCC_TOOLS.HTML
https://www.zilog.com/docs/tv/z86229.pdf

Thanks for the reply,

sadly the tools linked on the SCC Tools website are windows only, which defeats the purpose of my endeavor and closed source which allows no easy introspection into how they work.

The datasheet for the Zilog Z86229 NTSC Line 21 CCD Decoder chip, while very interesting, also does not fit my use case, as i am not trying to extract captions from an NTSC broadcast transmitted over the air but from an MPEG2 elementary stream demuxed from a VOB file which was retrieved from a DVD.

Best regards,

Earthnuker

Earthnuker
5th November 2021, 01:09
I should probably give a quick overview of how my closed-captions extractor works to make sure I'm not missing anything obvious:

- use ffprobe -f lavfi -i movie=foo.m2v[out+subcc] -show_packets to retrieve the position and timestamp of subtitle packets within the mpeg stream
- seek to the corresponding position+42 in the file, make sure there is a 000001B24343 marker
- retrieve caption blocks, process commands and update the state of the caption-rendering state machine accordingly
- if a "Display Buffer" command is received, retrieve all non-empty lines from the current screen buffer and print them to the console, along with the PTS of the MPEG2 packet that contained the "Display Buffer" command

my code is here: https://pastebin.com/DGPFa2Mm it's a bit messy because i hacked it together in two days

Best regards,

Earthnuker