edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # procodecs / avi |
| 2 | |
| 3 | Worktree `/home/user/.cache/wt/edith-procodecs-avi`, branch `lane-procodecs-avi`, server lane `edith-procodecs-avi`. Commits: the feature commit, then a clippy-allow commit. No trailers, not pushed. |
| 4 | |
| 5 | ## Design |
| 6 | Option chosen: reuse the TS/PS readers (least code). New `crates/engine/src/demux/avi.rs` holds `AviSrc`, an adapter over `ec_riff::AviDemuxer` that is a third `Src` variant in `demux/ts.rs` (`Src::Avi`). It rescales every stream's `dwScale/dwRate` time base to the 90 kHz ticks the readers use (and seeks back), synthesises the `ec_mpegts::TrackInfo` list, and derives the codec config the AVI does not state (H.264: `avcC` of the first SPS/PPS from the strf tail or first keyframes; MPEG-2: sequence header + extension). `TsDemuxer` (picture) and `TsAudio` (sound) then serve AVI unchanged except: |
| 7 | - `Flavor {Ts, Ps, Avi}` replaces the `ps: bool` (refusal wording `in.avi`, `Flavor::of(path)`). |
| 8 | - `TsDemuxer::open` maps `Mjpeg/ProRes/Dnxhd` to `Codec::{Mjpeg,ProRes,Dnxhd}`; `pending` is now a queue; `field_order()` exposed (`Demuxer::field_order()` public, for `MjpegDecoder::set_field_order`). |
| 9 | - `is_mpeg_system` includes `is_avi`, so audio.rs (probe_streams, Track::open, seek, waveform, export audio source, sync), subtitle, export copy-guard, `header_streams`, container name (`avi`) all route AVI with no further edits. |
| 10 | - `TsDecoder`: little-endian PCM (u8, s16, s24, s32, f32) and raw AAC with its AudioSpecificConfig. |
| 11 | - Probe: `header_streams` names mjpeg/prores/dnxhd, PCM bit depth, and lists a refused picture by ffprobe name (`rawvideo`, `dvvideo`, `mpeg4`, `msmpeg4v3`, ...). |
| 12 | |
| 13 | ## B-frames (no PTS in AVI) |
| 14 | Decoders release pictures in display order themselves, so sequential decode is right. A keyframe's display index is slot + the run of B pictures right behind it (open GOP leading Bs), detected from the bitstream (MPEG-2 picture_coding_type, H.264 slice_type); a seek goes back a keyframe if that index passes the target. Verified with x264 (bframes=2, closed and open-gop) and mpeg2video `-bf 2`: every picture equals the stream the AVI was remuxed from; seeks equal sequential. |
| 15 | Limits: a zero-size video chunk (dropped frame) keeps its slot but yields no picture, so later frames drift; a non-B-run open-GOP shape (e.g. pyramids where the leading pictures are not B slices) is taken at its slot; 96 kHz+ PCM sample positions may be one sample off (90 kHz tick). |
| 16 | |
| 17 | ## Refusals |
| 18 | Raw video, DV, MPEG-4 Part 2 / DivX / XviD / MS-MPEG4, other FourCCs: named, with `convert it with ffmpeg -i in.avi -c:v libx264 -c:a aac out.mp4`, in `Demuxer::open`/`picture_refusal` and (when audio exists) in the probe stream list. A file with a refused picture and usable audio opens as audio (probe_streams decodable, AudioSession::open Some); its picture open fails with the refusal. A video-only refused file: open error names it; probe lists no streams (ec-riff errors out of the whole open). |
| 19 | Note: ffmpeg remuxing an mp4 into AVI writes AVCC-framed H.264 (not Annex B) unless `-bsf:v h264_mp4toannexb`, and a bogus 600 fps rate unless `-r 25`; such files are not supported (tests remux with both). |
| 20 | |
| 21 | ## Tests (`crates/engine/tests/avi.rs`, 7, all pass) |
| 22 | b-frame pictures (h264, h264 open-gop, mpeg2): probe, 50 frames, pictures exact vs source, seeks and ranges equal sequential; mjpeg+pcm: probe, packets byte-equal to ffmpeg's, seek, field order, pictures PSNR>30 dB vs ffmpeg (SKIPPED with a message until the MJPEG decode seat exists; runs automatically after the merge); sound for pcm/mp3/mp2/aac/ac3 vs ffmpeg + seek == sequential; flash/beep sync after open and seek (h264+mp3, mpeg2+mp2, mjpeg+pcm sound only); export duration/frame count/sync; raw/dv/mpeg4 refusals with and without audio; sniff by bytes and `.divx`. |
| 23 | ProRes/DNxHD in AVI map to their Codec variants (no test; needs the other lane's seats). |
| 24 | |
| 25 | ## Required edits elsewhere |
| 26 | - export.rs: none. crates/app/subs.rs: none (AVI has no subtitles). playback.rs: none. |
| 27 | - Cargo.toml: none (ec-riff dep already present). |
| 28 | - Merge notes: demux.rs touched at `mod avi`, `is_avi` re-export, `container_name`, `Demuxer::field_order`; the picture-through-the-seat check for MJPEG in my test passes after the merge. |
| 29 | |
| 30 | ## DV / MPEG-4 Part 2 |
| 31 | ec-riff now maps both (DvVideo, Mpeg4Part2); per coordinator decision the engine keeps refusing them by name (`dvvideo`, `mpeg4`) with the ffmpeg line (commit 1c106bd6), tested. |
| 32 | |
| 33 | ## Gates (host c, commit 1c106bd6) |
| 34 | - clippy `-p engine -p edith_mcp -p edith --release --all-targets -D warnings`: clean. |
| 35 | - full suite: passed 3587, failed 3: the 2 known VA-API-only (h264_/hevc_mid_gop_seeks_match_a_sequential_decode) and `ui::icons::tests::every_icon_is_baked_and_every_file_has_a_variant` (edith app, asset-listing test; not touched by this lane, likely a base/asset-sync issue on the server). tests/avi.rs 7/7 pass. |