MP4Box(1)

๐Ÿ’– MP4Box(1) ๐Ÿ’–

okay bestie, buckle UP โ€” this is the manual page for MP4Box, straight out of the GPAC fam. It's MP4Box(1), which means section 1 of the manual, and yes it's the command-line one, the one you actually run in your terminal like the main character you are. ๐ŸŽ€


โœจ NAME โœจ

MP4Box โ€” the GPAC command-line media packager ๐Ÿฆ‹

Likeโ€ฆ it packs media. From the command line. That's the whole vibe. GPAC's little terminal bestie. ๐Ÿ’…


โœจ SYNOPSIS โœจ

MP4Box [options] [file] [options]

Read it again, carefully, because the order is doing a thing:

  • MP4Box โ€” the program itself, iconic, no notes ๐Ÿ‘‘
  • [options] โ€” options go first, because sure
  • [file] โ€” then a file, if you feel like it
  • [options] โ€” and then MORE OPTIONS after the file, because why would it be simple bestie ๐Ÿ˜ญ

The square brackets mean optional, so technically MP4Box alone is valid syntax, which is very "I showed up to class with no supplies" energy. But fr fr, the options-after-the-file thing is real and you will absolutely use it, so don't come for me. ๐Ÿ’€

โœจ General Options โœจ

okay bestie, so MP4Box is literally a multimedia packager with a vast number of functionalities: conversion, splitting, hinting, dumping, DASH-ing, encryption, transcoding and others. It's giving Swiss Army knife but for media. ๐ŸŽ€ MP4Box provides a large set of options, classified by categories (see -h). These options do not follow any particular ordering. No cap.

By default, MP4Box rewrites the input file. You can change this behavior by using the out option. MP4Box stores by default the file with 0.5 second interleaving and metadata (moov ...) at the beginning, making it suitable for HTTP download-and-play. This may however takes longer to store the file, use flat to change this behavior. ๐Ÿ’…

MP4Box usually generates a temporary file when creating a new IsoMedia file. The location of this temporary file is OS-dependent, and it may happen that the drive/partition the temporary file is created on has not enough space or no write access. In such a case, you can specify a temporary file location with -tmp. ๐Ÿ—‚๏ธ

Track identifier for track-based operations (usually referred to as tkID in the help) use the following syntax:

  • INT: target is track with ID INT
  • nINT: target is track number INT
  • audio, video, text: target is first audio, video or text track
  • audioN, videoN, textN: target is the Nth audio, video or text track, with N=1 being the first track of desired type

Option values: Unless specified otherwise, a track operation option of type integer expects a track identifier value following it. An option of type boolean expects no following value. โœจ


  • -mem-track โ€” enable memory tracker ๐Ÿง 
  • -mem-track-stack โ€” enable memory tracker with stack dumping ๐Ÿ“š
  • -p (string) โ€” use indicated profile for the global GPAC config. If not found, config file is created. If a file path is indicated, this will load profile from that file. Otherwise, this will create a directory of the specified name and store new config there. Reserved name 0 means a new profile, not stored to disk. Works using -p=NAME or -p NAME ๐Ÿ‘‘
  • -inter (number, default: 0.5) โ€” interleave file, producing track chunks with given duration in ms. A value of 0 disables interleaving ๐Ÿ”€
  • -old-inter (number) โ€” same as inter but without drift correction ๐Ÿ•ฐ๏ธ
  • -tight โ€” tight interleaving (sample based) of the file. This reduces disk seek operations but increases file size ๐Ÿ’พ
  • -flat โ€” store file with all media data first, non-interleaved. This speeds up writing time when creating new files โšก
  • -frag (number) โ€” fragment file, producing track fragments of given duration in ms. This disables interleaving ๐Ÿงฉ
  • -out (string) โ€” specify ISOBMFF output file name. By default input file is overwritten ๐Ÿ“
  • -co64 โ€” force usage of 64-bit chunk offsets for ISOBMF files ๐Ÿ”ข
  • -new โ€” force creation of a new destination file ๐Ÿ†•
  • -newfs โ€” force creation of a new destination file without temp file but interleaving support ๐Ÿ†•โœจ
  • -no-sys,-nosys โ€” remove all MPEG-4 Systems info except IOD, kept for profiles. This is the default when creating regular AV content ๐Ÿšซ
  • -no-iod โ€” remove MPEG-4 InitialObjectDescriptor from file ๐Ÿšซ
  • -mfra โ€” insert movie fragment random offset when fragmenting file (ignored in dash mode) ๐Ÿ“
  • -isma โ€” rewrite the file as an ISMA 1.0 file ๐Ÿ“ผ
  • -ismax โ€” same as isma and remove all clock references โฐ
  • -3gp โ€” rewrite as 3GPP(2) file (no more MPEG-4 Systems Info), always enabled if destination file extension is .3gp, .3g2 or .3gpp. Some tracks may be removed in the process ๐Ÿ“ฑ
  • -ipod โ€” rewrite the file for iPod/old iTunes ๐ŸŽต
  • -psp โ€” rewrite the file for PSP devices ๐ŸŽฎ
  • -brand (string) โ€” set major brand of file (ABCD) or brand with optional version (ABCD:v) ๐Ÿท๏ธ
  • -ab (string) โ€” add given brand to file's alternate brand list โž•
  • -rb (string) โ€” remove given brand to file's alternate brand list โž–
  • -cprt (string) โ€” add copyright string to file ยฉ๏ธ
  • -chap (string) โ€” set chapter information from given file. The following formats are supported (but cannot be mixed) in the chapter text file:
    • ZoomPlayer: AddChapter(nb_frames,chapter name), AddChapterBySeconds(nb_sec,chapter name) and AddChapterByTime(h,m,s,chapter name) with 1 chapter per line
    • Time codes: h:m:s chapter_name, h:m:s:ms chapter_name and h:m:s.ms chapter_name with 1 chapter per line
    • SMPTE codes: h:m:s;nb_f/fps chapter_name and h:m:s;nb_f chapter_name with nb_f the number of frames and fps the framerate with 1 chapter per line
    • Common syntax: CHAPTERX=h:m:s[:ms or .ms] on first line and CHAPTERXNAME=name on next line (reverse order accepted)
  • -chapqt (string) โ€” set chapter information from given file, using QT signaling for text tracks ๐Ÿ“–
  • -set-track-id tkID:id2 โ€” change id of track to id2 ๐Ÿ”„
  • -swap-track-id tkID1:tkID1 โ€” swap the id between tracks with id1 to id2 ๐Ÿ”
  • -rem (int) โ€” remove given track from file ๐Ÿ—‘๏ธ
  • -rap (int) โ€” remove all non-RAP samples from given track ๐ŸŽฏ
  • -refonly (int) โ€” remove all non-reference pictures from given track ๐Ÿ–ผ๏ธ
  • -enable (int) โ€” enable given track โœ…
  • -disable (int) โ€” disable given track โŒ
  • -timescale (int, default: 600) โ€” set movie timescale to given value (ticks per second) โฑ๏ธ
  • -lang [tkID=]LAN โ€” set language. LAN is the BCP-47 code (eng, en-UK, ...). If no track ID is given, sets language to all tracks ๐ŸŒ
  • -delay tkID=TIME โ€” set track start delay (>0) or initial skip (<0) in ms or in fractional seconds (N/D) โณ
  • -par tkID=PAR โ€” set visual track pixel aspect ratio. PAR is:
    • N:D: set PAR to N:D in track, do not modify the bitstream
    • wN:D: set PAR to N:D in track and try to modify the bitstream
    • none: remove PAR info from track, do not modify the bitstream
    • auto: retrieve PAR info from bitstream and set it in track
    • force: force 1:1 PAR in track, do not modify the bitstream
  • -clap tkID=CLAP โ€” set visual track clean aperture. CLAP is Wn,Wd,Hn,Hd,HOn,HOd,VOn,VOd or none
    • n, d: numerator, denominator
    • W, H, HO, VO: clap width, clap height, clap horizontal offset, clap vertical offset
  • -mx tkID=MX โ€” set track matrix, with MX is M1:M2:M3:M4:M5:M6:M7:M8:M9 in 16.16 fixed point integers or hexa ๐Ÿ”ข
  • -kind tkID=schemeURI=value โ€” set kind for the track or for all tracks using all=schemeURI=value ๐Ÿท๏ธ
  • -kind-rem tkID=schemeURI=value โ€” remove kind if given schemeID for the track or for all tracks with all=schemeURI=value ๐Ÿ—‘๏ธ
  • -name tkID=NAME โ€” set track handler name to NAME (UTF-8 string) ๐Ÿ“›
  • -tags,-itags (string) โ€” set iTunes tags to file, see -h tags ๐ŸŽต
  • -group-add (string) โ€” create a new grouping information in the file. Format is a colon-separated list of following options:
    • refTrack=ID: track used as a group reference. If not set, the track will belong to the same group as the previous trackID specified. If 0 or no previous track specified, a new alternate group will be created
    • switchID=ID: ID of the switch group to create. If 0, a new ID will be computed for you. If <0, disables SwitchGroup
    • criteria=string: list of space-separated 4CCs
    • trackID=ID: track to add to this group
