Repository navigation
Render in-band CEA-608 closed captions (#77) - #81
Conversation
Decode embedded eia_608 / c608 caption tracks (which have no FFmpeg ccaption decoder and previously sat active-but-blank) via a read-only observer on the segment producer's source connection, an in-house CEA-608 decoder, and the existing host-overlay subtitleCues path. No second demuxer/connection; segment output byte-identical; #55 native mov_text rendition untouched. First cut: 608 field-1 / CC1. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Screen.Recording.2026-06-26.at.4.08.20.PM.mov |
|
Merged and shipped in 4.6.0. Thanks @reckloon, this is a clean, well-tested implementation that lands exactly the externalised approach from the discussion: the read-only producer tap keeps the loopback segment output byte-identical, and the in-house CEA-608 decoder matches FFmpeg's Follow-ons noted for later: CEA-708 (DTVCC), 608 field 2 / channels CC2 to CC4, and the SEI-only carriage. Thanks also @DrHurt for the externalise-subtitles steer. |
Summary
A source whose only caption track is an embedded CEA-608 stream (
eia_608, e.g. a QuickTime/MP4c608track) currently can't render. FFmpegBuild ships noccaptiondecoder, so the side-demuxerEmbeddedSubtitleDecoderopen fails and the track sits active-but-blank (subActive=true / subCues=0) — selectable but producing no cues for the whole title.This PR decodes those captions in-house and renders them through the existing host-overlay subtitle path, without standing up a second demuxer, a second connection, or touching any existing pipeline. The caption bytes are read off the segment producer's source connection that the engine already holds.
Closes the rendering half of #77. First cut: 608 field-1 / channel CC1; CEA-708 (DTVCC) and field 2 are explicit follow-ons.
What it does
eia_608now renders its captions on the host overlay (subtitleCues), exactly like every other side-decoded subtitle codec (SRT/ASS/PGS/DVB).Architecture
Three pieces, all additive; the caption bytes ride the connection the producer already reads.
CCDataParser(new) — parses the barecc_datatriplet stream FFmpeg's MOV demuxer emits for ac608track (it strips thecdat/cdt2atom wrapper and hands downstream(cc_valid|cc_type, b0, b1)triplets). Pure byte parsing.CEA608Decoder(new) — an in-house line-21 state machine: pop-on / roll-up / paint-on, PAC row addressing, mid-row codes, and the basic / special / extended West-European character sets. Odd-parity validation, doubled-control suppression, the character tables and PAC bounds are all validated against FFmpeg'sccaption_dec.c(the decoder mpv/VLC mirror) and covered by unit tests.ClosedCaptionTap(new) — a read-only observer attached to the producer's source demuxer. The producer keeps theeia_608stream in its keep-set, hands each of its packets to the tap, then drops it (never muxed). The tap decodes on the pump thread, owns the cue buffer, and publishes immutable snapshots to the MainActor, which mirrors them intosubtitleCuesonly while the CC track is the active subtitle.Because the tap owns the buffer and
makeProducerre-threads the observer onto every producer (initial + restart), enabling CC mirrors the buffer instantly and seeks/reloads/wedges re-feed it automatically — no second connection, no per-seek re-arm. Snapshot delivery is sequence-guarded against out-of-order MainActor hops; the tap drops decoder + buffer state on an explicit seek (requestReset()fromseek()).Minimal interference — existing pipelines intact
closedCaptionStreamIndex == -1and every site is a no-op — the loopback-HLS segments are bit-for-bit unchanged.mov_textrendition untouched. CC is excluded from thetextTracksfilter (a caption track can't becometx3g) and rendered on the overlay like the bitmap subtitle codecs. Consistent limitation: host-overlay only, so no PiP/AirPlay CC (same as PGS/DVB today).Demuxer.trackInfo— fall back toavcodec_get_namewhen no decoder exists, so the track is identifiable (eia_608) instead of"unknown". Cannot affect any track that has a decoder.AetherEngine+Probe— add anisEmbeddedClosedCaptionCodecclassifier besideisBitmapSubtitleCodec.AetherEngine+Loading— exclude CC from themov_textfilter; arm the tap beforestart().AetherEngine+Subtitles/AetherEngine— route CC selection to mirror the tap's snapshot; reset the tap on seek.HLSVideoEngine— thread the CC stream index + observer onto every producer (same pattern as the Native subtitle rendition (AVMediaSelection / WebVTT) so subtitles survive PiP, AirPlay & external display #55subtitleCueStoresthreading).HLSSegmentProducer— one keep-set entry + one read-only observer call.Scope / limitations (stated)
tx3g, so no PiP/AirPlay CC) — same as the existing bitmap subtitle path.eia_608/c608). Captions carried only in the video bitstream SEI (no separate track) are out of scope here.Extending this system (future work)
The architecture splits cleanly into producer → parser → decoder →
subtitleCuesoverlay, and the overlay is the universal sink: anything that can emit timed text cues plugs in the same way. That makes several follow-ons cheap, in roughly increasing cost:cc_datatriplets from the caption stream and currently filters to field-1 (cc_type == 0);cc_type 2/3(708) andcc_type 1(field 2) flow through the exact same observer. Adding them is purely a decode-side change: reassemble the DTVCC packets (708) or extend the existing 608 channel handling (field 2 / CC2–CC4) and publish to the same buffer. No second connection, no producer changes.timed_id3text feed) can keep its stream in the producer keep-set, hand its packets to a small purpose-built parser, and publish cues — identical shape toClosedCaptionTap, byte-identical output preserved.subtitleCues. Heavier (it requires pixel decode), and best gated to on-demand, but it lands on the very same overlay — so the host UI, styling, positioning, and selection are unchanged.In short:
subtitleCuesis the extension point. For in-band data, copy the read-only producer-tap; for pixel-baked text, add a frame-OCR producer; either way the rendering, host overlay, seek/reload survival, and instant-enable behavior come for free.Files
New:
Decoder/CCDataParser.swift,Decoder/CEA608Decoder.swift,AetherEngine+ClosedCaptions.swift, plusTests/AetherEngineTests/CCDataParserTests.swiftandCEA608DecoderTests.swift.Edited:
Demuxer/Demuxer.swift,AetherEngine+Probe.swift,AetherEngine+Loading.swift,AetherEngine+Subtitles.swift,AetherEngine.swift,Video/HLSVideoEngine.swift,Video/HLSSegmentProducer.swift,CHANGELOG.md.Test plan
CCDataParsertriplet parsing (cc_valid/cc_type, bounds) andCEA608Decoder(pop-on display/erase, roll-up on CR, doubled- and tripled-control suppression, odd-parity rejection, extended-glyph correctness,reset()). FullAetherEngineTestssuite passes (221 tests, 0 failures) on macOS.eia_608MP4. Verified: captions render and stay in sync from cold start and on resume; survive short and long seeks; survive Jellyfin direct-stream reload; no A/V or audio regression. Selecting the track shows captions immediately.Acknowledgements
Externalise-subtitles steer by DrHurt.
🤖 Generated with Claude Code