How to Set HLS Segment Type to fMP4 in FFmpeg

This article provides a straightforward guide on how to configure FFmpeg to output HTTP Live Streaming (HLS) using fragmented MP4 (fMP4) segments instead of the traditional MPEG-TS format. You will learn the exact command-line options required, understand the key parameters, and see a practical example to implement this in your video streaming workflows.

By default, the FFmpeg HLS muxer outputs segments as MPEG-TS (.ts) files. To switch the segment format to fragmented MP4 (.m4s), you must use the -hls_segment_type option and set its value to fmp4.

The FFmpeg Command

Below is a standard FFmpeg command that converts an input video into an HLS stream with fMP4 segments:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 6 -hls_segment_type fmp4 output.m3u8

Parameter Breakdown

Why Use fMP4 for HLS?

Using fragmented MP4 segments offers several modern advantages over MPEG-TS:

  1. Cross-Platform Compatibility: fMP4 allows you to use the exact same media segments for both HLS (for Apple devices) and MPEG-DASH (for Android and web players), eliminating the need to store duplicate video files.
  2. Lower Storage Costs: Because you only need one set of fMP4 files for multiple streaming protocols, you save significant storage space on your origin servers and Content Delivery Networks (CDNs).
  3. Modern Codec Support: fMP4 is required if you plan to stream newer video codecs like HEVC (H.265) or AV1 over HLS.