From 543db30b8e37eb1f842abac23b61d358689a174e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 15:11:16 +0300 Subject: [PATCH] S4: move video_codec table to codec_table.rs (pure move) --- crates/ec-mp4/src/codec_table.rs | 40 ++++++++++++++++++++++++++++++++ crates/ec-mp4/src/demux.rs | 38 +----------------------------- crates/ec-mp4/src/lib.rs | 1 + 3 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 crates/ec-mp4/src/codec_table.rs diff --git a/crates/ec-mp4/src/codec_table.rs b/crates/ec-mp4/src/codec_table.rs new file mode 100644 index 00000000..b98eb08c --- /dev/null +++ b/crates/ec-mp4/src/codec_table.rs @@ -0,0 +1,40 @@ +use ec_core::CodecId; + +use crate::boxes::FourCc; + +pub(crate) fn video_codec(kind: &FourCc, video_track: bool) -> Option<(CodecId, &'static FourCc)> { + Some(match kind { + b"avc1" | b"avc3" => (CodecId::H264, b"avcC"), + b"hvc1" | b"hev1" => (CodecId::H265, b"hvcC"), + b"vp08" => (CodecId::Vp8, b"vpcC"), + b"vp09" => (CodecId::Vp9, b"vpcC"), + b"av01" => (CodecId::Av1, b"av1C"), + // Motion JPEG: QuickTime `jpeg` (Photo JPEG) and `mjpa` (MJPEG-A) carry whole JFIF + // frames and no configuration box. `mjpb` (MJPEG-B) packets have a different layout + // (no SOI, marker-less blocks at header offsets); ec-mjpeg detects and rewraps them. + // Uncompressed video; `raw ` is also the 8-bit PCM audio entry, so it needs a `vide` track. + // The decoder (ec-riff `RawVideoDecoder`) reads the layout from the synthesized header. + b"raw " | b"yuvs" if !video_track => return None, + b"raw " | b"yuvs" | b"2vuy" | b"yuv2" | b"v210" | b"v410" | b"b16g" => { + (CodecId::RawVideo, b"\0\0\0\0") + } + b"jpeg" | b"mjpa" | b"mjpb" => (CodecId::Mjpeg, b"\0\0\0\0"), + // ProRes entries carry no configuration box: the frame header is self-describing. + b"apco" | b"apcs" | b"apcn" | b"apch" | b"ap4h" | b"ap4x" => (CodecId::ProRes, b"\0\0\0\0"), + // Avid DNxHD (`AVdn`) and DNxHR (`AVdh`); the optional `DNxD` box is + // the only child worth keeping as extradata. + b"AVdn" | b"AVdh" => (CodecId::Dnxhd, b"DNxD"), + // MPEG-4 Part 2 Visual: `mp4v` carries the VOL header in the `esds` + // DecoderSpecificInfo; the 3GPP/QuickTime H.263 entries (`s263`, `h263`) + // carry no configuration the baseline decoder needs (`d263` is ignored). + b"mp4v" => (CodecId::Mpeg4Part2, b"esds"), + b"s263" | b"h263" => (CodecId::Mpeg4Part2, b"\0\0\0\0"), + // DV: QuickTime sample entries for DV25/DVCPRO25 (`dvc `/`dvcp`/`dvpp`), DVCPRO50 + // (`dv5n`/`dv5p`) and DVCPRO HD (`dvhq`/`dvh3`/`dvh5`/`dvh6`/`dvhp`...). The frame is + // self-describing: no configuration box. + b"dvc " | b"dvcp" | b"dvpp" | b"dvcs" | b"dvis" | b"dv5n" | b"dv5p" | b"dv5q" | b"dvhq" + | b"dvh1" | b"dvh2" | b"dvh3" | b"dvh4" | b"dvh5" | b"dvh6" | b"dvhp" | b"dvhs" + | b"dvhn" | b"dvhr" => (CodecId::DvVideo, b"\0\0\0\0"), + _ => return None, + }) +} diff --git a/crates/ec-mp4/src/demux.rs b/crates/ec-mp4/src/demux.rs index e7118f93..e516373e 100644 --- a/crates/ec-mp4/src/demux.rs +++ b/crates/ec-mp4/src/demux.rs @@ -10,6 +10,7 @@ use ec_core::{ use crate::asc; use crate::boxes::{Boxes, FourCc, Src, be16, be32, be64, full}; +use crate::codec_table::video_codec; use crate::esds::{Esds, object_type}; /// The whole movie header is read into memory at once — it is the index, and a @@ -1601,43 +1602,6 @@ pub(crate) fn opus_head(dops: &[u8]) -> Buf { Buf::from_vec(out) } -fn video_codec(kind: &FourCc, video_track: bool) -> Option<(CodecId, &'static FourCc)> { - Some(match kind { - b"avc1" | b"avc3" => (CodecId::H264, b"avcC"), - b"hvc1" | b"hev1" => (CodecId::H265, b"hvcC"), - b"vp08" => (CodecId::Vp8, b"vpcC"), - b"vp09" => (CodecId::Vp9, b"vpcC"), - b"av01" => (CodecId::Av1, b"av1C"), - // Motion JPEG: QuickTime `jpeg` (Photo JPEG) and `mjpa` (MJPEG-A) carry whole JFIF - // frames and no configuration box. `mjpb` (MJPEG-B) packets have a different layout - // (no SOI, marker-less blocks at header offsets); ec-mjpeg detects and rewraps them. - // Uncompressed video; `raw ` is also the 8-bit PCM audio entry, so it needs a `vide` track. - // The decoder (ec-riff `RawVideoDecoder`) reads the layout from the synthesized header. - b"raw " | b"yuvs" if !video_track => return None, - b"raw " | b"yuvs" | b"2vuy" | b"yuv2" | b"v210" | b"v410" | b"b16g" => { - (CodecId::RawVideo, b"\0\0\0\0") - } - b"jpeg" | b"mjpa" | b"mjpb" => (CodecId::Mjpeg, b"\0\0\0\0"), - // ProRes entries carry no configuration box: the frame header is self-describing. - b"apco" | b"apcs" | b"apcn" | b"apch" | b"ap4h" | b"ap4x" => (CodecId::ProRes, b"\0\0\0\0"), - // Avid DNxHD (`AVdn`) and DNxHR (`AVdh`); the optional `DNxD` box is - // the only child worth keeping as extradata. - b"AVdn" | b"AVdh" => (CodecId::Dnxhd, b"DNxD"), - // MPEG-4 Part 2 Visual: `mp4v` carries the VOL header in the `esds` - // DecoderSpecificInfo; the 3GPP/QuickTime H.263 entries (`s263`, `h263`) - // carry no configuration the baseline decoder needs (`d263` is ignored). - b"mp4v" => (CodecId::Mpeg4Part2, b"esds"), - b"s263" | b"h263" => (CodecId::Mpeg4Part2, b"\0\0\0\0"), - // DV: QuickTime sample entries for DV25/DVCPRO25 (`dvc `/`dvcp`/`dvpp`), DVCPRO50 - // (`dv5n`/`dv5p`) and DVCPRO HD (`dvhq`/`dvh3`/`dvh5`/`dvh6`/`dvhp`...). The frame is - // self-describing: no configuration box. - b"dvc " | b"dvcp" | b"dvpp" | b"dvcs" | b"dvis" | b"dv5n" | b"dv5p" | b"dv5q" | b"dvhq" - | b"dvh1" | b"dvh2" | b"dvh3" | b"dvh4" | b"dvh5" | b"dvh6" | b"dvhp" | b"dvhs" - | b"dvhn" | b"dvhr" => (CodecId::DvVideo, b"\0\0\0\0"), - _ => return None, - }) -} - /// A `ColourInformationBox`: the H.273 triplet, when it is the `nclx`/`nclc` /// kind rather than an ICC profile — as the raw triplet *and* as the tags that /// triplet really states. diff --git a/crates/ec-mp4/src/lib.rs b/crates/ec-mp4/src/lib.rs index e1fadf23..692993bf 100644 --- a/crates/ec-mp4/src/lib.rs +++ b/crates/ec-mp4/src/lib.rs @@ -52,6 +52,7 @@ mod asc; mod boxes; +mod codec_table; mod demux; mod esds; mod mux;