-
Notifications
You must be signed in to change notification settings - Fork 25
stsd: add support for jpeg #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,6 +287,7 @@ any! { | |
| Pasp, | ||
| Taic, | ||
| Fiel, | ||
| Jpeg, | ||
| Hev1, Hvc1, | ||
| Hvcc, Lhvc, | ||
| Mp4a, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| use crate::*; | ||
|
|
||
| /// Photo - JPEG ('jpeg'), QuickTime's Motion JPEG visual sample entry. | ||
| /// | ||
| /// Unlike most video codecs, JPEG has no separate decoder configuration box: | ||
| /// the quantization/Huffman tables and everything else needed to decode are | ||
| /// self-contained within each JPEG-coded sample (baseline JPEG per | ||
| /// [ITU-T T.81](https://www.itu.int/rec/T-REC-T.81-199209-I/en) | ISO/IEC 10918-1, the | ||
| /// core JPEG bitstream standard), so this is just a [`Visual`] sample entry | ||
| /// plus the usual optional extension boxes. | ||
| /// | ||
| /// `'jpeg'` itself is a QuickTime-registered codec, not part of the ISO | ||
| /// base media file format -- see its | ||
| /// [MP4RA registration](https://mp4ra.org/registered-types/codecs) (spec: | ||
| /// "QT") and Apple's QuickTime documentation on the | ||
| /// [Photo Compressor](https://developer.apple.com/Mac/library/documentation/QuickTime/RM/CompressDecompress/ImageComprMgr/E-Chapter/5CompressorsSupplied.html), | ||
| /// which each sample's JPEG bitstream conforms to. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Default)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct Jpeg { | ||
| pub visual: Visual, | ||
| pub btrt: Option<Btrt>, | ||
| pub colr: Option<Colr>, | ||
| pub pasp: Option<Pasp>, | ||
| pub fiel: Option<Fiel>, | ||
| } | ||
|
|
||
| impl Atom for Jpeg { | ||
| const KIND: FourCC = FourCC::new(b"jpeg"); | ||
|
|
||
| fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> { | ||
| let visual = Visual::decode(buf)?; | ||
|
|
||
| let mut btrt = None; | ||
| let mut colr = None; | ||
| let mut pasp = None; | ||
| let mut fiel = None; | ||
| while let Some(atom) = Any::decode_maybe(buf)? { | ||
| match atom { | ||
| Any::Btrt(atom) => btrt = atom.into(), | ||
| Any::Colr(atom) => colr = atom.into(), | ||
| Any::Pasp(atom) => pasp = atom.into(), | ||
| Any::Fiel(atom) => fiel = atom.into(), | ||
| unknown => Self::decode_unknown(&unknown)?, | ||
| } | ||
| } | ||
| skip_trailing_padding(buf); | ||
|
|
||
| Ok(Self { | ||
| visual, | ||
| btrt, | ||
| colr, | ||
| pasp, | ||
| fiel, | ||
| }) | ||
| } | ||
|
|
||
| fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> { | ||
| self.visual.encode(buf)?; | ||
| self.btrt.encode(buf)?; | ||
| self.colr.encode(buf)?; | ||
| self.pasp.encode(buf)?; | ||
| self.fiel.encode(buf)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_jpeg_roundtrip() { | ||
| let expected = Jpeg { | ||
| visual: Visual { | ||
| data_reference_index: 1, | ||
| width: 1920, | ||
| height: 1080, | ||
| compressor: "Photo - JPEG".into(), | ||
| ..Default::default() | ||
| }, | ||
| btrt: Some(Btrt { | ||
| buffer_size_db: 0, | ||
| max_bitrate: 5_000_000, | ||
| avg_bitrate: 2_000_000, | ||
| }), | ||
| colr: None, | ||
| pasp: Some(Pasp { | ||
| h_spacing: 1, | ||
| v_spacing: 1, | ||
| }), | ||
| fiel: None, | ||
| }; | ||
|
|
||
| let mut buf = Vec::new(); | ||
| expected.encode(&mut buf).unwrap(); | ||
|
|
||
| let decoded = Jpeg::decode(&mut buf.as_slice()).expect("failed to decode jpeg"); | ||
| assert_eq!(decoded, expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_jpeg_minimal() { | ||
| // No optional boxes at all -- just the bare VisualSampleEntry. | ||
| let expected = Jpeg { | ||
| visual: Visual { | ||
| data_reference_index: 1, | ||
| width: 640, | ||
| height: 480, | ||
| ..Default::default() | ||
| }, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let mut buf = Vec::new(); | ||
| expected.encode(&mut buf).unwrap(); | ||
|
|
||
| let decoded = Jpeg::decode(&mut buf.as_slice()).expect("failed to decode jpeg"); | ||
| assert_eq!(decoded, expected); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
The new
Jpegsample entry omits the optionalclapchild that the shared VisualSampleEntry contract declares. A JPEG file containing a clean-aperture box is therefore rejected or loses that metadata when decoded and cannot round-trip it; addclap: Option<Clap>and handleAny::Clapin both decoding and encoding.🤖 Prompt for AI Agents