h2non / filetype

Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature
https://pkg.go.dev/github.com/h2non/filetype?tab=doc
MIT License
2.05k stars 178 forks source link

add subtype check for mov matcher #123

Closed leslie-wang closed 1 year ago

leslie-wang commented 1 year ago

one mp4 video has below header, and match both mov and mp4 type based on current video matcher because of a map structure. Return result becomes unpredictable. This commit is to explicitly check subtype for mov file to exclude mov file for this type of videos

00000000: 0000 0020 6674 7970 6973 6f6d 0000 0200  ... ftypisom....
00000010: 6973 6f6d 6973 6f32 6176 6331 6d70 3431  isomiso2avc1mp41

From Apple https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-CJBCBIFF which describes subtype qt is needed for mov file

The file type atom has an atom type value of 'ftyp' and contains the
following fields:
Size
A 32-bit unsigned integer that specifies the number of bytes in this
atom.
Type
A 32-bit unsigned integer that identifies the atom type, typically
represented as a four-character code; this field must be set to 'ftyp'.
Major_Brand
A 32-bit unsigned integer that should be set to 'qt ' (note the two
trailing ASCII space characters) for QuickTime movie files.

Signed-off-by: Leslie wqyuwss@gmail.com