Skip to content

MP4Box

currentMigrated from docs/utilities/mp4box.mdx at 37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0

GPAC Ultramedia OSS for Video Streaming & Next-Gen Multimedia Transcoding, Packaging & Delivery

Latest release
v26.07.0
Last commit
License
LGPL-2.1
Stars
3,312

MP4Box is the command-line MP4 tool from GPAC, the open-source multimedia framework developed at Télécom Paris. It is to MP4 roughly what mkvmerge is to Matroska: it muxes elementary streams into MP4, edits tracks and metadata, concatenates and splits files, fragments them, and packages them for DASH and HLS streaming. It never re-encodes.

FFmpeg can do much of the basic muxing, but MP4Box gives finer control over the MP4 structure (brands, sample descriptions, edit lists, interleaving, fragmentation) and is a common choice for streaming packaging and for files that must pass strict MP4 validators or hardware players.

GPAC publishes installers for Windows and macOS, Linux packages and nightly builds on gpac.io/downloads. It is also packaged as gpac by most Linux distributions and by Homebrew. MP4Box is installed together with the gpac command, which exposes the same framework as a filter pipeline.

Terminal window
MP4Box -info input.mp4
MP4Box -diso input.mp4

-info lists the brands, tracks, track IDs, codecs, durations and whether the file is fragmented. -diso dumps the complete box structure to input_info.xml for detailed debugging.

Terminal window
MP4Box -add video.ivf -add audio.opus -new output.mp4

-new creates a new file. Without it, MP4Box edits the named file in place, adding to whatever it already contains.

Import options are appended to the file name with : and track selectors with #:

Terminal window
MP4Box -add video.h264:fps=24000/1001 -add audio.m4a:lang=ja -new output.mp4
MP4Box -add input.mkv#video -add input.mkv#audio -new output.mp4

Raw H.264/HEVC streams carry no timing, so give their frame rate with :fps=. #video, #audio and #trackID=N pick tracks from container inputs. Other useful import options are :name= (track title), :delay= (in milliseconds) and :dur= (import only part of the stream).

Terminal window
MP4Box -lang 2=ja input.mp4 # set the language of track ID 2, in place
MP4Box -rem 3 input.mp4 # remove track ID 3, in place
MP4Box -cat part1.mp4 -cat part2.mp4 -new joined.mp4
MP4Box -raw 1 input.mp4 # extract track ID 1 as a raw stream
MP4Box -split 300 input.mp4 # split into 300-second pieces at keyframes

Track IDs come from -info and usually start at 1. -cat requires the same codec and compatible settings in every part.

Terminal window
MP4Box -frag 2000 input.mp4 -out fragmented.mp4
MP4Box -dash 4000 -rap -profile onDemand -out dash/manifest.mpd input.mp4#video input.mp4#audio
MP4Box -dash 4000 -rap -out hls/master.m3u8 input.mp4#video input.mp4#audio

-frag writes a fragmented MP4 with fragments of about the given length in milliseconds. -dash sets the segment duration in milliseconds, and -rap starts every segment on a keyframe; the manifest type follows the -out extension (.mpd for DASH, .m3u8 for HLS). The onDemand profile writes one file per track, indexed for byte-range requests.

Segments can only start on keyframes, so encode with a fixed keyframe interval that divides the segment length (for example a keyframe every 2 seconds for 4-second segments). For adaptive streaming with several renditions, all renditions need their keyframes at the same timestamps; pass every rendition to the same -dash command.

The MP4Box documentation on the GPAC wiki covers every option; MP4Box -h import, -h dash and -h dump print the same sections offline.