FLAC audio can be stored in an MP4 file (ISO base media file format, ISO/IEC 14496-12) as an
audio track whose sample entry is fLaC. The mapping is Xiph’s “Encapsulation of
FLAC in ISO Base Media File Format”, version 0.0.4 (doc/isoflac.txt in the
xiph/flac repository, last changed 2022-06-10, commit
78d85dd4e4e8044d0f6989182cd1a22a461dce37), read in November 2026. It covers
ISO base media and its derivatives; FLAC in QuickTime files is outside its scope. The MP4
boxes around the sample entry are on the
MP4 codec boxes page, where dfLa is
also listed.
The track
- The specification defines no brand. A conforming file lists at least one brand that supports these rules among its compatible brands; the minimum is
isom. - The FLAC audio is the media data of an audio track: the handler type in the Handler Reference Box is
soun, and the Media Information Box holds a Sound Media Header Box. - The sample entry’s coding name is
fLaC. No encapsulation with anMP4AudioSampleEntryand an object type from the MPEG-4 Registration Authority is defined. - The
dfLabox inside the sample entry carries the decoder’s initial information. - A sample is exactly one FLAC frame, and every sample is a sync sample: no pre-roll or overlap is needed. The Sync Sample Box is absent as long as the track holds only FLAC samples, and
sample_is_non_sync_sampleis 0.
The informative box tree of the specification runs moov (mvhd, trak with
tkhd, an optional edts and elst, mdia with mdhd,
hdlr and minf holding smhd, dinf/dref/url or
urn and stbl with stsd (the fLaC entry with its dfLa),
stts, stsc, stsz or stz2, stco or co64),
then an optional mvex with trex; the order is strongly recommended.
The fLaC sample entry
FLACSampleEntry extends AudioSampleEntry('fLaC') and contains exactly one
FLAC Specific Box. The box fields and the FLAC structures inside it are both big-endian, though
the container treats FLAC’s own metadata and data blocks as unstructured octets.
| Field | Value |
|---|---|
channelcount | The channel count of the STREAMINFO block. Every frame header repeats the channel count and it must match this field and STREAMINFO. |
samplesize | The bits per sample of STREAMINFO; every frame header must match. |
samplerate | When possible, STREAMINFO’s sample rate shifted left 16 bits (the 16.16 fixed-point form). Above 65,535 Hz, the greatest expressible regular division of the rate: 48000.0 for 96 and 192 kHz; for an unusual rate with no such division, 65535.0 Hz. A reader must therefore take the true rate from the STREAMINFO in dfLa, not from here. The frame headers’ rate must match STREAMINFO and, as far as the limits above allow, this field. |
FLACSpecificBox | The dfLa box, below. |
The dfLa box
FLACSpecificBox extends FullBox('dfLa', version=0, 0): exactly one per sample
entry. It is a full box, so after the usual 8-byte box header (size and type) come a version byte
(0) and 24 bits of flags (0). A reader that does not support a version must not read the fields
after it. The rest of the box, to its end, is a run of FLAC metadata blocks:
| Field | Size | Meaning |
|---|---|---|
LastMetadataBlockFlag | 1 bit | 1 for the last block in the box, otherwise 0. As in the FLAC metadata block header. |
BlockType | 7 bits | A FLAC block type. The first block must be 0, STREAMINFO. |
Length | 24 bits | The number of bytes of block data that follow. |
BlockData | Length bytes | The block’s data, exactly as in a native FLAC file. |
The four header bytes and the data together are a complete native FLAC metadata block. At least one
block is required, the 34-byte STREAMINFO; if there are more, STREAMINFO
comes first. When a stream is remuxed from another container that holds FLAC’s native metadata
(Ogg and Matroska wrap it unmodified in the same way), the complete native metadata should be kept
in the dfLa box; the file may also repeat it in MP4’s own forms, provided the native
metadata is kept too. Unlike a native FLAC file, the box does not start with the fLaC
marker.
The smallest box is therefore 8 + 4 + 4 + 34 = 50 bytes: the box header, version and flags, one block
header (last flag 1, type 0, length 34) and the STREAMINFO data. The specification’s example shows
exactly that (size = 50, LastMetadataBlockFlag = 1, BlockType = 0,
Length = 34).
The sample
A sample is one complete FLAC frame: the frame header, one subframe per channel, any padding to a byte boundary, and the frame footer (CRC-16). The header’s channel count, rate and sample size must agree with STREAMINFO and the sample entry. A sample’s duration is the frame’s decoded block size divided by the media timescale; durations may vary within a stream, and FLAC uses no padding values. Sub-samples are not defined.
The specification’s example
A 0.7-second stereo 16-bit 48,000 Hz file: ftyp (major brand mp42, compatible
brands mp42 and isom), a moov with timescale 48000, one audio
track whose handler name is “Xiph Audio Handler”, stsd with one fLaC entry
(channelcount 2, samplesize 16, samplerate 48000.0) holding a 50-byte
dfLa at file offset 484, stts with 18 samples of 1,920 ticks, two chunks (13 and 5
samples) and 18 sample sizes from 848 to 977 bytes, then free and mdat.
The example’s printed sizes are not consistent with each other: the fLaC entry is
listed at position 448 with size 63, but its dfLa child is listed at position 484 with size
50, which needs the entry to be 86 bytes (8 + 28 + 50). The structure is clear from the field lists
above; do not take the example’s box sizes literally.
Sources
- Encapsulation of FLAC in ISO Base Media File Format – version 0.0.4,
doc/isoflac.txtinxiph/flac - MP4 codec boxes –
dfLabeside the other sample-entry boxes