Ch. 16 · Containers in Depth

한국어日本語
7 min

fMP4: MP4 Split into Fragments (moof + mdat)

Fragmented MP4 puts an index in every fragment instead of one for the whole file. This is why live and adaptive streaming use this structure.

A regular MP4 keeps the index for the whole file in a single moov, so it couldn't be completed until the end. Fragmented MP4 (fMP4) solves this by splitting the index up per fragment. The HLS and DASH segments from Chapter 10 and the CMAF chunks from Chapter 15 are exactly this structure (CMAF, CMAF chunks).

ftyp moov(no samples) moof mdat moof mdat … Init segment Fragment 1, fragment 2 … (can be appended endlessly)
fMP4 layout: an initialization part once, followed by repeating (moof + mdat) fragments
  • Initialization part (ftyp + moov): holds only the codec configuration and track information; the sample table is empty. A decoder can't be built until you know the codec, so the player fetches this before any fragments.
  • moof (movie fragment): a small index listing the number, sizes, and times of the samples in that fragment. It contains boxes such as mfhd and traf (tfhd, tfdt, trun).
  • mdat: the compressed data of that fragment.
  • sidx (optional): an index that gathers the times and file positions of the fragments in one place. It is used when you store many fragments in one file and want to seek.
Regular MP4fMP4
Index (sample location table)All in a single moovSplit across the moof of each fragment
State before it's finishedOften unplayable without moovReadable up to the fragments already written
Live and streamingNot suitableSuitable: output goes out fragment by fragment
Typical usesFile storage, distribution, editingHLS (fMP4), DASH, CMAF segments
fMP4 output example (a new fragment at each keyframe)
ffmpeg -i input.mp4 -c copy \
  -movflags frag_keyframe+empty_moov+default_base_moof \
  output_frag.mp4

frag_keyframe starts a new fragment at each keyframe, and empty_moov tells FFmpeg to write a moov with no samples at the start. Fragment length is directly tied to the GOP structure. A fragment has to be independently decodable, so it usually starts at a keyframe (GOP structure). That is why choosing the segment length is really choosing the GOP length.

What if you just double-click an fMP4 file?

An fMP4 can also have the .mp4 extension, but not every player handles it well. Without seek information (sidx), fast-forwarding can be inaccurate or the duration may not display correctly. For a regular file for archiving or distribution, it is safer to convert it back to a regular MP4 (you can reassemble it with -c copy).

fMP4Fragmented MP4

An MP4 in which moof+mdat fragments repeat after the initialization part. The basis of HLS (fMP4), DASH, and CMAF.

moofMovie fragment box

The metadata box listing the number, sizes, and times of the samples in one fMP4 fragment.

sidxSegment index box

An optional index that gathers the times and positions of fragments. Used for seeking.

Init segmentInitialization segment

The front part of an fMP4 (ftyp+moov) holding the codec configuration. It is needed before any fragment can be decoded.

Check yourself

What is the most direct reason fMP4 suits live streaming?