edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane edith-mpegts report
Branch lane-mpegts (worktree /home/user/.cache/wt/edith-mpegts), rebased onto 3feda907 (format v46) with no conflicts. Commits: 997805d2 (MPEG-TS), c8005c44 (clippy clean-ups), f56a8796 (MPEG-2 video + MPEG audio layers I/II, tests).
Commits use gitmoji messages and carry no trailers.
What changed (extension: MPEG-2 video, MP2/MP1)
- MPEG-2 video (stream types 0x01/0x02,
CodecId::Mpeg2Video) is now decoded, always in software, byec-mpeg2:demux.rs: newCodec::Mpeg2(name "MPEG-2"). Reachable only from a transport stream; the MatroskaV_MPEG2row inUNSUPPORTEDstays (an mkv with MPEG-2 is still refused as before, no work was asked there).demux/ts.rs: the sequence header + extension is the config, re-injected ahead of any keyframe that lacks one (a seek landing on a bare I picture still decodes). Profile is read as ffprobe spells it (Simple, Main, High, 4:2:2).Demuxer::h264_interlaced()is true for an MPEG-2 sequence withprogressive_sequence0 (name kept, doc says so).decode/mpeg2.rs(new):Stream+run_mpeg2, the same shape as the HEVC/VP8 seats. Registered inPulled(decode.rs), so playback, scrub, thumbnails and export all read the one decode.hw_decodesrefuses MPEG-2 by name ("plays on the ec-mpeg2 software seat"), engine-hw has a no-op arm (Codec::Mpeg2 => return None).- Interlace: an interlaced sequence goes through the existing
Deinterlacer, picture by picture (newDeinterlacer::flagged_only(): a picture coded progressive in an interlaced sequence, i.e. a film cadence, passes untouched; only pictures that state a field order are filtered).deinterlace::field_orderreads the first interlaced picture's order from ec-mpeg2 (probe reportstff/bff). The clip'sDeinterlacesetting is honoured the way H.264 honours it: stored only, behaviour is theFrameone; when the other lane makes the setting act, the Mpeg2 seat uses the sameDeinterlacerso it follows. - 4:2:2 (
I422) is averaged down a pair of chroma rows to 4:2:0 byDeep::load, exactly as H.264 4:2:2. - Seeks: land on the keyframe at or before the target (one earlier for an interlaced sequence, for the deinterlacer's predecessor). ec-mpeg2 drops the open-GOP B pictures that lack a forward reference, as ffmpeg does; they sit before the landing I picture in display order so the display index counts from the I picture. A seek equals the sequential decode (tested, deinterlaced too).
colorspace.rs: MPEG-2 colour tags from the sequence display extension, chroma from the sequence extension.
- MPEG audio Layers I and II (
CodecId::Mp1/Mp2): routed toec-mp3throughec_mp3::layer_codec_parameters, the sameTsDecoder::Mp3that serves Layer III. Probe names themmp1/mp2/mp3, decodable. - Refusals left: DTS, TrueHD (and DTS-HD), LATM. The old MPEG-2 and MP2 refusal tests were removed.
- Cargo.toml: second added line (see below).
What changed (first round)
crates/engine/src/demux/ts.rs(new, a child ofdemux.rs):is_mpegts(path)recognises a transport stream by extension (ts mts m2ts m2t tp trp) or by content. A file with an EBML orftypmagic is never taken for one.TsDemuxeris the picture reader. It returns Annex-B access units with SPS/PPS re-injected on keyframes that lack them. Frame count and rate come fromec-mpegtstiming. Seeks useSyncBeforeand return the display index of the keyframe they land on.TsAudioandTsDecoderread one sound track through their own demuxer, so a seek on the sound alone lands where the sound is. They decode AAC-ADTS (ec-aac), AC-3 and E-AC-3 (ec-ac3, folded to a stereo pair by the decoder), MP1/MP2/MP3 (ec-mp3) and HDMV LPCM (PcmS16BeandPcmS24Le). A seek reopens or Exact-seeks backwards with growing slack until the first audio packet is at or before the target, then runs a 0.35 s pre-roll through a fresh decoder.subtitles()returns PGS tracks as the sameMkvSubtitledisplay sets thatsubtitle::pgs_cuesalready reads.header_streams()feeds the probe.refusal_text()appends the ffmpeg conversion to a refusal.
demux.rs: new variantDemuxer::Tswith a match arm in everyDemuxermethod. Alsoprobe_bitrate,stated_secs,sync_points(returns empty),header_streams,container_name(mpegts, ormts/m2ts) and the pub re-exportdemux::is_mpegts.audio.rs:- New
Track::Ts(Box<TsAudio>), withrun_tsand theTrack::open,segment,check_decoder,copy_track,probe_streamsandunsupportedhooks. It is never stream-copied:copy_trackreports "uncopyable" and the export re-encodes. - Refused sound tracks (DTS, TrueHD, LATM) are listed by
probe_streamsasdecodable: falseunder their ffprobe name. Opening one yields a silent source.unsupported()names it with the ffmpeg line. run_tsplaces each packet by its timestamp. Sound that starts after the picture leaves leading silence. Sound that starts before frame 0 is trimmed.
- New
subtitle.rs:of_medianow dispatches to the newof_mpegts.mcp/src/tools/media.rs:"hdmv_pgs_subtitle"is namedpgs, and a transport stream skips the mp4 subtitle walk.crates/app/src/subs.rs: one line, the extension list incarries_subtitlesnow includests,m2ts,mtsandm2t. This is the exception you approved.crates/engine/tests/mpegts.rs(new): 9 tests.
Time model. Source time 0 is the first picture's earliest PTS, because the engine's frame 0 sits at t=0. A file with no picture counts from its first sound.
This differs from "earliest stream start". Sound that starts before the picture is trimmed to the picture, which keeps the A/V offset.
Cargo.toml
Two lines added to crates/engine/Cargo.toml, each with a comment above it:
ec-mpegts = { path = "../../../edith_codecs/crates/ec-mpegts" }
ec-mpeg2 = { path = "../../../edith_codecs/crates/ec-mpeg2" }
export.rs hunks
One hunk. The copyable expression near line 2945 gains || crate::demux::is_mpegts(&source.path). This only affects the card label, so it names a re-encode instead of a copy. CopyPlan already refuses non-Matroska sources, so a TS export always re-encodes.
GUI and peer-owned changes needed
-
crates/engine/src/playback.rs,parse_subtitles(about line 1798, peer-owned, NOT edited). The exact diff for its owner:let tracks = match crate::demux::is_matroska(path) + || crate::demux::is_mpegts(path) || path.extension().is_some_and(|e| {(
is_mpegtsis a pub re-export fromengine::demux; it does a cheap extension check, then a content sniff for unknown extensions.) Background: PGS from an.m2tsdoes NOT flow through thesubs.rsgate alone.parse_subtitlesonly callssubtitle::of_mediafor Matroska andmp4|m4v|mov. Any other extension is read as a standalone subtitle file and refused. The needed change:- add
|| crate::demux::is_mpegts(path)to the condition that selectssubtitle::of_media, or - add
"ts" | "m2ts" | "mts" | "m2t"to its extension list. - The engine side (
subtitle::of_mediatoof_mpegts) is ready.
- add
-
File dialog:
pick_fileincrates/app/src/files.rswas not inspected for extension filters. No extension list was found incrates/app/srcother thansubs.rs.
Tests (server host c, release)
cargo test -p engine --release --test mpegts passes 12 of 12 on the final tree (server host c, ffmpeg-skip convention kept). All sources are synthetic: testsrc2, a flash on black, a chirp and a beep.
- Picture vs ffmpeg:
.ts,.m2ts,.mts, a.tswith a start offset, and a video-only.ts. Probe gives codec, 352x288, 25 fps, 50 frames, and duration within 1 frame. The ec-h264 planes are byte-identical to ffmpeg's. - Seeks and remux: H.264 and HEVC (including a +10 s start).
open_atat 14 targets andopen_rangeequal the sequential decode. Sequential frames are bit-identical to the mp4 remux of the same stream. - Sound vs ffmpeg: AAC, AC-3, MP3, LPCM, and a two-audio
.mts(AC-3 plus pcm_bluray). Compared from 0, 0.4, 1.1 and 1.7 s with the picture-relative offset applied. Largest difference: AAC 1.6e-5, AC-3 2.9e-5, MP3 2e-6, LPCM 0 (the tolerance was 1.5e-3, or 1e-6 for LPCM). A seek equals the sequential decode within 1e-4. - Sync: flash at frame 25 (1.0 s) and beep at 1.0 s, with the beep within 65 ms. Covers start 0, start 10 s, 2 s before the 33-bit wrap, and a wrap in mid-clip. After a seek the beep stays within 2 ms and the picture seek lands on frame 25.
- Fake AVCHD: 1920x1080 tff, AC-3 plus pcm_bluray, 192-byte packets,
.mts.interlaced == "tff", 20 frames, planes equal to ffmpeg's, 20 deinterlaced session frames, both sound tracks decode, and the mp4 export has the right duration and frame count and has sound. - Export:
.mts(AC-3, +10 s) and.ts(AAC) to mp4. Length is 2.4 s ± 0.1, flash within 45 ms of 1.0 s, and beep within 90 ms of the flash. - MPEG-2 video (
mpeg2_video_opens_probes_and_decodes_as_ffmpeg_does): progressive.ts(MP2 sound),.m2tswith +10 s start (AC-3), interlaced tff, interlaced bff, 4:2:2 profile. Probe: codec Mpeg2, 352x288, 25 fps, 50 frames, duration within a frame,interlacedtff/bff/None, profile Main/4:2:2,mpeg2videoin the stream list. ec-mpeg2's planes through the engine's demuxer are byte-identical to ffmpeg's (4:2:0 and 4:2:2). The session yields frames 0..50. - MPEG-2 seeks (
mpeg2_seeks_equal_a_sequential_decode): same 5 shapes,open_atat 14 targets andopen_rangeequal the sequential session frames bit for bit (deinterlaced shapes included). - Deinterlace (
interlaced_mpeg2_is_deinterlaced_and_progressive_mpeg2_is_not): the session's frames of an interlaced file have less row-to-row comb energy than ffmpeg's woven frames. - MP2 sound is in the sound test (
mp2.tswith H.264 video,dvb.tsMPEG-2 + MP2 at +10 s): worst difference vs ffmpeg 3.2e-5 at 0, 0.4, 1.1, 1.7 s, and a seek equals the sequential decode. Sync test gained three DVB cases (MPEG-2 + MP2 at start 0, 10 s and a 33-bit wrap in mid-clip): flash on frame 25, beep within 65 ms, steady after a seek. The export test gaineddvb.tsanddvb-off.ts(MPEG-2 + MP2, start 0 and 10 s): length 2.4 s +/- 0.1, flash within 45 ms, beep within 90 ms of the flash. A renamed MPEG-2.datopens by content. - Refusals (
dts_and_truehd_tracks_are_refused_by_name_and_the_picture_still_opens): DTS and TrueHD tracks are listeddecodable: false,unsupported()names them with the ffmpeg line, the picture still opens (skips if ffmpeg cannot mux the fixture). LATM has no fixture (ffmpeg cannot put it in a transport stream).
Gates
cargo clippy -p engine -p edith_mcp -p edith --release --all-targets -- -D warningsis clean on host c.- Full test:
cargo test -p engine -p edith_mcp -p edith --release --no-fail-faston host c after the final commitf56a8796: 3411 passed, 2 failed, and the 2 are the known VA-API-onlyh264_mid_gop_seeks_match_a_sequential_decodeandhevc_mid_gop_seeks_match_a_sequential_decode.tests/mpegts.rs: 12 of 12. Clippy (-p engine -p engine-hw -p edith_mcp -p edith --release --all-targets -- -D warnings) clean on the final tree. - An earlier full run (run 2) had 103 failures, almost all in
saveload,sequences,speed*,stabilise,subtitles,transitionsand friends, while another lane's suite ran on host c at the same time. Every one panicked at the fixture copy (tests/saveload.rs:29,std::fs::copy(asset(name), ...).expect("copy the fixture")): the lane'sedith/assetswas missing or half-synced at that moment. It is not shared$HOMEstate: the tests' scratch directories come fromstd::env::temp_dir()(engine::scratch::fresh, per-laneTMPDIR, pid-named), and the only fixed paths in the engine aresrc/project/sequence.rs:1164(/tmp/edith-sequence-test*.mp4, a unit test that only names paths) and the cache dirs, which honourXDG_CACHE_HOME(proxy.rs,stabilise.rs). The assets come fromremote-run.sh's rsync of the main checkout'sassets/(EDITH_ASSETS), so a concurrent change or sync of that tree, or a lane-level race in the tree sync, explains it. Re-running the same binaries alone passed, and the third full run (same tree, host c free) was clean. No isolation fix is needed in project.rs/edith.rs; a possible hardening is forremote-run.shto sync assets into a per-lane directory atomically (rsync to a temp name, then rename). - No commit has trailers (checked
git log 3feda907..HEAD).
Known limits
-
MPEG-2
repeat_first_field(3:2 pulldown) is not applied: one coded picture is one timeline frame, so a pulled-down 29.97 file plays at its coded rate with no repeated fields. -
A Matroska file holding MPEG-2 (
V_MPEG2) is still refused: the MPEG-2 seat is reachable from transport streams only. -
No MPEG program stream demuxer exists in edith:
.mpg,.mpeg,.voband.m2v(raw elementary stream) are not opened (lib.rslists the extensions as non-audio and the open refuses them); this lane did not build one.ec-mpeg2's streaming API (send_bytes) would serve a raw.m2vreader, and.mpg/.vobneed a PS demuxer inec-mpegtsor a sibling crate. -
MPEG-1 video inside a TS (type 0x01) takes the same path as MPEG-2.
-
BD LPCM with more than 2 channels is not reordered to film order.
-
A keyframe that is a non-IDR recovery point with leading B-pictures gets a seek display index from its PTS only.
-
sync_pointsis empty for TS, so reverse play plans loosely. -
Only the first sound track feeds the bitrate card.
-
Time spent on a PGS import is one full demux of the file.