S4: move video_codec table to codec_table.rs (pure move)
Browse files at this commit543db30b8e37eb1f842abac23b61d358689a174eParent: 4fd4ed43 changed files +42 -37
- crates/ec-mp4/src/codec_table.rs +40 -0
- crates/ec-mp4/src/demux.rs +1 -37
- crates/ec-mp4/src/lib.rs +1 -0
crates/ec-mp4/src/codec_table.rsadded+40 -0
| @@ -0,0 +1,40 @@ | |||
| 1 | +use ec_core::CodecId; | ||
| 2 | + | ||
| 3 | +use crate::boxes::FourCc; | ||
| 4 | + | ||
| 5 | +pub(crate) fn video_codec(kind: &FourCc, video_track: bool) -> Option<(CodecId, &'static FourCc)> { | ||
| 6 | + Some(match kind { | ||
| 7 | + b"avc1" | b"avc3" => (CodecId::H264, b"avcC"), | ||
| 8 | + b"hvc1" | b"hev1" => (CodecId::H265, b"hvcC"), | ||
| 9 | + b"vp08" => (CodecId::Vp8, b"vpcC"), | ||
| 10 | + b"vp09" => (CodecId::Vp9, b"vpcC"), | ||
| 11 | + b"av01" => (CodecId::Av1, b"av1C"), | ||
| 12 | + // Motion JPEG: QuickTime `jpeg` (Photo JPEG) and `mjpa` (MJPEG-A) carry whole JFIF | ||
| 13 | + // frames and no configuration box. `mjpb` (MJPEG-B) packets have a different layout | ||
| 14 | + // (no SOI, marker-less blocks at header offsets); ec-mjpeg detects and rewraps them. | ||
| 15 | + // Uncompressed video; `raw ` is also the 8-bit PCM audio entry, so it needs a `vide` track. | ||
| 16 | + // The decoder (ec-riff `RawVideoDecoder`) reads the layout from the synthesized header. | ||
| 17 | + b"raw " | b"yuvs" if !video_track => return None, | ||
| 18 | + b"raw " | b"yuvs" | b"2vuy" | b"yuv2" | b"v210" | b"v410" | b"b16g" => { | ||
| 19 | + (CodecId::RawVideo, b"\0\0\0\0") | ||
| 20 | + } | ||
| 21 | + b"jpeg" | b"mjpa" | b"mjpb" => (CodecId::Mjpeg, b"\0\0\0\0"), | ||
| 22 | + // ProRes entries carry no configuration box: the frame header is self-describing. | ||
| 23 | + b"apco" | b"apcs" | b"apcn" | b"apch" | b"ap4h" | b"ap4x" => (CodecId::ProRes, b"\0\0\0\0"), | ||
| 24 | + // Avid DNxHD (`AVdn`) and DNxHR (`AVdh`); the optional `DNxD` box is | ||
| 25 | + // the only child worth keeping as extradata. | ||
| 26 | + b"AVdn" | b"AVdh" => (CodecId::Dnxhd, b"DNxD"), | ||
| 27 | + // MPEG-4 Part 2 Visual: `mp4v` carries the VOL header in the `esds` | ||
| 28 | + // DecoderSpecificInfo; the 3GPP/QuickTime H.263 entries (`s263`, `h263`) | ||
| 29 | + // carry no configuration the baseline decoder needs (`d263` is ignored). | ||
| 30 | + b"mp4v" => (CodecId::Mpeg4Part2, b"esds"), | ||
| 31 | + b"s263" | b"h263" => (CodecId::Mpeg4Part2, b"\0\0\0\0"), | ||
| 32 | + // DV: QuickTime sample entries for DV25/DVCPRO25 (`dvc `/`dvcp`/`dvpp`), DVCPRO50 | ||
| 33 | + // (`dv5n`/`dv5p`) and DVCPRO HD (`dvhq`/`dvh3`/`dvh5`/`dvh6`/`dvhp`...). The frame is | ||
| 34 | + // self-describing: no configuration box. | ||
| 35 | + b"dvc " | b"dvcp" | b"dvpp" | b"dvcs" | b"dvis" | b"dv5n" | b"dv5p" | b"dv5q" | b"dvhq" | ||
| 36 | + | b"dvh1" | b"dvh2" | b"dvh3" | b"dvh4" | b"dvh5" | b"dvh6" | b"dvhp" | b"dvhs" | ||
| 37 | + | b"dvhn" | b"dvhr" => (CodecId::DvVideo, b"\0\0\0\0"), | ||
| 38 | + _ => return None, | ||
| 39 | + }) | ||
| 40 | +} | ||
crates/ec-mp4/src/demux.rsmodified+1 -37
| @@ -10,6 +10,7 @@ use ec_core::{ | |||
| 10 | 10 | ||
| 11 | use crate::asc; | 11 | use crate::asc; |
| 12 | use crate::boxes::{Boxes, FourCc, Src, be16, be32, be64, full}; | 12 | use crate::boxes::{Boxes, FourCc, Src, be16, be32, be64, full}; |
| 13 | +use crate::codec_table::video_codec; | ||
| 13 | use crate::esds::{Esds, object_type}; | 14 | use crate::esds::{Esds, object_type}; |
| 14 | 15 | ||
| 15 | /// The whole movie header is read into memory at once — it is the index, and a | 16 | /// 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 { | |||
| 1601 | Buf::from_vec(out) | 1602 | Buf::from_vec(out) |
| 1602 | } | 1603 | } |
| 1603 | 1604 | ||
| 1604 | -fn video_codec(kind: &FourCc, video_track: bool) -> Option<(CodecId, &'static FourCc)> { | ||
| 1605 | - Some(match kind { | ||
| 1606 | - b"avc1" | b"avc3" => (CodecId::H264, b"avcC"), | ||
| 1607 | - b"hvc1" | b"hev1" => (CodecId::H265, b"hvcC"), | ||
| 1608 | - b"vp08" => (CodecId::Vp8, b"vpcC"), | ||
| 1609 | - b"vp09" => (CodecId::Vp9, b"vpcC"), | ||
| 1610 | - b"av01" => (CodecId::Av1, b"av1C"), | ||
| 1611 | - // Motion JPEG: QuickTime `jpeg` (Photo JPEG) and `mjpa` (MJPEG-A) carry whole JFIF | ||
| 1612 | - // frames and no configuration box. `mjpb` (MJPEG-B) packets have a different layout | ||
| 1613 | - // (no SOI, marker-less blocks at header offsets); ec-mjpeg detects and rewraps them. | ||
| 1614 | - // Uncompressed video; `raw ` is also the 8-bit PCM audio entry, so it needs a `vide` track. | ||
| 1615 | - // The decoder (ec-riff `RawVideoDecoder`) reads the layout from the synthesized header. | ||
| 1616 | - b"raw " | b"yuvs" if !video_track => return None, | ||
| 1617 | - b"raw " | b"yuvs" | b"2vuy" | b"yuv2" | b"v210" | b"v410" | b"b16g" => { | ||
| 1618 | - (CodecId::RawVideo, b"\0\0\0\0") | ||
| 1619 | - } | ||
| 1620 | - b"jpeg" | b"mjpa" | b"mjpb" => (CodecId::Mjpeg, b"\0\0\0\0"), | ||
| 1621 | - // ProRes entries carry no configuration box: the frame header is self-describing. | ||
| 1622 | - b"apco" | b"apcs" | b"apcn" | b"apch" | b"ap4h" | b"ap4x" => (CodecId::ProRes, b"\0\0\0\0"), | ||
| 1623 | - // Avid DNxHD (`AVdn`) and DNxHR (`AVdh`); the optional `DNxD` box is | ||
| 1624 | - // the only child worth keeping as extradata. | ||
| 1625 | - b"AVdn" | b"AVdh" => (CodecId::Dnxhd, b"DNxD"), | ||
| 1626 | - // MPEG-4 Part 2 Visual: `mp4v` carries the VOL header in the `esds` | ||
| 1627 | - // DecoderSpecificInfo; the 3GPP/QuickTime H.263 entries (`s263`, `h263`) | ||
| 1628 | - // carry no configuration the baseline decoder needs (`d263` is ignored). | ||
| 1629 | - b"mp4v" => (CodecId::Mpeg4Part2, b"esds"), | ||
| 1630 | - b"s263" | b"h263" => (CodecId::Mpeg4Part2, b"\0\0\0\0"), | ||
| 1631 | - // DV: QuickTime sample entries for DV25/DVCPRO25 (`dvc `/`dvcp`/`dvpp`), DVCPRO50 | ||
| 1632 | - // (`dv5n`/`dv5p`) and DVCPRO HD (`dvhq`/`dvh3`/`dvh5`/`dvh6`/`dvhp`...). The frame is | ||
| 1633 | - // self-describing: no configuration box. | ||
| 1634 | - b"dvc " | b"dvcp" | b"dvpp" | b"dvcs" | b"dvis" | b"dv5n" | b"dv5p" | b"dv5q" | b"dvhq" | ||
| 1635 | - | b"dvh1" | b"dvh2" | b"dvh3" | b"dvh4" | b"dvh5" | b"dvh6" | b"dvhp" | b"dvhs" | ||
| 1636 | - | b"dvhn" | b"dvhr" => (CodecId::DvVideo, b"\0\0\0\0"), | ||
| 1637 | - _ => return None, | ||
| 1638 | - }) | ||
| 1639 | -} | ||
| 1640 | - | ||
| 1641 | /// A `ColourInformationBox`: the H.273 triplet, when it is the `nclx`/`nclc` | 1605 | /// A `ColourInformationBox`: the H.273 triplet, when it is the `nclx`/`nclc` |
| 1642 | /// kind rather than an ICC profile — as the raw triplet *and* as the tags that | 1606 | /// kind rather than an ICC profile — as the raw triplet *and* as the tags that |
| 1643 | /// triplet really states. | 1607 | /// triplet really states. |
crates/ec-mp4/src/lib.rsmodified+1 -0
| @@ -52,6 +52,7 @@ | |||
| 52 | 52 | ||
| 53 | mod asc; | 53 | mod asc; |
| 54 | mod boxes; | 54 | mod boxes; |
| 55 | +mod codec_table; | ||
| 55 | mod demux; | 56 | mod demux; |
| 56 | mod esds; | 57 | mod esds; |
| 57 | mod mux; | 58 | mod mux; |