Configure DASH Segment Duration and Manifest Name in FFmpeg
This article provides a quick guide on how to customize the segment duration and manifest file name when packaging video content using the FFmpeg MPEG-DASH muxer. By configuring these settings, you can optimize streaming latency, compatibility, and file organization for your media delivery pipeline.
To configure DASH output in FFmpeg, you must use the DASH muxer by
specifying -f dash. Controlling the segment duration and
manifest name involves utilizing specific muxer private options.
Setting the Segment Duration
To define the length of each media segment, use the
-seg_duration option. This option accepts a value in
seconds (which can be a decimal).
For example, to set a segment duration of 4 seconds, add the following to your command:
-seg_duration 4By default, FFmpeg will attempt to cut segments at the nearest
keyframe (I-frame) close to this duration. To ensure precise segment
lengths, you should force keyframe intervals (GOP size) in your video
encoder settings to align with your target segment duration. For
example, if your video is 30 frames per second (fps) and you want
4-second segments, set the GOP size to 120 using
-g 120 -keyint_min 120 -sc_threshold 0.
Setting the Manifest Name
The name of the main DASH manifest file (the .mpd file)
is determined by the output file path specified at the very end of your
FFmpeg command.
For example, to name your manifest live_stream.mpd,
specify it as the output target:
live_stream.mpdCustomizing Segment File Names
In addition to the manifest name, you can customize how the
individual initialization and media segment files are named using the
-init_seg_name and -media_seg_name
options:
-init_seg_name: Sets the template for the initialization segments (default isinit-stream$RepresentationID$.m4s).-media_seg_name: Sets the template for the media segments (default ischunk-stream$RepresentationID$-$Number%05d$.m4s).
Complete Command Example
Below is a complete FFmpeg command that transcodes an input video,
sets the segment duration to 6 seconds, names the manifest
custom_manifest.mpd, and customizes the segment file
names:
ffmpeg -i input.mp4 \
-c:v libx264 -g 180 -keyint_min 180 -sc_threshold 0 \
-c:a aac \
-f dash \
-seg_duration 6 \
-init_seg_name 'init_$RepresentationID$.m4s' \
-media_seg_name 'chunk_$RepresentationID$_$Number$.m4s' \
custom_manifest.mpdIn this command: * -g 180 forces a keyframe every 180
frames (which equals 6 seconds of video at 30 fps), aligning perfectly
with the segment duration. * -f dash selects the DASH
muxer. * -seg_duration 6 instructs FFmpeg to split the
streams into 6-second chunks. * custom_manifest.mpd is the
output parameter that defines the name of the generated manifest.