FFmpeg Segment Naming and CSV List Generation
This guide explains how to split video files into smaller segments using FFmpeg, customize the resulting filenames using specific naming patterns, and automatically generate a CSV list of all created segment files. By utilizing FFmpeg’s built-in segment muxer, you can easily automate video splitting and maintain a structured index of your output files for post-processing or distribution.
Configuring Segment Naming Patterns
To split a video into segments, use FFmpeg’s segment
muxer (-f segment). You can control the filenames of the
generated segments by using C-style printf format templates or
date-and-time variables.
1. Sequential Numbering
The most common naming pattern uses %d (or
%0Nd for zero-padded numbers) to number segments
sequentially.
ffmpeg -i input.mp4 -f segment -segment_time 10 -reset_timestamps 1 output_%03d.mp4In this command: * -segment_time 10 splits the video
every 10 seconds. * -reset_timestamps 1 resets the
timestamps at the beginning of each segment. *
output_%03d.mp4 creates sequential files named
output_000.mp4, output_001.mp4,
output_002.mp4, and so on.
2. Timestamp-Based Naming
If you want the filenames to represent the actual date and time of
creation, enable the -strftime option.
ffmpeg -i input.mp4 -f segment -segment_time 10 -strftime 1 -reset_timestamps 1 "output_%Y-%m-%d_%H-%M-%S.mp4"This will name the files based on the system time when the segment
was written (e.g., output_2023-10-27_14-30-00.mp4).
Generating a CSV List of Created Files
FFmpeg can automatically generate a list of all created segment files
using the -segment_list and -segment_list_type
options.
To generate a standard CSV file listing the output segments, add these options to your command:
ffmpeg -i input.mp4 -f segment -segment_time 10 -segment_list segment_list.csv -segment_list_type csv -reset_timestamps 1 output_%03d.mp4Explanation of List Options:
-segment_list segment_list.csv: Specifies the filename and path for the generated list.-segment_list_type csv: Forces FFmpeg to format the list as a CSV file.
The generated segment_list.csv file will contain a
structured table in the following format, including the file name,
segment start time, and segment end time:
output_000.mp4,0.000000,10.000000
output_001.mp4,10.000000,20.000000
output_002.mp4,20.000000,30.000000
This CSV file can be directly imported into database systems, Excel, or custom scripts for further processing.