How to Output fMP4 Segments in FFmpeg HLS

This article explains how to configure the FFmpeg HLS (HTTP Live Streaming) muxer to generate fragmented MP4 (fMP4) segments instead of the default MPEG-2 Transport Stream (TS) format. You will learn the specific command-line options required to switch the segment type, define initialization files, and structure a complete FFmpeg command for modern HLS delivery.

By default, FFmpeg’s HLS muxer outputs media segments in the TS format (.ts). To output fragmented MP4 (.m4s) segments, you must use the -hls_segment_type option and set its value to fmp4.

The Core Configuration Option

The primary setting required to switch the muxer to fMP4 is:

-hls_segment_type fmp4

When this option is enabled, FFmpeg will generate an initialization segment (containing the track metadata) and a sequence of media fragment files containing the actual video and audio data.

Essential Parameters for fMP4 HLS

When configuring fMP4 output, you should also define how the initialization file and the individual fragments are named:

Complete Command Example

Below is a complete command that transcodes an input file into HLS-compatible H.264 video and AAC audio, segmenting it into 6-second fMP4 fragments:

ffmpeg -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f hls \
  -hls_time 6 \
  -hls_playlist_type vod \
  -hls_segment_type fmp4 \
  -hls_fmp4_init_filename "init.mp4" \
  -hls_segment_filename "segment_%03d.m4s" \
  playlist.m3u8

Explanation of the Command