Warning: Options modify state as they are parsed, trackID=1:criteria=lang:trackID=2 is different from criteria=lang:trackID=1:trackID=2 โš ๏ธ
  • -group-rem-track (int) โ€” remove given track from its group ๐Ÿ—‘๏ธ
  • -group-rem (int) โ€” remove the track's group ๐Ÿ—‘๏ธ
  • -group-clean โ€” remove all group information from all tracks ๐Ÿงน
  • -ref tkID:R4CC:refID โ€” add a reference of type R4CC from track ID to track refID (remove track reference if refID is 0) ๐Ÿ”—
  • -keep-utc โ€” keep UTC timing in the file after edit ๐Ÿ•ฐ๏ธ
  • -udta tkID:[OPTS] โ€” set udta for given track or movie if tkID is 0. OPTS is a colon separated list of:
    • type=CODE: 4CC code of the UDTA (not needed for box= option)
    • box=FILE: location of the udta data, formatted as serialized boxes
    • box=base64,DATA: base64 encoded udta data, formatted as serialized boxes
    • src=FILE: location of the udta data (will be stored in a single box of type CODE)
    • src=base64,DATA: base64 encoded udta data (will be stored in a single box of type CODE)
    • str=STRING: use the given string as payload for the udta box
Note: If no source is set, UDTA of type CODE will be removed ๐Ÿ“ฆ
  • -patch [tkID=]FILE โ€” apply box patch described in FILE, for given trackID if set ๐Ÿฉน
  • -bo โ€” freeze the order of boxes in input file ๐ŸงŠ
  • -init-seg (string) โ€” use the given file as an init segment for dumping or for encryption ๐ŸŽฌ
  • -zmov โ€” compress movie box according to ISOBMFF box compression or QT if mov extension ๐Ÿ—œ๏ธ
  • -xmov โ€” same as zmov and wraps ftyp in otyp ๐Ÿ—œ๏ธโœจ
  • -edits tkID=EDITS โ€” set edit list. The following syntax is used (no separators between entries):
    • r: removes all edits
    • eSTART: add empty edit with given start time. START can be
      • VAL: start time in seconds (int, double, fraction), media duration used as edit duration
      • VAL-DUR: start time and duration in seconds (int, double, fraction)
    • eSTART,MEDIA[,RATE]: add regular edit with given start, media start time in seconds (int, double, fraction) and rate (fraction or INT)
    • Examples:
      • re0-5e5-3,4: remove edits, add empty edit at 0s for 5s, then add regular edit at 5s for 3s starting at 4s in media track
      • re0-4,0,0.5: remove edits, add single edit at 0s for 4s starting at 0s in media track and playing at speed 0.5
  • -moovpad (int) โ€” specify amount of padding to keep after moov box for later inplace editing - if 0, moov padding is disabled ๐Ÿงฉ
  • -no-inplace โ€” disable inplace rewrite ๐Ÿšซ
  • -hdr (string) โ€” update HDR information based on given XML, none removes HDR info ๐ŸŒˆ
  • -time [tkID=]DAY/MONTH/YEAR-H:M:S โ€” set movie or track creation time ๐Ÿ“…
  • -mtime tkID=DAY/MONTH/YEAR-H:M:S โ€” set media creation time ๐Ÿ“…

โœจ Extracting Options โœจ

Okay so MP4Box can absolutely be used to extract media tracks from MP4 files ๐Ÿ’… bestie that's its whole thing. BUT โ€” and this is the important part โ€” if you need to convert those tracks after you pull them out, you gotta go check the filters doc instead. Different vibe, different doc. ๐Ÿฆ‹

Options, bb:

  • -raw (string) โ€” extract the given track in raw format when that's supported. Wanna name your own output file? Use tkID:output=FileName and it's yours. ๐ŸŽ€
  • -raws (string) โ€” extract each sample of the given track to its own file. Use tkID:N to grab just the Nth sample. one sample, one file, no cap. โœจ
  • -nhnt (int) โ€” extract the given track into NHNT format.
  • -nhml (string) โ€” extract the given track into NHML format. Add tkID:full if you want the full NHML dump with literally every packet property in it. ๐Ÿ’–
  • -webvtt-raw (string) โ€” extract the given track as raw media in WebVTT as metadata. Use tkID:embedded to shove the media data right into the WebVTT file. ๐ŸŒธ
  • -single (int) โ€” extract the given track into a brand new mp4 file. glow up โœจ
  • -six (int) โ€” extract the given track as raw media in experimental XML streaming instructions. yes it says experimental. we move anyway. ๐Ÿ™ˆ
  • -mux (string) โ€” multiplex the input file to the destination you give it. ๐ŸŽฌ
  • -qcp (int) โ€” same as -raw but it defaults to a QCP file for EVRC/SMV.
  • -saf โ€” multiplex the input file to SAF multiplex.
  • -dvbhdemux โ€” demultiplex a DVB-H file into IP Datagrams that get sent on the network. it's giving networking era ๐ŸŒˆ
  • -raw-layer (int) โ€” same as -raw but it skips the SVC/MVC/LHVC extractors while extracting.
  • -diod โ€” extract the file IOD in raw format. iconic.
  • -mpd (string) โ€” convert the given HLS or smooth manifest (local or remote http, both fine) to MPD โ€” options -url-template and -segment-timelinecan be used in this mode.
Note: this only provides basic conversion. For more advanced conversions, go see gpac -h dasher. ๐Ÿ‘‘
Warning: this is not compatible with other DASH options and it does not convert associated segments. fr fr, heads up. ๐Ÿ’€

๐ŸŒˆ DASH Options ๐ŸŒˆ

Also see, bestie:

  • the dasher gpac -h dasher filter documentation ๐Ÿ“š
  • [[DASH wiki|DASH-intro]] โœจ

๐Ÿ“ฅ Specifying input files ๐Ÿ“ฅ

Input media files to dash can use the following modifiers โ€” think of them as little accessories you can clip onto your filename ๐Ÿ’…:

  • #trackID=N: only use the track ID N from the source file
  • #N: only use the track ID N from the source file (this one's mapped to -tkid)
  • #video: only use the first video track from the source file
  • #audio: only use the first audio track from the source file
  • #Prop=Value: add PID filtering using the same syntax as SID fragments (cf gpac -h doc)
  • :id=NAME: set the representation ID to NAME. The reserved value NULL disables the representation ID for multiplexed inputs. If you don't set it, a default value gets computed and all selected tracks from the source end up in the same output multiplex.
  • :dur=VALUE: process VALUE seconds (fraction) from the media. If VALUE is longer than the media duration, the last sample duration gets extended.
  • :period=NAME: set the representation's period to NAME. You can use multiple periods. Periods show up in the MPD in the exact same order you specified them with this option.
  • :BaseURL=NAME: set the BaseURL. Set it multiple times for multiple BaseURLs.
