forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

dvdsubs.report.md4.8 KiBHistoryRawDownload

lane/dvdsubs: DVD (VobSub) and DVB bitmap subtitles

What was added

  • ec-core registry: CodecId::DvdSub (dvd_subtitle) and CodecId::DvbSub (dvb_subtitle), both MediaType::Subtitle. Variants are contiguous after RawVideo; test list count 41 -> 43.
  • ec-dvdsub (new crate): SPU decode (decode_spu), .idx / Matroska CodecPrivate text (parse_idx: size:, palette:, id:, timestamp:/filepos:), SpuAssembler (units are cut from the PES byte stream by their size field, PTS handed out in order), sub_file_units (standalone .sub MPEG-PS, private stream 1 substreams 0x20-0x3f), DvdSubDecoder (+ make_decoder).
  • ec-dvbsub (new crate): page / region / CLUT / object (2, 4, 8 bit, map tables, top/bottom field) / display-definition / end-of-set segments; DvbSubDecoder (+ make_decoder). Spec default CLUTs when none is sent.
  • Container wiring: Matroska S_VOBSUB and S_DVBSUB (demux + codec id in mux); MPEG-PS private stream 1 0x20-0x3f (was a refusal) -> StreamKind::DvdSub; MPEG-TS stream_type 0x06 with descriptor 0x59 -> StreamKind::DvbSub; mp4 mp4s sample entry with esds object type 0xE0 -> DvdSub (extradata = the idx text from the decoder-specific info). Bitmap subtitle streams (PGS, DVD, DVB) no longer wait for 3 packets / a timing probe.
  • Fuzz targets (same layout as ec-pgs): ec-dvdsub/fuzz (unit, sub_file), ec-dvbsub/fuzz (packets). Plus in-crate "rubbish never panics" tests.
  • Fixtures: tiny files under crates/ec-dvdsub/tests/data and crates/ec-dvbsub/tests/data, regenerated by scripts/gen-bitmap-sub-fixtures.sh (ffmpeg's dvdsub/dvbsub encoders need bitmaps, so the source is a synthetic 720x576 PGS from scripts/gen-bitmap-sub-fixtures.py, four cues; no third-party media).

Output type (what edith consumes)

Same as ec-pgs: Decoder::receive_frame gives Frame::Video RGBA8 straight-alpha, canvas-sized (720x576 by default; DVD takes size: from the idx text; DVB takes the display-definition segment), transparent where nothing is painted. Richer API next to it:

  • DVD: DvdSubDecoder::take_cue() -> Cue { frame, area (x,y,w,h), start_90k, end_90k: Option, forced }. Times are 90 kHz ticks after the packet PTS (SPU delay unit 1024/90000 s). frame.pts = packet pts + start delay. end_90k = None means "until the next cue". The decoder is built with DvdSubDecoder::new(extradata) (idx text); without a palette it uses the DVD default 16-colour table (what ffmpeg's encoder writes). For VOB/PS there is no IFO reader here: the caller passes the palette as idx text (palette: rrggbb, ...), e.g. built from the IFO.
  • DVB: DvbSubDecoder::take_cue() -> DvbCue { frame, timeout_ms, empty, page_state, regions }. A set with no regions yields empty: true (a clear). Display time = packet pts .. pts + timeout_ms, or the next set.
  • Packet framing: DVB takes the TS PES payload (20 00 0f ...) or the Matroska block (no 20 00); DVD takes one whole SPU per packet (mkv, mp4) - ec-mpegts reassembles units for VOB/PS.

edith needs: map CodecId::DvdSub / DvbSub to ec_dvdsub::make_decoder / ec_dvbsub::make_decoder where it maps Pgs; to show end times for DVD use take_cue() (or the next frame's pts), and for DVB timeout_ms; list the new codecs as bitmap subtitle in the track picker. Nothing in edith's crates/app was touched.

Verification (ffmpeg 8.1 as oracle; sub2video frames as raw RGBA)

  • DVD: mkv (S_VOBSUB), VOB (-target pal-dvd, private stream 1), mp4 (mp4s), .idx/.sub pair: 4 cues each, pixel-exact (0 differing pixels, alpha and RGB), starts within 2 ms, ends within 15 ms of ffmpeg. VOB, mp4 and idx/sub are compared against the mkv oracle frames (same cues) with one constant time shift for the muxing offset.
  • DVB: mkv (S_DVBSUB) and TS (0x06 + subtitling descriptor): 4 cues each, pixel-exact (max channel delta 0), starts within 2 ms.
  • Tests: crates/ec-dvdsub/tests/ffmpeg_parity.rs, crates/ec-dvbsub/tests/ffmpeg_parity.rs (skip loudly without ffmpeg; EC_REQUIRE_FIXTURES=1 makes that a failure).

Known limits

  • DVD: the colour/contrast change command (0x07) is skipped, not applied (menu highlights); forced flag is reported, not filtered. ffmpeg's own VOB muxer with a video stream (-f vob without -target) packs units across PES packets and states one PTS per two units; units without a PTS get pts = None (a standard disc and -target pal-dvd give one PTS per unit and decode fully).
  • DVB: character-coded objects (coding method 1) and the ancillary/composition page-id split are ignored (all page ids are decoded together); region/object state across epochs follows the page state (acquisition/mode change clears it). The ffmpeg fixtures exercise only the depth ffmpeg's encoder picks; the other depths are covered by hand-built unit tests.
  • Only whole-set cues are produced; edith does the compositing.