I have to design a module that detects mp4 files. If will get any random file as input and it has to tell whether it is a mp4 file or not. Where can I find the specification of headers for the mp4 file? Tried googling but could not find anything except the signature. Any other tips regarding C programming for the module?
问题:
回答1:
you can check the extension or the file signature (magic number)
http://www.garykessler.net/library/file_sigs.html
http://en.wikipedia.org/wiki/List_of_file_signatures
00 00 00 18 66 74 79 70 33 67 70 35 ....ftyp 3gp5 MPEG-4 video files
Or if you're on Unix/Linux you can parse the output of file(1) from your program.
Edit:
You don't need to scan the whole file to identify it, the signature will do, however, if you have to, note that MP4 is a container for other formats, which means you will probably need to know about MP4 and other formats it contains as well, there's some information here: http://en.wikipedia.org/wiki/MPEG-4_Part_14
I'd use something like libffmpeg to do that instead.
回答2:
ISO base media file format is freely available and MP4 file format is extension of "Base media format", for most of the cases its enough to understand "Base media format". try google will return a standard.
To detect if the file is MP4 you need to read first 8 bytes, which contain (first 4 bytes the size of ATOM and next 4 bytes "FTYP"). after that it contain the majorbrand and compatiblebrans - if either of them is ISOM it is definitely a MP4 file.so you need to parse only initial few bytes to confiem MP4 file.
You can also look at "mp4v2-1.9.1" code to understand MP4 format.
回答3:
It's a container format. The specification is here.
Even with the specification in hand, you would have a lot of work to do to support all a container could represent in your program; Set realistic requirements.