Configure FFmpeg HLS Segment Names Using strftime

This article explains how to configure the segment naming format in FFmpeg’s HTTP Live Streaming (HLS) muxer using the strftime library. You will learn how to enable the time-based naming option, understand the common formatting specifiers, and implement a practical command-line example to generate uniquely timestamped video segments.

To use time-based naming for HLS segments in FFmpeg, you must explicitly enable the strftime option and define a naming template using standard time format specifiers in the segment filename option.

Required FFmpeg Flags

To configure this setup, you must use two key parameters in your FFmpeg command:

  1. -strftime 1: This flag enables strftime processing for the segment filenames.
  2. -hls_segment_filename: This flag defines the template for the output segment files, utilizing time-based placeholders.

Configuration Example

Here is a standard FFmpeg command that transcodes an input file into HLS segments named after the current system date and time:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 10 -strftime 1 -hls_segment_filename "file_%Y-%m-%d_%H-%M-%S.ts" playlist.m3u8

Common strftime Format Specifiers

The string provided to -hls_segment_filename can be customized using standard C library strftime specifiers:

Using the command example above, a segment written on October 25, 2023, at 3:45:10 PM will be named: file_2023-10-25_15-45-10.ts

Important Usage Notes