From 81bf3feb39a3304a9d9bb30025ad208ffd158602 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 12 Nov 2026 22:09:46 +0100 Subject: [PATCH 01/86] mxf: CinemaDNG in MXF (frame-wrapped DNG pictures), read and write The demuxer identifies CinemaDNG from the CinemaDNG container labels, the registered MXF-GC TIFF/EP container and picture coding labels, a 42h picture element type, or a TIFF header with the DNGVersion tag at the start of the essence. The writer produces OP1a files with frame-wrapped DNG pictures, the provisional container label, element type 42h and an RGBA descriptor (no coding label); OP-Atom is refused because it is clip-wrapped here. Same change as the crates/mxf part of storytold/Filmcraft#1078, ported onto craft-media. Co-Authored-By: Claude Sonnet 5.5 --- crates/media/README.md | 11 +++- crates/media/src/mxf/essence.rs | 81 ++++++++++++++++++++++++++-- crates/media/src/mxf/file.rs | 8 ++- crates/media/src/mxf/mod.rs | 5 +- crates/media/src/mxf/write.rs | 54 ++++++++++++++++--- crates/media/src/mxf/write/labels.rs | 4 ++ crates/media/src/mxf/write/tests.rs | 50 +++++++++++++++++ 7 files changed, 198 insertions(+), 15 deletions(-) diff --git a/crates/media/README.md b/crates/media/README.md index 387ab8cdd..48c930d1b 100644 --- a/crates/media/README.md +++ b/crates/media/README.md @@ -614,6 +614,7 @@ Implemented from the SMPTE documents (editions used): | SMPTE ST 386 | 2004 | D-10 (IMX) mapping: container label, sound element type | | SMPTE ST 2019-4 | 2009 | VC-3 (DNxHD / DNxHR) mapping | | SMPTE RDD 44 | 2017 | Apple ProRes mapping | +| Adobe CinemaDNG Image Data Format Specification | 1.0.0.0 (September 2009), §7 | CinemaDNG in MXF: frame-wrapped DNG picture elements (element type 42h), the essence container labels for CFA / LinearRaw content, RGBA descriptor; the labels are the specification's **provisional** values from Adobe's experimental range (byte 9 = 0Fh), not SMPTE-registered | | SMPTE RP 224 / RP 210 | registers | labels: data definitions, picture coding, essence containers, operational patterns; property labels of the primer pack (writer) | | SMPTE ST 330 | 2011 | basic UMIDs of the written packages | @@ -655,7 +656,10 @@ let pcm = mxf.read_pcm(&file, a, 48_000, 1920)?; // planar f32, sample-exact orders by the bitstream (the AVC picture order counts). - **Codecs.** From the picture essence coding label, then the essence container label, then the essence bytes: AVC / AVC-Intra, VC-3, ProRes (profile from the label), MPEG-2, - MPEG-4 visual, JPEG 2000, DV, uncompressed. + MPEG-4 visual, JPEG 2000, DV, uncompressed, CinemaDNG (the CinemaDNG container labels, the + registered MXF-GC TIFF/EP container and TIFF/EP picture coding labels, a 42h picture element + type, or a TIFF header with the DNGVersion tag at the start of the essence; the DNG pictures + themselves are developed by `craft-raw`). - **Sound.** PCM chunks (frame- or clip-wrapped) with sample counts; `read_pcm` decodes little-endian 8/16/24/32-bit PCM (wave / AES3 descriptors) and ST 331 AES3 elements (D-10). - **Timecode.** The material package timecode component (start frame count, rounded base, @@ -728,7 +732,10 @@ w.finish()?; element types 0x0C / 0x0D), ProRes (RDD 44: coding label profile byte, container `02 1C`), AVC byte stream (ST 381-3: container `02 10 60`, coding label from `profile_idc`; Annex B access units with in-band SPS / PPS — the AVC sub-descriptor is not written), Broadcast Wave PCM - (ST 382: container `02 06 01/02`, element types 0x01 / 0x02). + (ST 382: container `02 06 01/02`, element types 0x01 / 0x02), CinemaDNG (frame-wrapped DNG + datasets, element type 0x42, the provisional container label `0F 0A 0D 0B 02 7F 01/02 00`, an + RGBA descriptor with pixel layout and reference levels of the decoded 16-bit RGB picture and no + coding label; OP-Atom is refused because it is clip-wrapped here and DNG datasets cannot be). - `write_opatom_pcm(&OpAtomPcm, &[i32])` builds a complete in-memory OP-Atom PCM file (AAF media consolidation); `encode_pcm` interleaves planar f32 as little-endian PCM. diff --git a/crates/media/src/mxf/essence.rs b/crates/media/src/mxf/essence.rs index 27f893dc5..2c0d1ef7e 100644 --- a/crates/media/src/mxf/essence.rs +++ b/crates/media/src/mxf/essence.rs @@ -27,6 +27,9 @@ pub enum Codec { Dv, /// Uncompressed pictures (ST 384). Uncompressed, + /// CinemaDNG: one DNG (TIFF) dataset per frame-wrapped picture element (CinemaDNG Image Data + /// Format Specification §7), or TIFF/EP pictures under the registered MXF-GC TIFF/EP labels. + CinemaDng, /// Linear PCM, little-endian (Broadcast Wave and AES3 descriptors, ST 382). Pcm, /// 8-channel AES3 element data (ST 331, D-10 sound). @@ -46,13 +49,14 @@ impl Codec { Codec::Jpeg2000 => "JPEG 2000", Codec::Dv => "DV", Codec::Uncompressed => "Uncompressed", + Codec::CinemaDng => "CinemaDNG", Codec::Pcm => "PCM", Codec::Aes3Element => "AES3 PCM", Codec::Unknown => "unknown", } } /// The crate-wide identifier: VC-3 is [`CodecId::Dnxhd`], PCM and AES3 element data are - /// [`CodecId::Pcm`]; JPEG 2000, DV and uncompressed pictures have no identifier. + /// [`CodecId::Pcm`]; JPEG 2000, DV, uncompressed and CinemaDNG pictures have no identifier. /// /// [`CodecId::Dnxhd`]: crate::CodecId::Dnxhd /// [`CodecId::Pcm`]: crate::CodecId::Pcm @@ -65,15 +69,35 @@ impl Codec { Codec::Mpeg2 => Id::Mpeg2Video, Codec::Mpeg4Visual => Id::Mpeg4Video, Codec::Pcm | Codec::Aes3Element => Id::Pcm, - Codec::Jpeg2000 | Codec::Dv | Codec::Uncompressed | Codec::Unknown => Id::Unknown, + Codec::Jpeg2000 | Codec::Dv | Codec::Uncompressed | Codec::CinemaDng | Codec::Unknown => Id::Unknown, } } /// Every picture is coded independently. pub fn intra_only(&self) -> bool { - matches!(self, Codec::Avc { intra: true } | Codec::Vc3 | Codec::ProRes { .. } | Codec::Jpeg2000 | Codec::Dv | Codec::Uncompressed) + matches!( + self, + Codec::Avc { intra: true } | Codec::Vc3 | Codec::ProRes { .. } | Codec::Jpeg2000 | Codec::Dv | Codec::Uncompressed | Codec::CinemaDng + ) } } +/// The CinemaDNG essence container labels (CinemaDNG Image Data Format Specification 1.0.0.0, +/// §7.2.1): provisional, unregistered labels from Adobe's experimental range (byte 9 = 0F h), +/// `…0F 0A 0D 0B 02 7F cc 00` with content kind `cc` 01 (CFA) or 02 (LinearRaw). +pub const CINEMADNG_CONTAINER_PREFIX: [u8; 6] = [0x0F, 0x0A, 0x0D, 0x0B, 0x02, 0x7F]; + +/// Element type (byte 15 of the picture element key) of a frame-wrapped CinemaDNG picture: the +/// "TIFF" type of ST 331 (CinemaDNG specification §7.1.1.2). +pub const CINEMADNG_ELEMENT_TYPE: u8 = 0x42; + +/// Whether `ul` is a CinemaDNG essence container label (CFA or LinearRaw content), or the +/// registered MXF-GC TIFF/EP container (`…0D 01 03 01 02 14 ww 00`, RP 224). +pub fn is_cinemadng_container(ul: &Ul) -> bool { + ul.is_smpte() + && (ul.item_starts_with(&CINEMADNG_CONTAINER_PREFIX) && matches!(ul.0[14], 0x01 | 0x02) + || ul.item_starts_with(&[0x0D, 0x01, 0x03, 0x01, 0x02, 0x14])) +} + /// Identify a picture codec from the picture essence coding label and the essence container label. pub fn identify_picture(coding: Option