From fdd039d8ee2418981024986de7c37be891e8e158 Mon Sep 17 00:00:00 2001 From: Vasili Bulkin Date: Sat, 19 Feb 2022 19:50:28 +0300 Subject: [PATCH] Improve detection of mov files (video/quicktime). Fixes detection of mov files produced by Nikon cameras (and probably some other atypical muxers). The first 4 bytes of a mov file specify the size of the 'ftyp' atom. While typically the "Compatible_Brands[]" array contains just the "qt " brand and the size is 0x14, muxers are free to add an arbitrary number of brand markers, changing the size. For example, Nikon cameras add the brand "niko". See https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-39017 --- src/matchers/video.rs | 10 ++-------- testdata/sample2.mov | Bin 0 -> 24 bytes tests/video.rs | 1 + 3 files changed, 3 insertions(+), 8 deletions(-) create mode 100644 testdata/sample2.mov diff --git a/src/matchers/video.rs b/src/matchers/video.rs index d4cb142..dbf0f67 100644 --- a/src/matchers/video.rs +++ b/src/matchers/video.rs @@ -48,14 +48,8 @@ pub fn is_webm(buf: &[u8]) -> bool { /// Returns whether a buffer is Quicktime MOV video data. pub fn is_mov(buf: &[u8]) -> bool { buf.len() > 15 - && ((buf[0] == 0x0 - && buf[1] == 0x0 - && buf[2] == 0x0 - && buf[3] == 0x14 - && buf[4] == 0x66 - && buf[5] == 0x74 - && buf[6] == 0x79 - && buf[7] == 0x70) + && (((buf[4] == b'f' && buf[5] == b't' && buf[6] == b'y' && buf[7] == b'p') + && (buf[8] == b'q' && buf[9] == b't' && buf[10] == b' ' && buf[11] == b' ')) || (buf[4] == 0x6d && buf[5] == 0x6f && buf[6] == 0x6f && buf[7] == 0x76) || (buf[4] == 0x6d && buf[5] == 0x64 && buf[6] == 0x61 && buf[7] == 0x74) || (buf[12] == 0x6d && buf[13] == 0x64 && buf[14] == 0x61 && buf[15] == 0x74)) diff --git a/testdata/sample2.mov b/testdata/sample2.mov new file mode 100644 index 0000000000000000000000000000000000000000..84af1b95f81be8ddb3112354fefb295ba50edda2 GIT binary patch literal 24 ccmZQzV30^FsVpcgQBY72<75EQd70Vy07B{p761SM literal 0 HcmV?d00001 diff --git a/tests/video.rs b/tests/video.rs index eea22bf..536cd5d 100644 --- a/tests/video.rs +++ b/tests/video.rs @@ -7,6 +7,7 @@ test_format!(Video, "video/x-matroska", "mkv", mkv, "sample.mkv"); test_format!(Video, "video/webm", "webm", webm, "sample.webm"); test_format!(Video, "video/quicktime", "mov", mov, "sample.mov"); +test_format!(Video, "video/quicktime", "mov", mov2, "sample2.mov"); test_format!(Video, "video/x-msvideo", "avi", avi, "sample.avi");