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
, container: Option, mpeg_descriptor: bool) -> Codec {
if let Some(c) = coding.filter(Ul::is_smpte) {
@@ -81,6 +105,9 @@ pub fn identify_picture(coding: Option, container: Option, mpeg_descript
// 04 01 02 02 .. : compressed picture coding
if b[8..12] == [0x04, 0x01, 0x02, 0x02] {
match (b[12], b[13]) {
+ // TIFF/EP Profile 2 picture coding (RP 224: 03 02 01 01 uncompressed CFA … 04
+ // compressed LinearRaw), the coding of DNG pictures
+ (0x03, 0x02) if b[14] == 0x01 => return Codec::CinemaDng,
// 01: MPEG compression (ISO/IEC 13818-2 profiles, 14496-2, 14496-10)
(0x01, 0x01..=0x1F) => return Codec::Mpeg2,
(0x01, 0x20..=0x2F) => return Codec::Mpeg4Visual,
@@ -99,6 +126,9 @@ pub fn identify_picture(coding: Option, container: Option, mpeg_descript
return Codec::Uncompressed;
}
}
+ if container.is_some_and(|c| is_cinemadng_container(&c)) {
+ return Codec::CinemaDng;
+ }
if let Some(c) = container.filter(Ul::is_smpte)
&& c.item_starts_with(&[0x0D, 0x01, 0x03, 0x01, 0x02])
{
@@ -117,8 +147,30 @@ pub fn identify_picture(coding: Option, container: Option, mpeg_descript
if mpeg_descriptor { Codec::Mpeg2 } else { Codec::Unknown }
}
+/// DNG evidence in the leading bytes of a TIFF: a TIFF 6.0 §2 header whose first IFD, when it lies
+/// within `b`, holds the DNGVersion tag (DNG 1.x §2, tag 50706). A plain TIFF has no such tag.
+fn is_dng(b: &[u8]) -> bool {
+ let le = match b.get(..4) {
+ Some(h) if h == b"II*\0" => true,
+ Some(h) if h == b"MM\0*" => false,
+ _ => return false,
+ };
+ let u16_at = |o: usize| b.get(o..o + 2).map(|v| if le { u16::from_le_bytes([v[0], v[1]]) } else { u16::from_be_bytes([v[0], v[1]]) });
+ let Some(ifd) = b.get(4..8).map(|v| if le { u32::from_le_bytes([v[0], v[1], v[2], v[3]]) } else { u32::from_be_bytes([v[0], v[1], v[2], v[3]]) })
+ else {
+ return false;
+ };
+ let Some(count) = usize::try_from(ifd).ok().and_then(|o| u16_at(o).map(|n| (o, n))) else {
+ return false;
+ };
+ (0..usize::from(count.1)).any(|i| u16_at(count.0 + 2 + i * 12) == Some(50706))
+}
+
/// Identify a picture codec from the first bytes of an essence element.
pub fn sniff_picture(b: &[u8]) -> Option {
+ if is_dng(b) {
+ return Some(Codec::CinemaDng);
+ }
if b.len() >= 8 && &b[4..8] == b"icpf" {
return Some(Codec::ProRes { profile: None });
}
@@ -367,6 +419,20 @@ mod tests {
assert_eq!(identify_picture(None, None, false), Codec::Unknown);
}
+ #[test]
+ fn identifies_cinemadng() {
+ // CinemaDNG specification §7.2.1: CFA and LinearRaw containers (any registry version byte)
+ let adobe = |kind: u8| Ul([0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0F, 0x0A, 0x0D, 0x0B, 0x02, 0x7F, kind, 0x00]);
+ assert_eq!(identify_picture(None, Some(adobe(1)), false), Codec::CinemaDng);
+ assert_eq!(identify_picture(None, Some(adobe(2)), false), Codec::CinemaDng);
+ assert_eq!(identify_picture(None, Some(adobe(3)), false), Codec::Unknown);
+ // RP 224: MXF-GC frame-wrapped TIFF/EP container, TIFF/EP picture coding
+ assert_eq!(identify_picture(None, Some(ul(&[0x0D, 1, 3, 1, 2, 0x14, 1])), false), Codec::CinemaDng);
+ assert_eq!(identify_picture(Some(ul(&[4, 1, 2, 2, 3, 2, 1, 3])), None, false), Codec::CinemaDng);
+ assert!(Codec::CinemaDng.intra_only());
+ assert_eq!(Codec::CinemaDng.name(), "CinemaDNG");
+ }
+
#[test]
fn sniffs_essence() {
assert_eq!(sniff_picture(&[0, 0, 0, 1, 0x09, 0x10]), Some(Codec::Avc { intra: false }));
@@ -374,6 +440,15 @@ mod tests {
assert_eq!(sniff_picture(&[0, 0, 2, 0x80, 1]), Some(Codec::Vc3));
assert_eq!(sniff_picture(&[0, 0, 0, 9, b'i', b'c', b'p', b'f']), Some(Codec::ProRes { profile: None }));
assert_eq!(sniff_picture(&[1, 2, 3]), None);
+ // a TIFF header alone is not DNG; an IFD0 with the DNGVersion tag (50706 = 0xC612) is
+ let tiff_le = |tag: u16| [b"II*\0\x08\0\0\0\x01\0".as_slice(), &tag.to_le_bytes(), &[1, 0, 4, 0, 0, 0, 1, 4, 0, 0], &[0; 8]].concat();
+ let tiff_be = |tag: u16| [b"MM\0*\0\0\0\x08\0\x01".as_slice(), &tag.to_be_bytes(), &[0, 1, 0, 0, 0, 4, 1, 4, 0, 0], &[0; 8]].concat();
+ assert_eq!(sniff_picture(&tiff_le(0xC612)), Some(Codec::CinemaDng));
+ assert_eq!(sniff_picture(&tiff_be(0xC612)), Some(Codec::CinemaDng));
+ assert_eq!(sniff_picture(&tiff_le(0x0100)), None);
+ assert_eq!(sniff_picture(&tiff_be(0x0100)), None);
+ assert_eq!(sniff_picture(b"II*\0\x08\0\0\0"), None);
+ assert_eq!(sniff_picture(b"II*\0"), None);
}
#[test]
diff --git a/crates/media/src/mxf/file.rs b/crates/media/src/mxf/file.rs
index 15d847c7d..9064bcb83 100644
--- a/crates/media/src/mxf/file.rs
+++ b/crates/media/src/mxf/file.rs
@@ -910,7 +910,7 @@ fn build_track(
}
// A wrong or missing label: trust the essence bytes.
if let Some(first) = elements.first() {
- let head = read_upto(src, first.value_offset, 64)?;
+ let head = read_upto(src, first.value_offset, 4096)?;
if let Some(sniffed) = sniff_picture(&head) {
let agree = std::mem::discriminant(&sniffed) == std::mem::discriminant(&codec);
if !agree && !matches!(codec, Codec::Avc { intra: true }) {
@@ -918,6 +918,12 @@ fn build_track(
}
}
}
+ // CinemaDNG §7.1.1.2: a "TIFF" picture element type names DNG pictures
+ if codec == Codec::Unknown
+ && elements.first().is_some_and(|e| e.key.0[12] == 0x15 && e.key.0[14] == super::essence::CINEMADNG_ELEMENT_TYPE)
+ {
+ codec = Codec::CinemaDng;
+ }
t.codec = codec;
t.picture = Some(pi);
build_pictures(src, &mut t, elements, index, warnings)?;
diff --git a/crates/media/src/mxf/mod.rs b/crates/media/src/mxf/mod.rs
index ca0e8f918..56de637c7 100644
--- a/crates/media/src/mxf/mod.rs
+++ b/crates/media/src/mxf/mod.rs
@@ -2,7 +2,8 @@
//! ST 377-1 (file format: KLV, partitions, primer pack, header metadata, index tables, random
//! index pack), ST 378 (OP1a), ST 390 (OP-Atom), ST 379-1/2 (generic container), ST 381-1 (MPEG
//! video mapping), ST 381-3 (AVC mapping), ST 382 (AES3 / Broadcast Wave audio mapping), ST 331
-//! (AES3 element data, D-10 sound), ST 2019-4 (VC-3 mapping) and RDD 44 (ProRes mapping).
+//! (AES3 element data, D-10 sound), ST 2019-4 (VC-3 mapping), RDD 44 (ProRes mapping) and the CinemaDNG
+//! specification's MXF mapping (frame-wrapped DNG pictures).
//!
//! [`open`] walks the file's KLV packets (keys and lengths only; essence payloads are never read
//! while opening), parses the partition packs, the primer pack and header metadata of the most
@@ -32,7 +33,7 @@ mod meta;
pub mod write;
pub use crate::source::{ByteSource, ReadSeekSource};
-pub use essence::{Codec, PictureInfo, SoundFormat, SoundInfo, aes3_element_samples, decode_pcm};
+pub use essence::{CINEMADNG_CONTAINER_PREFIX, CINEMADNG_ELEMENT_TYPE, Codec, PictureInfo, SoundFormat, SoundInfo, aes3_element_samples, decode_pcm};
pub use file::{Chunk, EssenceTrack, MxfFile, OperationalPattern, Partition, PartitionKind, Sample, Timecode, TrackKind, Wrapping, open};
pub use index::{IndexEntry, IndexSegment};
pub use klv::{Rational, Ul};
diff --git a/crates/media/src/mxf/write.rs b/crates/media/src/mxf/write.rs
index 9fb6bfea2..42abf846f 100644
--- a/crates/media/src/mxf/write.rs
+++ b/crates/media/src/mxf/write.rs
@@ -107,6 +107,10 @@ pub enum PictureCoding {
ProRes { profile: u8 },
/// H.264 / AVC Annex B byte stream; `profile_idc` from the SPS (66, 77, 100, …).
Avc { profile_idc: u8, intra: bool },
+ /// CinemaDNG: one DNG dataset per picture (CinemaDNG specification §7), frame-wrapped only,
+ /// with an RGBA descriptor of the decoded 16-bit RGB image. `linear_raw`: the pictures are
+ /// LinearRaw (PhotometricInterpretation 34892) rather than CFA (32803).
+ CinemaDng { linear_raw: bool },
}
impl PictureCoding {
@@ -116,9 +120,10 @@ impl PictureCoding {
_ => true,
}
}
- /// Picture essence coding label.
- fn coding_label(&self) -> [u8; 16] {
- match *self {
+ /// Picture essence coding label (None: CinemaDNG, which has no registered one, §7.2.2.2).
+ fn coding_label(&self) -> Option<[u8; 16]> {
+ Some(match *self {
+ PictureCoding::CinemaDng { .. } => return None,
PictureCoding::Vc3 { cid } => {
let code = if (1235..=1234 + 0x7F).contains(&cid) { (cid - 1234) as u8 } else { 0 };
[0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x0A, 0x04, 0x01, 0x02, 0x02, 0x71, code, 0x00, 0x00]
@@ -145,7 +150,7 @@ impl PictureCoding {
};
[0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x0A, 0x04, 0x01, 0x02, 0x02, 0x01, b13, b14, 0x01]
}
- }
+ })
}
/// (essence container label, element type) for frame or clip wrapping.
fn container(&self, clip: bool) -> ([u8; 16], u8) {
@@ -154,6 +159,12 @@ impl PictureCoding {
PictureCoding::Vc3 { .. } => (essence_container(0x0A, 0x11, w, 0x00), if clip { 0x0D } else { 0x0C }),
PictureCoding::ProRes { .. } => (essence_container(0x0D, 0x1C, w, 0x00), if clip { 0x18 } else { 0x17 }),
PictureCoding::Avc { .. } => (essence_container(0x0A, 0x10, 0x60, w), if clip { 0x16 } else { 0x15 }),
+ // CinemaDNG §7.2.1 (provisional label) and §7.1.1.2 (element type 42h); always frame
+ // wrapped (`MxfWriter::new` refuses clip wrapping)
+ PictureCoding::CinemaDng { linear_raw } => (
+ [0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0F, 0x0A, 0x0D, 0x0B, 0x02, 0x7F, if *linear_raw { 0x02 } else { 0x01 }, 0x00],
+ 0x42,
+ ),
}
}
}
@@ -202,6 +213,8 @@ impl PictureDesc {
if matches!(cid, 1235 | 1241 | 1250 | 1256 | 1270 | 1271) { 10 } else { 8 },
if matches!(cid, 1256 | 1270) { (1, 1) } else { (2, 1) },
),
+ // §7.2.2.3: the decoded image is described as 16 bits per component
+ PictureCoding::CinemaDng { .. } => (16, (1, 1)),
};
PictureDesc {
coding,
@@ -589,6 +602,19 @@ impl MxfWriter {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid PCM sound description"));
}
let clip = cfg.pattern == Pattern::OpAtom;
+ if clip && matches!(cfg.picture.as_ref().map(|p| p.coding), Some(PictureCoding::CinemaDng { .. })) {
+ // CinemaDNG §7.1.1: a TIFF dataset has no length field, so DNG pictures can't be clip wrapped
+ return Err(io::Error::new(
+ io::ErrorKind::InvalidInput,
+ "CinemaDNG pictures are frame wrapped only (this writer's OP-Atom is clip wrapped)",
+ ));
+ }
+ if let Some(p) = &cfg.picture {
+ // CinemaDNG §7.2.2.3 fixes the decoded image at 16 bits per component
+ if matches!(p.coding, PictureCoding::CinemaDng { .. }) && p.depth != 16 {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput, "CinemaDNG pictures are described at 16 bits per component"));
+ }
+ }
let mut tracks = Vec::new();
let mut id = cfg.first_track_id.max(2);
if let Some(p) = &cfg.picture {
@@ -985,7 +1011,8 @@ impl MxfWriter {
TrackKind::Picture => {
// Picture tracks exist only with a picture configuration.
let Some(p) = cfg.picture.as_ref() else { continue };
- let mut s = Set::new(0x28, uid);
+ let rgba = matches!(p.coding, PictureCoding::CinemaDng { .. });
+ let mut s = Set::new(if rgba { 0x29 } else { 0x28 }, uid);
if multiple {
s.u32(0x3006, t.id);
}
@@ -1020,8 +1047,21 @@ impl MxfWriter {
// field dominance: the temporally first field (1 top, 2 bottom)
s.u8(0x3212, if p.bottom_field_first { 2 } else { 1 });
}
- s.p(0x3201, &p.coding.coding_label())
- .p(0x3210, &tcl)
+ if let Some(label) = p.coding.coding_label() {
+ s.p(0x3201, &label);
+ }
+ if rgba {
+ // RGBA descriptor (ST 377-1 G.2.40): pixel layout R, G, B of 16 bits each and
+ // the component reference levels. CinemaDNG §7.2.2.3 fixes the decoded
+ // image at 16 bits; `MxfWriter::new` rejects any other `PictureDesc::depth`.
+ let mut layout = [0u8; 16];
+ layout[..6].copy_from_slice(&[b'R', 16, b'G', 16, b'B', 16]);
+ let max = u32::from(u16::MAX);
+ s.p(0x3401, &layout).u32(0x3406, max).u32(0x3407, 0);
+ s.write(&mut out);
+ continue;
+ }
+ s.p(0x3210, &tcl)
.p(0x321A, &ce)
.p(0x3219, &cp)
.u32(0x3301, depth)
diff --git a/crates/media/src/mxf/write/labels.rs b/crates/media/src/mxf/write/labels.rs
index eb8fbc040..12f62c7fd 100644
--- a/crates/media/src/mxf/write/labels.rs
+++ b/crates/media/src/mxf/write/labels.rs
@@ -120,6 +120,10 @@ pub const PRIMER: &[(u16, [u8; 16])] = &[
(0x3304, ul(&[0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x05, 0x03, 0x03])),
(0x3305, ul(&[0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x05, 0x03, 0x04])),
(0x3306, ul(&[0x01, 0x01, 0x01, 0x02, 0x04, 0x01, 0x05, 0x03, 0x05])),
+ // RGBA picture essence descriptor (ST 377-1; RP 210): PixelLayout, ComponentMaxRef, ComponentMinRef
+ (0x3401, ul(&[0x01, 0x01, 0x01, 0x02, 0x04, 0x01, 0x05, 0x03, 0x06])),
+ (0x3406, ul(&[0x01, 0x01, 0x01, 0x05, 0x04, 0x01, 0x05, 0x03, 0x0B])),
+ (0x3407, ul(&[0x01, 0x01, 0x01, 0x05, 0x04, 0x01, 0x05, 0x03, 0x0C])),
(0x3D03, ul(&[0x01, 0x01, 0x01, 0x05, 0x04, 0x02, 0x03, 0x01, 0x01, 0x01])),
(0x3D02, ul(&[0x01, 0x01, 0x01, 0x04, 0x04, 0x02, 0x03, 0x01, 0x04])),
(0x3D07, ul(&[0x01, 0x01, 0x01, 0x05, 0x04, 0x02, 0x01, 0x01, 0x04])),
diff --git a/crates/media/src/mxf/write/tests.rs b/crates/media/src/mxf/write/tests.rs
index 91574fec7..eac50a0e9 100644
--- a/crates/media/src/mxf/write/tests.rs
+++ b/crates/media/src/mxf/write/tests.rs
@@ -401,6 +401,56 @@ fn long_pcm_reads_backed_by_the_file_are_not_capped() {
assert!(m.read_pcm(&f, 0, 0, frames + (1 << 24)).is_err());
}
+/// A TIFF-headed stand-in for a DNG dataset (the demuxer only carries the bytes).
+fn dng_like(i: usize) -> Vec {
+ let mut v = b"II*\0\x08\0\0\0".to_vec();
+ v.extend(std::iter::repeat_n(i as u8 ^ 0x33, 300 + 11 * i));
+ v
+}
+
+#[test]
+fn cinemadng_op1a_reads_back() {
+ for linear_raw in [false, true] {
+ let mut cfg = op1a_config(Rational::new(24, 1), PictureCoding::CinemaDng { linear_raw });
+ cfg.sound.truncate(1);
+ let mut w = MxfWriter::new(Cursor::new(Vec::new()), cfg).unwrap();
+ for i in 0..6 {
+ w.push_picture(&dng_like(i), FrameInfo::intra()).unwrap();
+ w.push_sound(0, &pcm16(i * 2000, 2000)).unwrap();
+ }
+ let f = w.finish().unwrap().into_inner();
+ // CinemaDNG §7.1.1.2: picture element key 06.0E.2B.34.01.02.01.01.0D.01.03.01.15.01.42.01
+ let key = [0x06, 0x0E, 0x2B, 0x34, 0x01, 0x02, 0x01, 0x01, 0x0D, 0x01, 0x03, 0x01, 0x15, 0x01, 0x42, 0x01];
+ assert_eq!(f.windows(16).filter(|k| *k == key).count(), 6);
+ // §7.2.1: the essence container label of the content kind
+ let ec = [0x06, 0x0E, 0x2B, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0F, 0x0A, 0x0D, 0x0B, 0x02, 0x7F, if linear_raw { 2 } else { 1 }, 0x00];
+ assert!(f.windows(16).any(|k| k == ec));
+ let m = open(&f).unwrap();
+ assert!(m.warnings.is_empty(), "{:?}", m.warnings);
+ let v = m.track_of_kind(TrackKind::Picture).unwrap();
+ let t = &m.tracks[v];
+ assert_eq!(t.codec, Codec::CinemaDng);
+ assert_eq!(t.wrapping, Wrapping::Frame);
+ assert_eq!(t.samples.len(), 6);
+ let p = t.picture.as_ref().unwrap();
+ assert!(p.rgba, "RGBA picture essence descriptor (§7.2.2)");
+ assert_eq!((p.frame_width(), p.frame_height()), (64, 36));
+ assert!(p.picture_coding.is_none());
+ for i in 0..6 {
+ assert!(t.samples[i].key);
+ assert_eq!(m.read_sample(&f, v, i).unwrap(), dng_like(i));
+ }
+ assert_eq!(m.timecode.unwrap().format(), "01:02:30:00");
+ }
+}
+
+#[test]
+fn cinemadng_is_never_clip_wrapped() {
+ let mut cfg = WriterConfig::new(Pattern::OpAtom, Rational::new(24, 1), PackageIds::from_seed("t", "T"));
+ cfg.picture = Some(PictureDesc::new(PictureCoding::CinemaDng { linear_raw: false }, 64, 36));
+ assert!(MxfWriter::new(Cursor::new(Vec::new()), cfg).is_err());
+}
+
/// One `push_sound` of a long clip must not cost more than the clip itself: draining the buffered
/// PCM from the front for every edit unit made this quadratic (about 16 s for 10 minutes).
#[test]