Warning: this does not modify the generated files location (see segment template). ๐Ÿ™ˆ
  • :bandwidth=VALUE: set the representation's bandwidth to the value you give it
  • :pdur=VALUE: sets the duration of the associated period to VALUE seconds (fraction) (it's an alias for period_duration:VALUE). This only gets used when no input media is specified (remote period insertion), e.g. :period=X:xlink=Z:pdur=Y
  • :ddur=VALUE: override the target DASH segment duration to VALUE seconds (fraction) for this input (alias for duration:VALUE)
  • :xlink=VALUE: set the xlink value for the period containing this element. Only the xlink declared on the first rep of a period will be used.
  • :asID=VALUE: set the AdaptationSet ID to VALUE (unsigned int)
  • :role=VALUE: set the role of this representation (cf DASH spec). Media with different roles belong to different adaptation sets.
  • :desc_p=VALUE: add a descriptor at the Period level.
  • :desc_as=VALUE: add a descriptor at the AdaptationSet level. Two input files with different values will land in different AdaptationSet elements.
  • :desc_as_c=VALUE: add a descriptor at the AdaptationSet level. The value is ignored while creating AdaptationSet elements.
  • :desc_rep=VALUE: add a descriptor at the Representation level. The value is ignored while creating AdaptationSet elements.
  • :sscale: force the movie timescale to match the media timescale of the first track in the segment.
  • :trackID=N: same as setting the fragment #trackID=
  • @f1[:args][@fN:args][@@fK:args]: set a filter chain to insert between the source and the dasher. Each filter in the chain is formatted as a regular filter, see the filter doc gpac -h doc. If you set several filters:
    • they'll be chained in the order you gave them if they're separated by a single @
    • a new filter chain gets created if they're separated by a double @@. In this case, no representation ID is assigned to the source.

Example:

source.mp4:@c=avc:b=1M@@c=avc:b=500k

This will load a filter chain with two encoders connected to the source and to the dasher. ๐ŸŽ€

Example:

source.mp4:@c=avc:b=1M@c=avc:b=500k

This will load a filter chain with the second encoder connected to the output of the first (!!). yes that's a real exclamation, we're all fine ๐Ÿ’€

Note: @f must be placed after all other options. like, after. all of them. ๐Ÿซถ
Note: Descriptors value must be a properly formatted XML element(s), and the value is not checked. The syntax can use file@FILENAME to load content from a file. ๐ŸŒธ

โœจ Options โœจ

bestie this is the DASH options motherlode ๐Ÿ’… grab a boba, we're going through every single one, no skips, no cap.

  • -dash number โ€” creates a DASH out of your input files, where number is the segment duration in ms (for the onDemand profile it's the subsegment duration instead) ๐ŸŽฌ
  • -dash-live number โ€” generates a live DASH session using number as the segment duration in ms. bonus mode: doing -dash-live=F also writes the live context out to F. MP4Box just stays in the live session until you press q or something fatal happens ๐Ÿ’€
  • -ddbg-live number โ€” literally the same as -dash-live but with no time regulation, purely for debug purposes ๐Ÿ›
  • -frag number โ€” sets the fragment duration in ms. if you don't set it, it defaults to the DASH duration (so one fragment per segment, cute) โœจ
  • -out string โ€” names your output MPD file, periodt ๐Ÿ“
  • -profile, -dash-profile string โ€” picks the target DASH profile and auto-sets default options so you actually conform to it. default is full in static mode, live in dynamic mode (and yes, the old syntax using :live instead of .live as the separator is still possible, legacy icon ๐Ÿ‘‘). the defined values are onDemand, live, main, simple, full, hbbtv1.5.live, dashavc264.live, dashavc264.onDemand, dashif.ll
  • -profile-ext string โ€” sets a list of profile extensions, the way DASH-IF and DVB use them. the string gets colon-concatenated with whatever profile you're using ๐Ÿ”—
  • -rap โ€” makes sure segments begin with random access points. heads up tho: segment durations might vary depending on the source encoding, it's giving chaotic but valid ๐ŸŒˆ
  • -frag-rap โ€” same vibe but for all the fragments: every fragment begins with a random access point (durations might vary depending on the source encoding) ๐ŸŽฏ
  • -segment-name string โ€” sets the segment name for the segments you generate. if you don't set it (default), segments get concatenated in the output file โ€” except in the live profile where it's dash_%%s. the supported replacement strings are:
    • $Number[%%0Nd]$ gets replaced by the segment number, possibly prefixed with 0
    • $RepresentationID$ gets replaced by representation name
    • $Time$ gets replaced by segment start time
    • $Bandwidth$ gets replaced by representation bandwidth
    • $Init=NAME$ gets replaced by NAME for init segment, ignored otherwise
    • $Index=NAME$ gets replaced by NAME for index segments, ignored otherwise
    • $Path=PATH$ gets replaced by PATH when creating segments, ignored otherwise
    • $SubNumber[%%0Nd]$ gets replaced by the segment subnumber in segment sequences, possibly prefixed with 0
    • $Segment=NAME$ gets replaced by NAME for media segments, ignored for init segments
  • -segment-ext string, default: m4s โ€” sets the segment extension. null means no extension at all ๐Ÿšซ
  • -init-segment-ext string, default: mp4 โ€” sets the segment extension for init, index and bitstream switching segments. null means no extension ๐Ÿ™…
  • -segment-timeline โ€” uses SegmentTimeline when generating segments ๐Ÿ“Š
  • -segment-marker string โ€” adds a box of the given type (a 4CC) at the end of each DASH segment ๐Ÿท๏ธ
  • -insert-utc โ€” inserts a UTC clock at the beginning of each ISOBMF segment โฐ
  • -base-url string โ€” sets the Base url at MPD level. can be used several times.
Warning: this does not modify generated files location, so don't let it fool you bestie ๐Ÿซ 
  • -mpd-title string โ€” sets the MPD title ๐Ÿ“›
  • -mpd-source string โ€” sets the MPD source ๐Ÿ“š
  • -mpd-info-url string โ€” sets the MPD info url ๐Ÿ”—
  • -cprt string โ€” adds a copyright string to the MPD ยฉ๏ธ
  • -dash-ctx string โ€” store/restore DASH timing from the file you point at ๐Ÿ’พ
  • -dynamic โ€” uses the dynamic MPD type instead of static ๐ŸŒ€
  • -last-dynamic โ€” same as -dynamic but it closes the period (inserts the lmsg brand if needed and updates the duration) ๐Ÿ”’
  • -mpd-duration number โ€” sets the duration in seconds of a live session (if it's 0, you gotta use -mpd-refresh) โณ
  • -mpd-refresh number โ€” sets the MPD update time in seconds ๐Ÿ”„
  • -time-shift int โ€” sets the MPD time shift buffer depth in seconds. -1 keeps all the files. default is 0 ๐Ÿ•ฐ๏ธ
  • -subdur number โ€” sets the max duration in ms of the input file to be dashed in LIVE or context mode. this does not change the segment duration, it just stops dashing once the segments produced exceed that duration. if there aren't enough samples to finish a segment, data is looped โ€” unless -no-loop is used, which triggers a period end ๐Ÿ”
  • -run-for int โ€” runs the dash-live session for the given ms, then dips out ๐Ÿƒโ€โ™€๏ธ
  • -min-buffer int โ€” sets the MPD min buffer time in ms ๐Ÿงบ
  • -ast-offset int โ€” sets the MPD AvailabilityStartTime offset in ms if positive, or the availabilityTimeOffset of each representation if negative โš–๏ธ
  • -dash-scale int โ€” says the timing for -dash, -dash-live, -subdur and -frag is expressed in the given timescale (units per seconds) rather than ms ๐Ÿ“
  • -mem-frags โ€” fragmentation happens in memory rather than on disk before flushing to disk ๐Ÿง 
  • -pssh int โ€” sets the pssh store mode:
    • v: initial movie
    • f: movie fragments
    • m: MPD
    • mv, vm: in initial movie and MPD
    • mf, fm: in movie fragments and MPD
    • n: remove PSSH from MPD, initial movie and movie fragments
  • -sample-groups-traf โ€” stores sample group descriptions in traf (duplicated for each traf). if not set, sample group descriptions go in the initial movie ๐Ÿ“ฆ
  • -mvex-after-traks โ€” stores the mvex box after the trak boxes within the moov box. if not set, mvex goes before ๐Ÿ—‚๏ธ
  • -sdtp-traf int โ€” uses the sdtp box in traf (Smooth-like):
    • no: do not use sdtp
    • sdtp: use the sdtp box to indicate sample dependencies and do not write info in trun sample flags
    • both: use the sdtp box to indicate sample dependencies and also write info in trun sample flags
  • -no-cache โ€” disables the file cache for dash inputs ๐Ÿšซ
  • -no-loop โ€” disables looping content in live mode and uses period switch instead ๐Ÿ”„
  • -hlsc โ€” inserts UTC in variant playlists for live HLS โฑ๏ธ
  • -bound โ€” segmentation will always try to split before or at, but never after, the segment boundary โœ‚๏ธ
  • -closest โ€” segmentation will use the closest frame to the segment boundary (before or after) ๐ŸŽฏ
  • -subsegs-per-sidx, -frags-per-sidx int โ€” sets the number of subsegments to be written in each SIDX box:
    • 0: a single SIDX box is used per segment
    • -1: no SIDX box is used
  • -ssix โ€” enables SubsegmentIndexBox describing 2 ranges, first one from moof to end of first I-frame, second one unmapped. this does not work with daisy chaining mode enabled โš ๏ธ
  • -url-template โ€” uses SegmentTemplate instead of explicit sources in segments. ignored if segments are stored in the output file ๐Ÿ”—
  • -url-template-sim โ€” uses SegmentTemplate simulation while converting HLS to MPD ๐Ÿงช
  • -daisy-chain โ€” uses daisy-chain SIDX instead of hierarchical. ignored if frags/sidx is 0 โ›“๏ธ
  • -single-segment โ€” uses a single segment for the whole file (OnDemand profile) 1๏ธโƒฃ
  • -single-file โ€” uses a single file for the whole file (default) ๐Ÿ“„
  • -bs-switching string, default: inband, values: inband|merge|multi|no|single โ€” sets the bitstream switching mode:
    • inband: use inband param set and a single init segment
    • merge: try to merge param sets in a single sample description, fallback to no
    • multi: use several sample description, one per quality
    • no: use one init segment per quality
    • pps: use out of band VPS,SPS,DCI, inband for PPS,APS and a single init segment
    • single: to test with single input
  • -moof-sn int โ€” sets the sequence number of the first moof to the given value ๐Ÿ”ข
  • -tfdt int โ€” sets the TFDT of the first traf to the given value in SCALE units (cf -dash-scale) โฒ๏ธ
  • -no-frags-default โ€” disables default fragments flags in trex (required by some dash-if profiles and CMAF/smooth streaming compatibility) ๐Ÿšง
  • -single-traf โ€” uses a single track fragment per moof (smooth streaming and derived specs may require this) 1๏ธโƒฃ
  • -tfdt-traf โ€” uses a tfdt per track fragment (when -single-traf is used) โฒ๏ธ
  • -dash-ts-prog int โ€” program_number to be considered in case of an MPTS input file ๐Ÿ“บ
  • -frag-rt โ€” when using fragments in live mode, flush fragments according to their timing โฑ๏ธ
  • -cp-location string โ€” sets the ContentProtection element location:
    • as: sets ContentProtection in the AdaptationSet element
    • rep: sets ContentProtection in the Representation element
    • both: sets ContentProtection in both elements
  • -start-date string โ€” for live mode, sets the start date (as xs:date, e.g. YYYY-MM-DDTHH:MM:SSZ). default is current UTC.
Warning: do not use with multiple periods, nor when DASH duration is not a multiple of GOP size ๐Ÿ˜ญ
  • -cues string โ€” ignores dash duration and segments according to cue times in the given XML file (see tests/media/dash_cues for examples) ๐ŸŽฏ
  • -strict-cues โ€” throws an error if something is wrong while parsing cues or applying cue-based segmentation ๐Ÿ’ฅ
  • -merge-last-seg โ€” merges the last segment if it's shorter than half the target duration ๐Ÿค

๐ŸŒˆ File splitting โœ‚๏ธ

okay bestie, this is the glow-up section โ€” MP4Box can split your input files by size, by duration, or straight-up extract a given part of the file into new IsoMedia file(s). ๐Ÿ’…

The catch? This needs at most one track in the input file to have non random-access points (so like, typically one video track at most). Fr fr.

Splitting will ignore all MPEG-4 Systems tracks and hint tracks, but it will try to split private media tracks. She's inclusive like that. ๐Ÿซถ

Your input file also needs enough random access points to actually be splittable. If notโ€ฆ ๐Ÿ˜ญ you will have to re-encode the content. No cap.

Oh and you can add media to a file and split it in the same pass! Iconic. But heads up: in this case, the destination file (the one which would be obtained without splitting) will not be stored. It's giving "trust the process".


Time ranges are specified as follows:

  • S-E โ€” S start and E end times, formatted as HH:MM:SS.ms, MM:SS.ms or time in seconds (int, double, fraction)
  • S:E โ€” S start time and E end times in seconds (int, double, fraction). If E is prefixed with D, this sets E = S + time
  • S:end or S:end-N โ€” S start time in seconds (int, double), N number of seconds (int, double) before the end

MP4Box splitting runs a filter session using the reframer filter as follows:

  • splitrange option of the reframer is always set
  • source is demultiplexed with alltk option set
  • start and end ranges are passed to xs and xe options of the reframer
  • for -splitz, options xadjust and xround=after are enforced
  • for -splitg, options xadjust and xround=before are enforced
  • for -splitf, option xround=seek is enforced and propbe_refset if not specified at prompt
  • for -splitx, option xround=closest and propbe_ref are enforced if not specified at prompt

The default output storage mode is to full interleave and will require a temp file for each output. ๐Ÿ—‚๏ธ This behavior can be modified using -flat, -newfs, -inter and -frag.

The output file name(s) can be specified using -out and templates (e.g. -out split$num%04d$.mp4 produces split0001.mp4, split0002.mp4, ...). โœจ

Multiple time ranges can be specified as a comma-separated list for -splitx, -splitz and -splitg. Slay.

  • -split (string) โ€” split in files of given max duration (float number) in seconds. A trailing unit can be specified:
    • M, m: duration is in minutes
    • H, h: size is in hours
  • -split-rap, -splitr โ€” split in files at each new RAP ๐ŸŽฏ
  • -split-size, -splits (string) โ€” split in files of given max size (integer number) in kilobytes. A trailing unit can be specified:
    • M, m: size is in megabytes
    • G, g: size is in gigabytes
  • -split-chunk, -splitx (string) โ€” extract the specified time range as follows:
    • the start time is moved to the RAP sample closest to the specified start time
    • the end time is kept as requested
  • -splitz (string) โ€” extract the specified time range so that ranges A:B and B:C share exactly the same boundary B:
    • the start time is moved to the RAP sample at or after the specified start time
    • the end time is moved to the frame preceding the RAP sample at or following the specified end time
  • -splitg (string) โ€” extract the specified time range as follows:
    • the start time is moved to the RAP sample at or before the specified start time
    • the end time is moved to the frame preceding the RAP sample at or following the specified end time
  • -splitf (string) โ€” extract the specified time range and insert edits such that the extracted output is exactly the specified range ๐ŸŽ€

๐ŸŒธ File Dumping ๐ŸŒธ

MP4Box has many dump functionalities, from simple track listing to more complete reporting of special tracks. She contains multitudes, bestie. ๐Ÿ’–

Options:

  • -std โ€” dump/write to stdout and assume stdout is opened in binary mode
  • -stdb โ€” dump/write to stdout and try to reopen stdout in binary mode
  • -tracks โ€” print the number of tracks on stdout
  • -info (string) โ€” print movie info (no parameter) or track extended info with specified ID
  • -infon (string) โ€” print track info for given track number, 1 being the first track in the file
  • -infox โ€” print movie and track extended info (same as -info N for each track)
  • -diso, -dmp4 โ€” dump IsoMedia file boxes in XML output
  • -dxml โ€” dump IsoMedia file boxes and known track samples in XML output
  • -disox โ€” dump IsoMedia file boxes except sample tables in XML output
  • -keep-comp โ€” do not decompress boxes when dumping
  • -keep-ods โ€” do not translate ISOM ODs and ESDs tags (debug purpose only)
  • -bt โ€” dump scene to BT format
  • -xmt โ€” dump scene to XMT format
  • -wrl โ€” dump scene to VRML format
  • -x3d โ€” dump scene to X3D XML format
  • -x3dv โ€” dump scene to X3D VRML format
  • -lsr โ€” dump scene to LASeR XML (XSR) format
  • -svg โ€” dump scene to SVG
  • -drtp โ€” dump rtp hint samples structure to XML output
  • -dts โ€” print sample timing, size and position in file to text output
  • -dtsx โ€” same as -dts but does not print offset
  • -dtsc โ€” same as -dts but analyses each sample for duplicated dts/cts (slow !) ๐ŸŒ
  • -dtsxc โ€” same as -dtsc but does not print offset (slow !) ๐ŸŒ
  • -dnal (int) โ€” print NAL sample info of given track
  • -dnalc (int) โ€” print NAL sample info of given track, adding CRC for each nal
  • -dnald (int) โ€” print NAL sample info of given track without DTS and CTS info
  • -dnalx (int) โ€” print NAL sample info of given track without DTS and CTS info and adding CRC for each nal
  • -sdp โ€” dump SDP description of hinted file
  • -dsap (int) โ€” dump DASH SAP cues (see -cues) for a given track
  • -dsaps (int) โ€” same as -dsap but only print sample number
  • -dsapc (int) โ€” same as -dsap but only print CTS
  • -dsapd (int) โ€” same as -dsap but only print DTS
  • -dsapp (int) โ€” same as -dsap but only print presentation time
  • -dcr โ€” dump ISMACryp samples structure to XML output
  • -dchunk โ€” dump chunk info
  • -dump-cover โ€” extract cover art ๐ŸŽจ
  • -dump-chap โ€” extract chapter file as TTXT format
  • -dump-chap-ogg โ€” extract chapter file as OGG format
  • -dump-chap-zoom โ€” extract chapter file as zoom format
  • -dump-udta [tkID:]4cc โ€” extract user data for the given 4CC. If tkID is given, dumps from UDTA of the given track ID, otherwise moov is used
  • -mergevtt โ€” merge vtt cues while dumping
  • -ttxt (int) โ€” convert input subtitle to GPAC TTXT format if no parameter. Otherwise, dump given text track to GPAC TTXT format
  • -srt (int) โ€” convert input subtitle to SRT format if no parameter. Otherwise, dump given text track to SRT format
  • -nstat โ€” generate node/field statistics for scene
  • -nstats โ€” generate node/field statistics per Access Unit
  • -nstatx โ€” generate node/field statistics for scene after each AU
  • -hash โ€” generate SHA-1 Hash of the input file ๐Ÿ”
  • -comp (string) โ€” replace with compressed version all top level box types given as parameter, formatted as orig_4cc_1=comp_4cc_1[,orig_4cc_2=comp_4cc_2]
  • -topcount (string) โ€” print to stdout the number of top-level boxes matching box types given as parameter, formatted as 4cc_1,4cc_2N
  • -topsize (string) โ€” print to stdout the number of bytes of top-level boxes matching types given as parameter, formatted as 4cc_1,4cc_2N or all for all boxes
  • -bin โ€” convert input XML file using NHML bitstream syntax to binary
  • -mpd-rip โ€” fetch MPD and segment to disk
  • -udp-write (string, default: IP[:port]) โ€” write input name to UDP (default port 2345)
  • -raw-cat (string) โ€” raw concatenation of given file with input file
  • -wget (string) โ€” fetch resource from http(s) URL
  • -dm2ts โ€” dump timing of an input MPEG-2 TS stream sample timing
  • -check-xml โ€” check XML output format for -dnal*, -diso* and -dxml options
  • -fuzz-chk โ€” open file without probing and exit (for fuzz tests)

๐Ÿ’œ Importing Options ๐Ÿ’œ

๐Ÿฆ‹ File importing ๐Ÿฆ‹

Syntax is:

add / cat URL[#FRAGMENT][:opt1...:optN=val]

This process will create the destination file if not existing, and add the track(s) to it. If you wish to always create a new destination file, add -new.

The supported input media types depend on your installation, check filters documentation for more info. iykyk. ๐Ÿ‘‘

To select a desired media track from a source, a fragment identifier # can be specified, before any other options. The following syntax is used:

  • #video: adds the first video track found in source
  • #audio: adds the first audio track found in source
  • #auxv: adds the first auxiliary video track found in source
  • #pict: adds the first picture track found in source
  • #trackID=ID or #ID: adds the specified track. For IsoMedia files, ID is the track ID. For other media files, ID is the value indicated by MP4Box -info inputFile
  • #pid=ID: number of desired PID for MPEG-2 TS sources
  • #prog_id=ID: number of desired program for MPEG-2 TS sources
  • #program=NAME: name of desired program for MPEG-2 TS sources

By default all imports are performed sequentially, and final interleaving is done at the end; this however requires a temporary file holding original ISOBMF file (if any) and added files before creating the final output. Since this can become quite large, it is possible to add media to a new file without temporary storage, using -flat option, but this disables media interleaving. ๐Ÿ˜ฌ

If you wish to create an interleaved new file with no temporary storage, use the -newfs option. The interleaving might not be as precise as when using -new since it is dependent on multiplexer input scheduling (each execution might lead to a slightly different result). Additionally in this mode:

  • Some multiplexing options (marked with X below) will be activated for all inputs (e.g. it is not possible to import one AVC track with xps_inband and another without).
  • Some multiplexing options (marked as D below) cannot be used as they require temporary storage for file edition.
  • Usage of cat is possible, but concatenated sources will not be interleaved in the output. If you wish to perform more complex cat/add operations without temp file, use a playlist.

Source URL can be any URL supported by GPAC, not limited to local files. ๐ŸŒˆ

Note bestie ๐ŸŽ€ When you're importing SRT or SUB files, MP4Box is gonna pick default layout options so the subtitles show up at the bottom of the video. And likeโ€ฆ you SHOULD NOT import those files before any video track is already in the destination file, otherwise the results are probably gonna be straight-up useless (default SRT/SUB importing uses the default serif font, fontSize 18 and display size 400x60). Want the full tea? Go check the TTXT doc. โœจ

When you import several tracks/sources in one pass, all the options get applied if they're relevant to each source. These options are set for all the imported streams. If you need them per stream instead, set per-file options with the syntax -add stream[:opt1:...:optN]. ๐Ÿ’…

The import file name can be set to empty or self, which means the import options should be applied to the destination file track(s). For example:

-add self:moovts=-1:noedit src.mp4

This applies moovts and noedit to all tracks in src.mp4. Another one:

-add self#2:moovts=-1:noedit src.mp4

This applies moovts and noedit to the track with ID=2 in src.mp4. Only per-file options marked with a S work in this mode, just so you know. ๐Ÿ™ˆ

When you're importing an ISOBMFF/QT file, only options marked as C or S can be used.

When importing as an external track, only options marked as E can be used.


โœจ Allowed per-file options โœจ

  • dur (int) โ€” XCE โ€” import only the specified duration from the media. The value can be:
    • a positive float: that's the duration in seconds
    • a fraction: that's the duration as a NUM/DEN fraction
    • a negative integer: that's the duration in number of coded frames
  • start (number) โ€” C โ€” target start time in the source media. Heads up, it may not be supported depending on the source ๐Ÿ˜ญ
  • lang (string) โ€” SE โ€” set the imported media language code
  • delay (int) โ€” SE โ€” set the imported media initial delay (>0) or initial skip (<0), in ms or as fractional seconds (N/D)
  • par (string) โ€” S โ€” set the visual pixel aspect ratio (peep -par)
  • clap (string) โ€” S โ€” set the visual clean aperture (peep -clap)
  • mx (string) โ€” SE โ€” set the track matrix (peep -mx)
  • name (string) โ€” S โ€” set the track handler name
  • ext (string) โ€” override the file extension when importing
  • hdlr (string) โ€” S โ€” set the track handler type to the given code point (4CC)
  • stype (string) โ€” S โ€” force the sample description type to the given code point (4CC). Ngl this may likely break the file ๐Ÿ’€
  • tkhd (int) โ€” SE โ€” set the track header flags, either as a hex integer or as a comma-separated list of enable, movie, preview, size_ar keywords (use tkhd+=FLAGS to add and tkhd-=FLAGS to remove)
  • disable โ€” SE โ€” disable the imported track(s); use disable=no to force-enable a disabled track
  • group (int) โ€” SE โ€” add the track as part of the G alternate group. If G is 0, the first available GroupID gets picked
  • fps (string) โ€” S โ€” same as -fps
  • rap โ€” DS โ€” import only RAP samples
  • refs โ€” DS โ€” import only reference pictures
  • trailing โ€” keep trailing 0-bytes in AVC/HEVC samples
  • agg (int) โ€” X โ€” same as -agg
  • dref โ€” XC โ€” same as -dref
  • keep_refs โ€” C โ€” keep track reference when importing a single track
  • nodrop โ€” same as -no-drop
  • packed โ€” X โ€” same as -packed
  • sbr โ€” same as -sbr
  • sbrx โ€” same as -sbrx
  • ovsbr โ€” same as -ovsbr
  • ps โ€” same as -ps
  • psx โ€” same as -psx
  • asemode (string) โ€” XS โ€” set the mode used to create the AudioSampleEntry. The value can be:
    • v0-bs: use MPEG AudioSampleEntry v0 and the channel count from the bitstream (even if it's greater than 2) โ€” this is the default
    • v0-2: use MPEG AudioSampleEntry v0 and force the channel count to 2
    • v1: use MPEG AudioSampleEntry v1 and the channel count from the bitstream
    • v1-qt: use QuickTime Sound Sample Description Version 1 and the channel count from the bitstream (even if it's greater than 2). This also triggers using alis data references instead of url, even for non-audio tracks
  • audio_roll (int) โ€” S โ€” add a roll sample group with roll_distance N for audio tracks
  • roll (int) โ€” S โ€” add a roll sample group with roll_distance N
  • proll (int) โ€” S โ€” add a preroll sample group with roll_distance N
  • mpeg4 โ€” X โ€” same as the -mpeg4 option
  • nosei โ€” discard all SEI messages during import
  • svc โ€” import SVC/LHVC with explicit signaling (no AVC base compatibility)
  • nosvc โ€” discard SVC/LHVC data when importing
  • svcmode (string) โ€” DS โ€” set the SVC/LHVC import mode. The value can be:
    • split: each layer is in its own track
    • merge: all layers are merged in a single track
    • splitbase: all layers are merged in a track, and the base goes in another
    • splitnox: each layer is in its own track, and no extractors are written
    • splitnoxib: each layer is in its own track, no extractors are written, using inband param set signaling
  • temporal (string) โ€” DS โ€” set the HEVC/LHVC temporal sublayer import mode. The value can be:
    • split: each sublayer is in its own track
    • splitbase: all sublayers are merged in a track, and the HEVC base goes in another
    • splitnox: each layer is in its own track, and no extractors are written
  • subsamples โ€” add SubSample information for AVC+SVC
  • deps โ€” import sample dependency information for AVC and HEVC
  • ccst โ€” S โ€” add a default HEIF ccst box to the visual sample entry
  • forcesync โ€” SE โ€” force non IDR samples with I slices (OpenGOP or GDR) to be marked as sync points
Warning: THE RESULTING FILE IS NOT COMPLIANT WITH THE SPEC โ€” but it will fix seeking in most players, soโ€ฆ trade-offs, bestie ๐Ÿ˜ญ
  • xps_inband โ€” XC โ€” set xPS inband for AVC/H264 and HEVC (for the reverse operation, re-import from raw media)
  • xps_inbandx โ€” XC โ€” same as xps_inband and it also keeps the first xPS in the sample description
  • au_delim โ€” keep AU delimiter NAL units in the imported file
  • max_lid (int) โ€” set the HEVC max layer ID to be imported to N (by default it imports all layers)
  • max_tid (int) โ€” set the HEVC max temporal ID to be imported to N (by default it imports all temporal sublayers)
  • tiles โ€” S โ€” add HEVC tiles signaling and NALU maps without splitting the tiles into different tile tracks
  • split_tiles โ€” DS โ€” split HEVC tiles into different tile tracks, one tile (or all tiles of one slice) per track
  • negctts โ€” S โ€” use negative CTS-DTS offsets (ISO4 brand). Use negctts=no to force using a positive offset on an existing track
  • chap โ€” SE โ€” specify that the track is a chapter track
  • chapter (string) โ€” SE โ€” add a single chapter (old nero format) with the given name lasting the entire file
  • chapfile (string) โ€” SE โ€” add a chapter file (old nero format)
  • layout (string) โ€” SE โ€” specify the track layout as WxH[xXxY][xLAYER]. If W (resp H) is 0, the max width (resp height) of the tracks in the file is used
  • rescale (int) โ€” S โ€” force media timescale to TS (int or fraction) and change the media duration
  • sampdur (int) โ€” S โ€” force all samples duration (D) or sample durations and media timescale (D/TS), used to patch CFR files with broken timings
  • timescale (int) โ€” S โ€” set the imported media timescale to TS
  • moovts (int) โ€” SE โ€” set the movie timescale to TS. A negative value picks the media timescale of the first track imported
  • noedit โ€” XS โ€” do not set an edit list when importing B-frames video tracks
  • rvc (string) โ€” S โ€” set the RVC configuration for the media
  • fmt (string) โ€” override format detection with the given format โ€” this disables data probing and forces the ext option on the source
  • profile (int) โ€” S โ€” override AVC profile. It's an integer value, or one of high444, high, extended, main, baseline
  • level (int) โ€” S โ€” override AVC level; if the value is < 6, it's interpreted as a decimal expression
  • compat (int) โ€” S โ€” force the profile compatibility flags for the H.264 content
  • novpsext โ€” remove VPS extensions from the HEVC VPS
  • keepav1t โ€” keep the AV1 temporal delimiter OBU in samples, might help if the source file had losses
  • dlba (string) โ€” S โ€” force DolbyAtmos mode for EAC3. The value can be:
    • no: disable Atmos signaling
    • auto: use Atmos signaling from the first sample
    • N: force Atmos signaling using compatibility type index N
  • font (string) โ€” specify the font name for text import (default Serif)
  • size (int) โ€” specify the font size for text import (default 18)
  • text_layout (string) โ€” specify the track text layout as WxHxXxY
    • if W (resp H) = 0: the max width (resp height) of the tracks in the file is used
    • if Y=-1: the layout gets moved to the bottom of the track area
    • X and Y can be omitted: :layout=WxH
  • swf-global โ€” all SWF defines are placed in the first scene replace rather than when needed
  • swf-no-ctrl โ€” use a single stream for movie control and dictionary (this disables ActionScript)
  • swf-no-text โ€” remove all SWF text
  • swf-no-font โ€” remove all embedded SWF Fonts (local playback host fonts are used instead)
  • swf-no-line โ€” remove all lines from SWF shapes
  • swf-no-grad โ€” remove all gradients from SWF shapes
  • swf-quad โ€” use quadratic bezier curves instead of cubic ones
  • swf-xlp โ€” support for lines transparency and scalability
  • swf-ic2d โ€” use indexed curve 2D hardcoded proto
  • swf-same-app โ€” appearance nodes are reused
  • swf-flatten (number) โ€” complementary angle below which 2 lines are merged; 0 means no flattening
  • kind (string) โ€” SE โ€” set the kind for the track as schemeURI=value
  • txtflags (int) โ€” set the display flags (hexa number) of the text track. Use txtflags+=FLAGS to add flags and txtflags-=FLAGS to remove flags
  • rate (int) โ€” force average rate and max rate to VAL (in bps) in the btrt box. If it's 0, the btrt box gets removed
  • stz2 โ€” S โ€” use a compact size table (for low-bitrates)
  • bitdepth (int) โ€” set bit depth to VAL for imported video content (default is 24)
  • colr (string) โ€” S: set the color profile for your imported video content, bestie. The value has to be formatted like one of these:
    • nclc,p,t,m: where p is colour primary (int or string), t is transfer characteristics (int or string) and m is matrix coef (int or string), cf -h cicp
    • nclx,p,t,m,r: same as nclx with r full range flag (yes, on or no, off)
    • prof,path: where path is the file containing the ICC color profile
    • rICC,path: where path is the file containing the restricted ICC color profile
    • 'none': removes color info
  • hdr (string) โ€” S: set HDR info on a track (see .I -hdr), and 'none' removes HDR info โœจ
  • dvp, -dv-profile (string) โ€” S: set the Dolby Vision profile on your imported track. The deets:
    • Profile is an integer, or none to remove DV signaling
    • Profile can be suffixed with a compatibility ID, e.g. 5.hdr10
    • Allowed compatibility ID are none, hdr10, bt709, hlg709, hlg2100, bt2020, brd, or an integer value as per DV spec
    • Profile can be prefixed with f to force DV codec type signaling, e.g. f8.2
  • fullrange (string) โ€” S: force the video fullrange type in VUI for the AVC|H264 content (value yes, on or no, off)
  • videofmt (string) โ€” S: force the video format in VUI for AVC|H264 and HEVC content, value can be component, pal, ntsc, secam, mac, undef
  • colorprim (string) โ€” S: force the colour primaries in VUI for AVC|H264 and HEVC (int or string, cf -h cicp)
  • colortfc (string) โ€” S: force transfer characteristics in VUI for AVC|H264 and HEVC (int or string, cf -h cicp)
  • colormx (string) โ€” S: force the matrix coefficients in VUI for the AVC|H264 and HEVC content (int or string, cf -h cicp)
  • tc (string) โ€” SE: inject a single QT timecode. Value is formatted as:
    • [d]FPS[/FPS_den],h,m,s,f[,framespertick]: optional drop flag, framerate (integer or fractional), hours, minutes, seconds and frame number
    • d is an optional flag used to indicate that the counter is in drop-frame format
    • the framespertick is optional and defaults to round(framerate); it indicates the number of frames per counter tick
  • edits (string) โ€” SE: override edit list, same syntax as .I -edits
  • lastsampdur (string) โ€” S: set the duration of the last sample. Value is formatted as:
    • no value: use the previous sample duration
    • integer: indicate the duration in milliseconds
    • N/D: indicate the duration as fractional second
  • ID (int) โ€” SE: set target ID
    • a value of 0 (default) will try to keep source track ID
    • a value of -1 will ignore source track ID
    • other value will try to set track ID to this value if no other track with same ID is present
  • tkgp (string) โ€” SE: assign a track group to a track. Value is formatted as TYPE,N with TYPE the track group type (4CC) and N the track group ID. A negative ID removes from track group ID -N
  • tkidx (string) โ€” SE: set track position in track list, 1 being first track in file
  • extk โ€” CE: add track as external track
  • times (string) โ€” SE: modify timestamps using the timestamp file specified in value. Timestamp file is formatted as:
    • a line starting with # is a comment, in which timescale=V can be used to set timescale (1000 by default)
    • empty lines are ignored
    • one line per sample in decode order, formated as cts or dts cts
  • stats, -fstat โ€” C: print filter session stats after import
  • graph, -fgraph โ€” C: print filter session graph after import
  • sopt:[OPTS] โ€” set OPTS as additional arguments to the source filter. OPTS can be any usual filter argument, see filter doc gpac -h doc
  • dopt:[OPTS] โ€” X: set OPTS as additional arguments to the destination filter. OPTS can be any usual filter argument, see filter doc gpac -h doc
  • @f1[:args][@fN:args] โ€” set a filter chain to insert before the multiplexer. Each filter in the chain is formatted as a regular filter, see filter doc gpac -h doc. A @@ separator starts a new chain (see DASH help). The last filter in each chain shall not have any ID specified
Note, bestie: sopt, dopt and @f must be placed after all other options. No sneaking them in the middle ๐Ÿ’…

๐ŸŒˆ Global import options ๐ŸŒˆ

  • -add (string) โ€” add the given file's tracks to the file. Multiple inputs can be specified using +, e.g. -add url1+url2
  • -cat (string) โ€” concatenate the given file's samples to the file, creating tracks if needed. Multiple inputs can be specified using +, e.g. -cat url1+url2.
Note: This aligns the initial timestamp of the file to be concatenated
  • -catx (string) โ€” same as .I cat but new tracks can be imported before concatenation by specifying +ADD_COMMAND where ADD_COMMAND is a regular .I add syntax
  • -catpl (string) โ€” concatenate files listed in the given playlist file (one file per line, lines starting with # are comments).
Note: Each listed file is concatenated as if called with -cat
  • -unalign-cat โ€” do not attempt to align timestamps of samples in-between tracks
  • -force-cat โ€” skip the media configuration check when concatenating a file.
Warning: THIS MAY BREAK THE CONCATENATED TRACK(S) ๐Ÿ˜ญ do not say I didn't warn you
  • -keep-sys โ€” keep all MPEG-4 Systems info when using .I add and .I cat (only used when adding IsoMedia files)
  • -dref โ€” keep media data in the original file using data referencing. The resulting file only contains the meta-data of the presentation (frame sizes, timing, etc...) and references media data in the original file. This is extremely useful when developing content, since importing and storage of the MP4 file is much faster and the resulting file much smaller.
Note: Data referencing may fail on some files because it requires the framed data (e.g. an IsoMedia sample) to be continuous in the original file, which is not always the case depending on the original interleaving or bitstream format (AVC or HEVC cannot use this option)
  • -no-drop, -nodrop โ€” force constant FPS when importing AVI video
  • -packed โ€” force packed bitstream when importing raw MPEG-4 part 2 Advanced Simple Profile
  • -sbr โ€” backward compatible signaling of AAC-SBR
  • -sbrx โ€” non-backward compatible signaling of AAC-SBR
  • -ps โ€” backward compatible signaling of AAC-PS
  • -psx โ€” non-backward compatible signaling of AAC-PS
  • -ovsbr โ€” oversample SBR import (SBR AAC, PS AAC and oversampled SBR cannot be detected at import time)
  • -fps (string) โ€” force frame rate for video and SUB subtitles import to the given value, expressed as a number, as TS-inc or TS/inc.
Note: For raw H263 import, default FPS is 15, otherwise 25. This is accepted for ISOBMFF import but :rescale option should be preferred
  • -mpeg4 โ€” force MPEG-4 sample descriptions when possible. For AAC, forces MPEG-4 AAC signaling even if MPEG-2
  • -agg (int) โ€” aggregate N audio frames in 1 sample (3GP media only, maximum value is 15)

๐Ÿ‘‘ Hinting Options ๐Ÿ‘‘

So like, IsoMedia hinting consists in creating special tracks in the file that contain transport protocol specific information and optionally multiplexing information. These tracks are then used by the server to create the actual packets being sent over the network โ€” in other words they provide the server with hints on how to build packets, hence their names hint tracks ๐ŸŽ€

MP4Box supports creation of hint tracks for RTSP servers supporting these such as QuickTime Streaming Server, DarwinStreaming Server or 3GPP-compliant RTSP servers. Iconic behaviour, honestly.

Note: GPAC streaming tools rtp output and rtsp server do not use hint tracks, they use on-the-fly packetization from any media sources, not just MP4

โœจ Options: โœจ

  • -hint โ€” hint the file for RTP/RTSP
  • -mtu (int, default: 1450) โ€” specify RTP MTU (max size) in bytes (this includes 12 bytes RTP header)
  • -copy โ€” copy media data to hint track rather than reference (speeds up server but takes much more space)
  • -multi [maxptime] โ€” enable frame concatenation in RTP packets if possible (with max duration 100 ms or maxptime ms if given)
  • -rate (int, default: 90000) โ€” specify rtp rate in Hz when no default for payload
  • -mpeg4 โ€” force MPEG-4 generic payload whenever possible
  • -latm โ€” force MPG4-LATM transport for AAC streams
  • -static โ€” enable static RTP payload IDs whenever possible (by default, dynamic payloads are always used)
  • -add-sdp (string) โ€” add the given SDP string to movie (string) or track (tkID:string), tkID being the track ID or the hint track ID
  • -no-offset โ€” signal no random offset for sequence number and timestamp (support will depend on server)
  • -unhint โ€” remove all hinting information from file
  • -group-single โ€” put all tracks in a single hint group
  • -ocr โ€” force all MPEG-4 streams to be synchronized (MPEG-4 Systems only)
  • -rap โ€” signal random access points in RTP packets (MPEG-4 Systems)
  • -ts โ€” signal AU Time Stamps in RTP packets (MPEG-4 Systems)
  • -size โ€” signal AU size in RTP packets (MPEG-4 Systems)
  • -idx โ€” signal AU sequence numbers in RTP packets (MPEG-4 Systems)
  • -iod โ€” prevent systems tracks embedding in IOD (MPEG-4 Systems), not compatible with .I -isma

๐ŸŽฌ MPEG-4 Scene Encoding Options

โœจ General considerations โœจ

okay so here's the tea, bestie: MP4Box does encoding and decoding of BT, XMT, VRML and (partially) X3D formats into MPEG-4 BIFS, plus encoding and decoding of XSR and SVG into MPEG-4 LASeR. it's giving versatile ๐Ÿ’…

Any media track you specify through a MuxInfo element gets imported into the resulting MP4 file. automatic. no cap.

want the full lore? go read https://wiki.gpac.io/Howtos/scenecoding/MPEG-4-BIFS-Textual-Format and the related pages ๐Ÿฆ‹

๐ŸŽ  Scene Random Access ๐ŸŽ 

MP4Box can encode BIFS or LASeR streams and insert random access points at a given frequency. this is SO useful when you're packaging content for broadcast, because users will not turn in the scene at the same time (rude of them, honestly). in MPEG-4 terminology this is called the scene carousel. iconic behavior.

๐Ÿงฉ BIFS Chunk Processing ๐Ÿงฉ

The BIFS chunk encoding mode allows encoding single BIFS access units from an initial context and a set of commands. very demure, very mindful.

The generated AUs are raw BIFS (not SL-packetized), in files called FILE-ESID-AUIDX.bifs, with FILE the basename of the input file.

Commands with a timing of 0 in the input will modify the carousel version only (i.e. output context). Commands with a timing different from 0 in the input will generate new AUs. periodt.

Options:

  • -mp4 โ€” specify input file is for BIFS/LASeR encoding
  • -def โ€” encode DEF names in BIFS
  • -sync (int) โ€” force BIFS sync sample generation every given time in ms (cannot be used with shadow or carousel)
  • -shadow (int) โ€” force BIFS sync shadow sample generation every given time in ms (cannot be used with sync or carousel)
  • -carousel (int) โ€” use BIFS carousel (cannot be used with sync or shadow)
  • -sclog โ€” generate scene codec log file if available
  • -ms (string) โ€” import tracks from the given file
  • -ctx-in (string) โ€” specify initial context (MP4/BT/XMT) file for chunk processing. Input file must be a commands-only file
  • -ctx-out (string) โ€” specify storage of updated context (MP4/BT/XMT) file for chunk processing, optional
  • -resolution (int) โ€” resolution factor (-8 to 7, default 0) for LASeR encoding, and all coordinates are multiplied by 2^res before truncation (LASeR encoding)
  • -coord-bits (int) โ€” number of bits used for encoding truncated coordinates (0 to 31, default 12) (LASeR encoding)
  • -scale-bits (int) โ€” extra bits used for encoding truncated scales (0 to 4, default 0) (LASeR encoding)
  • -auto-quant (int) โ€” resolution is given as if using resolution but coord-bits and scale-bits are inferred (LASeR encoding)
  • -global-quant (int) โ€” resolution is given as if using resolution but the res is inferred (BIFS encoding)

๐Ÿ” Encryption/Decryption Options ๐Ÿ”

MP4Box supports encryption and decryption of ISMA, OMA and CENC content, see encryption filter gpac -h cecrypt. ๐Ÿ‘‘

It requires a specific XML file called CryptFile, whose syntax is available at https://wiki.gpac.io/xmlformats/Common-Encryption

Image files (HEIF) can also be crypted / decrypted, using CENC only.

Options:

  • -crypt (string) โ€” encrypt the input file using the given CryptFile
  • -decrypt (string) โ€” decrypt the input file, potentially using the given CryptFile. If CryptFile is not given, will fail if the key management system is not supported
  • -set-kms tkID=kms_uri โ€” change ISMA/OMA KMS location for a given track or for all tracks if all= is used

๐Ÿ–ผ๏ธ Meta and HEIF Options ๐Ÿ–ผ๏ธ

IsoMedia files can be used as generic meta-data containers โ€” for example, storing XML information and sample images for a movie. The resulting file may not always contain a movie, as is the case with some HEIF files or MPEG-21 files. ngl that's a whole vibe shift and it's valid.

These information can be stored at the file root level (as is the case for HEIF/IFF and MPEG-21 file formats), or at the movie or track level for a regular movie.

  • -set-meta ABCD[:tk=tkID] โ€” set meta box type, with ABCD the four char meta type (NULL or 0 to remove meta)
    • tk not set: use root (file) meta
    • tkID == 0: use moov meta
    • tkID != 0: use meta of given track
  • -add-item (string) โ€” add resource to meta, with parameter syntax file_path[:opt1:optN]
    • file_path this or self: item is the file itself
    • tk=tkID: meta location (file, moov, track)
    • name=str: item name, none if not set
    • type=itype: item 4cc type (not needed if mime is provided)
    • mime=mtype: item mime type, none if not set
    • encoding=enctype: item content-encoding type, none if not set
    • id=ID: item ID (strictly positive integer)
    • ref=4cc,id: reference of type 4cc (such as 'dimg', 'auxl', 'cdsc') to an other item (can be set multiple times)
    • group=4cc,id: indicate the type 4cc (such as 'altr') and id of an entity group this item belongs to
    • replace: replace existing item by new item
  • -add-image (string) โ€” add the given file as HEIF image item, with parameter syntax file_path[:opt1:optN]. If filepath is omitted, source is the input MP4 file
    • name, id, ref, group: see add-item
    • primary: indicate that this item should be the primary item
    • time=t[-e][/i]: use the next sync sample after time t (float, in sec, default 0). A negative time imports ALL intra frames as items
      • If e is set (float, in sec), import all sync samples between t and e
      • If i is set (float, in sec), sets time increment between samples to import
    • split_tiles: for an HEVC tiled image, each tile is stored as a separate item
    • image-size=wxh: force setting the image size and ignoring the bitstream info, used for grid, overlay and identity derived images also
    • rotation=a: set the rotation angle for this image to 90*a degrees anti-clockwise
    • mirror-axis=axis: set the mirror axis: vertical, horizontal
    • clap=Wn,Wd,Hn,Hd,HOn,HOd,VOn,VOd: see track clap
    • image-pasp=axb: force the aspect ratio of the image
    • image-pixi=(a|a,b,c): force the bit depth (1 or 3 channels)
    • hidden: indicate that this image item should be hidden
    • icc_path: path to icc data to add as color info
    • alpha: indicate that the image is an alpha image (should use ref=auxl also)
    • depth: indicate that the image is a depth image (should use ref=auxl also)
    • it=ID: indicate the item ID of the source item to import
    • itp=ID: same as it= but copy over all properties of the source item
    • tk=tkID: indicate the track ID of the source sample. If 0, uses the first video track in the file
    • samp=N: indicate the sample number of the source sample
    • ref: do not copy the data but refer to the final sample/item location, ignored if filepath is set
    • agrid[=AR]: creates an automatic grid from the image items present in the file, in their declaration order. The grid will try to have AR aspect ratio if specified (float), or the aspect ratio of the source otherwise. The grid will be the primary item and all other images will be hidden
    • av1_op_index: select the AV1 operating point to use via a1op box
    • replace: replace existing image by new image, keeping props listed in keep_props
    • keep_props=4CCs: coma-separated list of properties types to keep when replacing the image, e.g. keep_props=auxC
    • auxt=URN: mark image as auxiliary using given URN
    • auxd=FILE: use data from FILE as auxiliary extensions (cf auxC box)
    • any other options will be passed as options to the media importer, see -add
  • -add-derived-image (string) โ€” create an image grid, overlay or identity item, with parameter syntax :type=(grid|iovl|iden)[:opt1:optN]
    • image-grid-size=rxc: set the number of rows and columns of the grid
    • image-overlay-offsets=h,v[,h,v]*: set the horizontal and vertical offsets of the images in the overlay
    • image-overlay-color=r,g,b,a: set the canvas color of the overlay [0-65535]
    • any other options from add-image can be used
  • -rem-item,-rem-image item_ID[:tk=tkID] โ€” remove resource from meta
  • -set-primary item_ID[:tk=tkID] โ€” set item as primary for meta
  • -set-xml xml_file_path[:tk=tkID][:binary] โ€” set meta XML data
  • -rem-xml [tk=tkID] โ€” remove meta XML data
  • -dump-xml file_path[:tk=tkID] โ€” dump meta XML to file
  • -dump-item item_ID[:tk=tkID][:path=fileName] โ€” dump item to file
  • -package (string) โ€” package input XML file into an ISO container, all media referenced except hyperlinks are added to file
  • -mgt (string) โ€” package input XML file into an MPEG-U widget with ISO container, all files contained in the current folder are added to the widget package

๐Ÿงš SWF Importer Options ๐Ÿงš

MP4Box can import simple Macromedia Flash files (".SWF") ๐Ÿซถ throwback era fr fr.

You can specify a SWF input file with '-bt', '-xmt' and '-mp4' options

Options:

  • -global โ€” all SWF defines are placed in first scene replace rather than when needed
  • -no-ctrl โ€” use a single stream for movie control and dictionary (this will disable ActionScript)
  • -no-text โ€” remove all SWF text
  • -no-font โ€” remove all embedded SWF Fonts (local playback host fonts used)
  • -no-line โ€” remove all lines from SWF shapes
  • -no-grad โ€” remove all gradients from swf shapes
  • -quad โ€” use quadratic bezier curves instead of cubic ones
  • -xlp โ€” support for lines transparency and scalability
  • -ic2d โ€” use indexed curve 2D hardcoded proto
  • -same-app โ€” appearance nodes are reused
  • -flatten (number) โ€” complementary angle below which 2 lines are merged, value 0 means no flattening

๐Ÿท๏ธ Tagging support ๐Ÿท๏ธ

Tags get written as a colon-separated list, bestie, like this:

tag_name=tag_value[:tag2=val2]
  • Setting a tag with no value, or a value of NULL, removes the tag.
  • The special tag value clear (or reset) removes all the tags. poof ๐Ÿ’จ
  • The special tag value cust means it's a custom domain tag โ€” and in that case the tag value must start with DOMAIN,MEAN,.

Example

-itags cust='com.apple.iTunes,iTunEXTC,My Tag Value'

The DOMAIN and/or NAME strings can be empty, no stress. Unsupported tags? You can add them using their four character code as the tag name, and the value will be assumed to be a string. And if your tag name is only 3 characters long, the prefix 0xA9 gets used to build the four character code. cute ๐ŸŽ€

You can also load tags from a text file with -itags filename. That file has to be in UTF8 and follow this vibe:

  • lines starting with tag_name=value kick off a new tag
  • every other line is the continuation of the last declared tag

If the tag name starts with WM/, the tag goes into the Xtra box (that's a WMA tag, string only).

๐Ÿ”‘ QT metadata key ๐Ÿ”‘

The tag gets added as a QT metadata key if:

  • tag_name starts with QT/
  • or tag_name isn't recognized and is longer than 4 characters

Your tag_name can optionally be prefixed with HDLR@, which sets the tag namespace 4CC โ€” and the default namespace is mdta.

And the tag_value can be prefixed with:

  • S: force string encoding (this one has to go first) instead of parsing the tag value
  • b: use 8-bit encoding for signed or unsigned int
  • s: use 16-bit encoding for signed or unsigned int
  • l: use 32-bit encoding for signed or unsigned int
  • L: use 64-bit encoding for signed or unsigned int
  • f: force float encoding for numbers

Numbers get converted by default and stored in variable-size mode. And if you wanna force a positive integer into signed storage, just slap a + in front of the number. periodt ๐Ÿ’…

Example

-tags io.gpac.some_tag=s+32

This forces storing the value 32 in signed 16 bit format. slay.

The tag_value can also be formatted as:

  • XxY@WxH: a rectangle type
  • XxY: a point type
  • W@H: a size type
  • A,B,C,D,E,F,G,H,I: a 3x3 matrix
  • FNAME: data is loaded from FNAME, type set to jpeg or png if needed

โœจ Supported tag names (name, value, type, aliases) โœจ

  • title (ยฉnam) โ€” string (alias name)
  • artist (ยฉART) โ€” string
  • album_artist (aART) โ€” string (alias albumArtist)
  • album (ยฉalb) โ€” string
  • group (ยฉgrp) โ€” string (alias grouping)
  • composer (ยฉcom) โ€” string
  • writer (ยฉwrt) โ€” string
  • conductor (ยฉcon) โ€” string
  • comment (ยฉcmt) โ€” string (alias comments)
  • genre (gnre) โ€” string (ID3 genre tag)
  • created (ยฉday) โ€” string (alias releaseDate)
  • track (ยฉtrk) โ€” string
  • tracknum (trkn) โ€” fraction (syntax: A/B or A, B will be 0)
  • disk (disk) โ€” fraction (syntax: A/B or A, B will be 0)
  • tempo (tmpo) โ€” integer
  • compilation (cpil) โ€” bool (yes or no)
  • show (tvsh) โ€” string (alias tvShow)
  • episode_id (tven) โ€” string (alias tvEpisodeID)
  • season (tvsn) โ€” integer (alias tvSeason)
  • episode (tves) โ€” integer (alias tvEPisode)
  • network (tvnn) โ€” string (alias tvNetwork)
  • sdesc (desc) โ€” string (alias description)
  • ldesc (ldes) โ€” string (alias longDescription)
  • lyrics (ยฉlyr) โ€” string
  • sort_name (sonm) โ€” string (alias sortName)
  • sort_artist (soar) โ€” string (alias sortArtist)
  • sort_album_artist (soaa) โ€” string (alias sortAlbumArtist)
  • sort_album (soal) โ€” string (alias sortAlbum)
  • sort_composer (soco) โ€” string (alias sortComposer)
  • sort_show (sosn) โ€” string (alias sortShow)
  • cover (covr) โ€” file path (alias artwork)
  • copyright (cprt) โ€” string
  • tool (ยฉtoo) โ€” string (alias encodingTool)
  • encoder (ยฉenc) โ€” string (alias encodedBy)
  • pdate (purd) โ€” string (alias purchaseDate)
  • podcast (pcst) โ€” bool (yes or no)
  • url (purl) โ€” string (alias podcastURL)
  • keywords (kyyw) โ€” string
  • category (catg) โ€” string
  • hdvideo (hdvd) โ€” integer
  • media (stik) โ€” integer (alias mediaType)
  • rating (rtng) โ€” integer (alias contentRating)
  • gapless (pgap) โ€” bool (yes or no)
  • art_director (ยฉard) โ€” string
  • arranger (ยฉarg) โ€” string
  • lyricist (ยฉaut) โ€” string
  • acknowledgement (ยฉcak) โ€” string
  • song_description (ยฉdes) โ€” string
  • director (ยฉdir) โ€” string
  • equalizer (ยฉequ) โ€” string
  • liner (ยฉlnt) โ€” string
  • record_company (ยฉmak) โ€” string
  • original_artist (ยฉope) โ€” string
  • phono_rights (ยฉphg) โ€” string
  • producer (ยฉprd) โ€” string
  • performer (ยฉprf) โ€” string
  • publisher (ยฉpub) โ€” string
  • sound_engineer (ยฉsne) โ€” string
  • soloist (ยฉsol) โ€” string
  • credits (ยฉsrc) โ€” string
  • thanks (ยฉthx) โ€” string
  • online_info (ยฉurl) โ€” string
  • exec_producer (ยฉxpd) โ€” string
  • genre (ยฉgen) โ€” string (ID3 genre tag)
  • location (ยฉxyz) โ€” string

๐ŸŽฌ Live Scene Encoder Options ๐ŸŽฌ

These options get specified as opt_name=opt_val. Here's the menu, bestie:

  • -live โ€” enable live BIFS/LASeR encoder
  • -dst (string) โ€” destination IP
  • -port (int, default: 7000) โ€” destination port
  • -mtu (int, default: 1450) โ€” path MTU for RTP packets
  • -ifce (string) โ€” IP address of the physical interface to use
  • -ttl (int, default: 1) โ€” time to live for multicast packets
  • -sdp (string, default: session.sdp) โ€” output SDP file
  • -dims โ€” turn on DIMS mode for SVG input
  • -no-rap โ€” disable RAP sending and carousel generation
  • -src (string) โ€” source of scene updates
  • -rap (int) โ€” duration in ms of base carousel; you can specify the RAP period of a single ESID (not in DIMS) using ESID=X:time

Runtime options, aka the lil keyboard shortcuts ๐Ÿซถ:

  • q: quits
  • u: inputs some commands to be sent
  • U: same as u but signals the updates as critical
  • e: inputs some commands to be sent without being aggregated
  • E: same as e but signals the updates as critical
  • f: forces RAP sending
  • F: forces RAP regeneration and sending
  • p: dumps current scene

๐ŸŒธ EXAMPLES ๐ŸŒธ

Basic and advanced examples are available at https://wiki.gpac.io/MP4Box/MP4Box โ€” go look, it's giving tutorial energy ๐Ÿ’–


๐Ÿ’œ MORE ๐Ÿ’œ

Authors: GPAC developers, see git repo history (-log)

For bug reports, feature requests, more information and source code, visit https://github.com/gpac/gpac

build: 26.02

Copyright: (c) 2000-2024 Telecom Paris distributed under LGPL v2.1+ - https://gpac.io


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€


okay bestie that's literally the whole page, you ate it up ๐Ÿ’…โœจ This was the MP4Box(1) manpage โ€” source/version MP4Box, dated 2019. no cap, go tag some files ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from