Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#2340: uncompressed QuickTime video (raw 24-bit RGB, 2vuy, v210) decodes

irgendwasmitfelixdd2d3111d688
diff --git a/crates/codecs/src/lib.rs b/crates/codecs/src/lib.rs
index 9a8bebdbf..f3ae47b72 100644
--- a/crates/codecs/src/lib.rs
+++ b/crates/codecs/src/lib.rs
@@ -77,7 +77,7 @@ impl From<CodecError> for filmcraft_media::MediaError {
}
/// Our own (pure-Rust) decoders, in the order they are tried.
-const BUILTIN_FACTORIES: [VideoDecoderFactory; 10] = [
+const BUILTIN_FACTORIES: [VideoDecoderFactory; 11] = [
video::h264_factory,
video::hevc_factory,
video::vp8_factory,
@@ -88,6 +88,7 @@ const BUILTIN_FACTORIES: [VideoDecoderFactory; 10] = [
video::dnx_factory,
video::mjpeg_factory,
video::mpeg2_factory,
+ video::raw_factory,
];
fn factories() -> &'static RwLock<Vec<VideoDecoderFactory>> {
diff --git a/crates/codecs/src/mp4.rs b/crates/codecs/src/mp4.rs
index 6e33c027e..b4936b484 100644
--- a/crates/codecs/src/mp4.rs
+++ b/crates/codecs/src/mp4.rs
@@ -580,6 +580,9 @@ fn codec_label(c: &CodecConfig) -> String {
CodecConfig::Hevc(_) => "HEVC".into(),
CodecConfig::Vp9(c) => format!("VP9 (Profile {})", c.profile),
CodecConfig::Unknown { fourcc, .. } if fourcc.0 == *b"vp08" => "VP8".into(),
+ CodecConfig::Unknown { fourcc, .. } if fourcc.0 == *b"raw " => "Uncompressed RGB".into(),
+ CodecConfig::Unknown { fourcc, .. } if fourcc.0 == *b"2vuy" => "Uncompressed YUV 4:2:2".into(),
+ CodecConfig::Unknown { fourcc, .. } if fourcc.0 == *b"v210" => "Uncompressed YUV 4:2:2 10-bit".into(),
CodecConfig::Av1(c) => format!("AV1 ({} Profile)", ["Main", "High", "Professional"].get(c.seq_profile as usize).unwrap_or(&"Main")),
CodecConfig::Apv(a) => match filmcraft_apv::Profile::from_idc(a.profile_idc) {
Some(p) => p.name().into(),
diff --git a/crates/codecs/src/tests.rs b/crates/codecs/src/tests.rs
index 52af0574c..9c8ea8c19 100644
--- a/crates/codecs/src/tests.rs
+++ b/crates/codecs/src/tests.rs
@@ -236,6 +236,33 @@ fn mp4_flac_audio() {
assert!(peak > 0.05 && peak < 1.0, "audio peak {peak}");
}
+/// #2340: uncompressed QuickTime video (`raw ` 24-bit RGB, `2vuy`, `v210`) decodes, with fl32
+/// audio, instead of being reported unreadable.
+#[test]
+fn quicktime_uncompressed_video() {
+ let src = ["-f", "lavfi", "-i", "color=c=0x3060C0:s=64x36:r=24:d=0.5", "-f", "lavfi", "-i", "sine=frequency=1000:sample_rate=48000:d=0.5"];
+ for (name, vcodec) in [
+ ("raw_rgb24.mov", ["-c:v", "rawvideo", "-pix_fmt", "rgb24"]),
+ ("raw_2vuy.mov", ["-c:v", "rawvideo", "-pix_fmt", "uyvy422"]),
+ ("raw_v210.mov", ["-c:v", "v210", "-pix_fmt", "yuv422p10le"]),
+ ] {
+ let args: Vec<&str> = src.iter().copied().chain(vcodec).chain(["-c:a", "pcm_f32be", "-shortest"]).collect();
+ let Some(b) = fixture(name, &args) else { return };
+ let src = crate::open_bytes(name, b).unwrap_or_else(|e| panic!("{name}: {e}"));
+ let f = src.video_frame(FrameRequest { time: Tick(TICKS_PER_SECOND / 4), scale: 1.0 }).unwrap_or_else(|e| panic!("{name}: {e}"));
+ assert_eq!((f.width, f.height), (64, 36), "{name}");
+ assert!(src.info().video.as_ref().is_some_and(|v| v.codec.starts_with("Uncompressed")), "{name}: {:?}", src.info().video);
+ let rgba = f.to_rgba8();
+ let px = &rgba[(18 * 64 + 32) * 4..][..3];
+ for (got, want) in px.iter().zip([0x30u8, 0x60, 0xc0]) {
+ assert!((*got as i32 - want as i32).abs() <= 6, "{name}: {px:?}");
+ }
+ let a = src.audio(12_000, 4800, 48_000).expect("fl32 audio");
+ let peak = a.channels[0].iter().fold(0f32, |m, s| m.max(s.abs()));
+ assert!(peak > 0.05 && peak < 1.0, "{name}: audio peak {peak}");
+ }
+}
+
#[test]
fn matroska_prores_pcm() {
check_mkv("blue_prores_pcm.mkv", &["-c:v", "prores_ks", "-profile:v", "2"], &["-c:a", "pcm_s16le"]);
diff --git a/crates/codecs/src/video.rs b/crates/codecs/src/video.rs
index 28b3f4c66..7a4a2ef55 100644
--- a/crates/codecs/src/video.rs
+++ b/crates/codecs/src/video.rs
@@ -1094,6 +1094,13 @@ fn esds_object_type(raw: &[u8]) -> Option<u8> {
raw.get(p).copied()
}
+/// Uncompressed QuickTime / MP4 video (`raw ` 24-bit RGB, `2vuy`, `v210`, #2340).
+pub fn raw_factory(e: &SampleEntry) -> Option<Result<Box<dyn VideoDecoder>>> {
+ let v = e.video.as_ref()?;
+ let format = RawFormat::from_mov(e.format.0, v.depth)?;
+ Some(RawVideoDecoder::new(format, u32::from(v.width), u32::from(v.height), false).map(|d| Box::new(d) as Box<dyn VideoDecoder>))
+}
+
pub fn mpeg2_factory(e: &SampleEntry) -> Option<Result<Box<dyn VideoDecoder>>> {
match &e.codec {
CodecConfig::Unknown { fourcc, raw } if is_mpeg2_entry(&fourcc.0, raw) => {
@@ -1168,6 +1175,11 @@ pub enum RawFormat {
Nv12,
/// Luma only (`Y800`, `GREY`, `Y8 `).
Gray8,
+ /// 24-bit R, G, B; rows unpadded (QuickTime `raw ` at depth 24).
+ Rgb24,
+ /// 10-bit 4:2:2 Y'CbCr, six pixels in four little-endian words, rows padded to 128 bytes
+ /// (QuickTime `v210`); shown at 8 bits.
+ V210,
}
impl RawFormat {
@@ -1193,13 +1205,24 @@ impl RawFormat {
})
}
+ /// The layout of a QuickTime / MP4 video sample entry (`raw ` RGB at depth 24, `2vuy`, `v210`).
+ pub fn from_mov(fourcc: [u8; 4], depth: u16) -> Option<RawFormat> {
+ match (&fourcc, depth) {
+ (b"raw ", 24) => Some(RawFormat::Rgb24),
+ (b"2vuy", _) => Some(RawFormat::Uyvy),
+ (b"v210", _) => Some(RawFormat::V210),
+ _ => None,
+ }
+ }
+
pub fn label(self) -> &'static str {
match self {
- RawFormat::Bgr24 => "Uncompressed RGB 24-bit",
+ RawFormat::Bgr24 | RawFormat::Rgb24 => "Uncompressed RGB 24-bit",
RawFormat::Bgrx32 => "Uncompressed RGB 32-bit",
RawFormat::Yuy2 | RawFormat::Uyvy => "Uncompressed YUV 4:2:2",
RawFormat::I420 | RawFormat::Yv12 | RawFormat::Nv12 => "Uncompressed YUV 4:2:0",
RawFormat::Gray8 => "Uncompressed greyscale",
+ RawFormat::V210 => "Uncompressed YUV 4:2:2 10-bit",
}
}
}
@@ -1254,6 +1277,42 @@ impl RawVideoDecoder {
}
VideoFrame::rgba8(self.width, self.height, rgba)
}
+ RawFormat::Rgb24 => {
+ let stride = w * 3;
+ if s.len() < stride * h {
+ return Err(short());
+ }
+ let mut rgba = Vec::with_capacity(w * h * 4);
+ for px in s.get(..stride * h).unwrap_or_default().as_chunks::<3>().0 {
+ rgba.extend_from_slice(&[px[0], px[1], px[2], 255]);
+ }
+ VideoFrame::rgba8(self.width, self.height, rgba)
+ }
+ RawFormat::V210 => {
+ // 6 pixels per 16 bytes; each row padded to a multiple of 128 bytes (48 pixels)
+ let stride = w.div_ceil(48) * 128;
+ if s.len() < stride * h {
+ return Err(short());
+ }
+ let (mut y, mut u, mut v) = (Vec::with_capacity(w * h), Vec::with_capacity(cw * h), Vec::with_capacity(cw * h));
+ for row in s.chunks_exact(stride).take(h) {
+ // the row's 10-bit samples in order: Cb Y Cr Y Cb Y Cr Y …, kept at 8 bits
+ let mut comps = row.as_chunks::<4>().0.iter().flat_map(|b| {
+ let word = u32::from_le_bytes(*b);
+ [word & 0x3ff, (word >> 10) & 0x3ff, (word >> 20) & 0x3ff].map(|c| (c >> 2) as u8)
+ });
+ for x in 0..cw {
+ let (Some(cb), Some(y0), Some(cr), Some(y1)) = (comps.next(), comps.next(), comps.next(), comps.next()) else { break };
+ u.push(cb);
+ v.push(cr);
+ y.push(y0);
+ if 2 * x + 1 < w {
+ y.push(y1);
+ }
+ }
+ }
+ self.yuv([y, u, v], filmcraft_frame::Chroma::C422)
+ }
RawFormat::Yuy2 | RawFormat::Uyvy => {
let stride = cw * 4;
if s.len() < stride * h {