I found out recently that one of our instrumental tracks wasn’t working properly as it was using a Matroska audio-only file.
It happens because filetype.guess relies on magic numbers to detect the filetype, which can’t easily tell the difference between an audio-only matroska file (.mka) and video matroska file (.mkv). Instead it recognizes the matroska file format and returns video/x-matroska. I would assume that it also happens with .m4a and .ogg files which also use a container format that can hold video tracks.
The easy way out would be to use mimetypes.guess_file_type which does differentiate the two by relying on the file extension. But I suppose that it was meant as a quick check that the file is indeed an audio file.
To check the file content while supporting these container formats I would suggest relying on mediainfo or ffmpeg to check that the file contains only an audio track.
I found out recently that one of our instrumental tracks wasn’t working properly as it was using a Matroska audio-only file.
It happens because
filetype.guessrelies on magic numbers to detect the filetype, which can’t easily tell the difference between an audio-only matroska file (.mka) and video matroska file (.mkv). Instead it recognizes the matroska file format and returnsvideo/x-matroska. I would assume that it also happens with.m4aand.oggfiles which also use a container format that can hold video tracks.The easy way out would be to use
mimetypes.guess_file_typewhich does differentiate the two by relying on the file extension. But I suppose that it was meant as a quick check that the file is indeed an audio file.To check the file content while supporting these container formats I would suggest relying on mediainfo or ffmpeg to check that the file contains only an audio track.