MP4 File Format Part 1

This is a MP4 file format notes that reference from ISO IEC 14496-12 2005 edition about Information technology — Coding of audio-visual objects — Part 12: ISO base media file format

This is not designed for details explanation of each atom. For detail information, please read the ISO IEC 14496-12 document.

General Format


In general, MP4 file format has the following structure

ftyp
  • File type box that denote the mp4 media type
mdat
  • Media data box which contains the actual AV frames.
  • Within a mdat, there are chunks and samples
moov
  • Movie box which is the container for all metadata
  • Each moov has have a mvhd (Movie header box)
  • It can contains N trak box. Each trak box contains media specific meta data information Usually, it will have 2 tracks (video and audio)
  • More importantly, it contains sample information such as stsd, stts, stsz stsc, stco, etc...

Mdat Atom

MPEG4 sample


H.264 sample


Mdat is the media data atom which contain video and audio frames. As you can see from the screenshot, it is separated into 2 tracks (video and audio). Each track has multiple chunks and each chunks has multiple samples. Usually, you can treat each sample as a AV frame.

The number of sample in the chunk is defined in stsc atom (sample to chunk box) and the chunk offset is defined in stco atom (chunk offset box).

For MPEG4 (see MPEG4 sample), the red box denote the start code for MPEG4 Elementary stream. ISO 14496-14 states that MPEG4 media-data is stored as access units, a range of contiguous bytes for each access unit (a single access unit is the definition of a ‘sample’ for an MPEG-4 media stream). See 3.1.1 of the document

For H.264 (see H.264 sample), the red box denote the frame size (4 bytes). The blue box is the start of the frame, in this case, it is H.264 Non-IDR frame. ISO 14496-15 states that H.264 sample needs a length field preceding each NAL. See 5.2.3 of that document.

STSC - Sample To Chunk Box


The stsc tells you the number of samples in a chunk. To read this, you need to read first chunk and samples per chunks together. In the screenshot, first chunk has 1, 3, 5, 6..... and samples per chunk has 4, 5, 4, 5.... This means the followings:

chunk 1 - 2 has 4 samples
chunk 3 - 4 has 5 samples
chunk 5 has 4 samples

and so on...

STCO - Chunk Offset Box


This box tells you the location of the chunk. This offset is referred from the start of file. In the screenshot, it has values of 1516, 4880,...

As this is a video track, that means the first video chunk is located at 1516 bytes of the file.

STSZ - Sample Size Box


This box tell you the size of each sample in the chunk. It also tells you the number of sample counts in this track.

If you look at the entry size, it state 2229, 529,....

That means the first sample has 2229 bytes and second samples has 529 bytes

STSD - Sample Description Box


This box tells you the codec type, initialization and any information requires for the coding in the track.

As you can see in the screenshot, it contains AVC configuration box. Those are the information required (SPS, PPS, etc..) for decoding this video track.

Reference: ISO IEC 14496-12, ISO IEC 14496-14, ISO IEC 14496-15

Comments

  1. Hi
    where can i get the application which prints the format of .mp4 file

    If its written by you is it possible to share it?

    Regards
    Sharath

    ReplyDelete
  2. You can get it at http://code.google.com/p/mp4parser/

    ReplyDelete
  3. Hey Really Superb Spec. Thanks for sharing this. I hope you do not mind if I follow your blog, adding your rss to my client. :D
    Peter, see also mp4 convert to mov mac

    ReplyDelete
  4. MP4 is the most common use video format for nowadays.
    and I always need to convert VOB to MP4 Mac for share.
    Nice Post!!

    ReplyDelete
  5. i am capturing a h264 elementary over RTP and storing in MP4 format. i now all the data can be stored in a single chunk and in a single sample. Is this correct?
    on what basis i should choose number of chunks and samples per chunk?

    ReplyDelete
  6. Yes. You can do a single chunk per single sample way.

    As for number of chunk and sample per chunk, for my own preference and simplicity, I will do in a GOV view. Because RTP come in I-P-P-P-P-P and need to be decode to NAL before storing into MP4 format. I will be more convenience to decode all frame as GOV, then treat each frame as sample and the whole GOV as chunk.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. i deleted a few comments, which i will try and contact you by email about.

    ReplyDelete
  10. These songs are great, I usually put my favorite songs into cell phone ringtones, You should also choose your own ringtone to your cell phone. You can visit my site to listen and download free ringtones for mobile phones, everything All quality and free, I hope you like them: https://ringtonesmobile.net/

    I really need your comments to change the new look of the ringtone world.

    These are my favorite tunes that you can refer to:

    - bollywood ringtone download
    - Pop ringtone download
    - Iphone ringtone download
    - Marimba ringtone download
    - Dance ringtone download

    ReplyDelete
  11. This blog is really helpful for my database. It enhanced the area of my thoughts and pushed me beyond the boundaries. Work ethic of every point is different and represent a new way to improve myself.
    online zwangerschapscursus

    ReplyDelete
  12. A blog must be connected to the person in need. It is really important to understand the actual feel of such necessity and the essence of objective behind it. Author must give proper time to understand every topic before writing it.
    access control turnstiles

    ReplyDelete
  13. This is an awesome article a debt of gratitude is in order for sharing this enlightening data. I will visit your site consistently for some most recent post. I will visit your website consistently for Some most recent post.
    Archos Mobile Price in Bangladesh

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. I am thankful to this blog for assisting me. I added some specified clues which are really important for me to use them in my writing skill. Really helpful stuff made by this blog.online zwangerschapscursus

    ReplyDelete
  16. This post is extremely radiant. I extremely like this post. It is outstanding amongst other posts that I ve read in quite a while. Much obliged for this better than average post. I truly value it!

    ReplyDelete
  17. our enthusiasm leads you beyond the limits. When you feel yourself enthusiastic that’s the time you can cross any limit. You seek to get perfection by using the ability of work. Read such motivational article and definitely it will help you to know new facts.ondernemer worden opleiding

    ReplyDelete
  18. I always replied to this blog post and its been a long time since I came into knowledge of this blog. One of my friend’s suggestion worked for me and I am still regular to read every post of this blog.opleiding eigen bedrijf

    ReplyDelete
  19. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. https://homebusinessmag.com/businesses/how-to-guides-businesses/how-to-convert-youtube-mp4-videos/

    ReplyDelete
  20. I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. https://www.motorverso.com/ontiva-com-youtube-to-mp4-converter-for-car-viewing/

    ReplyDelete
  21. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. btclod.com

    ReplyDelete
  22. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks mostville.com

    ReplyDelete
  23. what an Informative post you share! Thanks and keep up your work! apk.care

    ReplyDelete
  24. Thank you for dropping this post. Not really helpful for me but maybe useful for other. APK Download

    ReplyDelete
  25. Mp4 is popular format nowaday. I love your post, thank for information Apkdownload

    ReplyDelete
  26. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. Method Ik Zentrum

    ReplyDelete

Post a Comment

Popular Posts