FFmpeg Concat Demuxer Text File Format
This guide explains how to properly format the input text file
required by the FFmpeg concat demuxer to join multiple
video or audio files. You will learn the exact syntax rules, how to
handle file paths, and how to use optional directives like duration and
inpoint to control your media stream.
Basic Syntax Rules
The text file is a simple plain text document (usually named
inputs.txt or filelist.txt) where you list the
media assets you want to concatenate in chronological order.
- The
fileDirective: Every media file must be preceded by the wordfile, followed by a space, and the path to the file enclosed in single quotes. - Comments: Lines starting with
#are ignored and can be used for comments. - Line Breaks: Each instruction must be on its own line.
Here is a basic example of a text file:
# This is a comment listing the videos to merge
file 'input1.mp4'
file 'input2.mp4'
file 'input3.mp4'
Handling Paths and Special Characters
Relative Paths: By default, FFmpeg looks for files relative to the directory where the text file is located.
Absolute Paths: You can use absolute paths (e.g.,
file '/usr/share/videos/input1.mp4'). However, if you use absolute paths or paths that go up parent directories (using../), you must include the-safe 0flag in your FFmpeg command.Escaping Characters: If your file names contain single quotes, spaces, or special characters, escape the single quote with a backslash and a single quote
'\''or enclose the string carefully. For example, for a file namedvideo's.mp4:file 'video'\''s.mp4'
Advanced Directives (Optional)
You can add extra parameters below each file line to fine-tune how FFmpeg processes the stream.
duration: Specifies the duration of the clip in seconds. This is particularly useful when concatenating still images.inpoint: Defines the start time of the segment (in seconds).outpoint: Defines the end time of the segment (in seconds).
Example using advanced parameters:
file 'video1.mp4'
inpoint 5.0
outpoint 15.5
file 'video2.mp4'
inpoint 0.0
outpoint 10.0
How to Run the FFmpeg Command
Once your text file is saved (for example, as list.txt),
run the following command in your terminal to concatenate the files
without re-encoding:
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4-f concat: Specifies the concat demuxer.-safe 0: Allows the use of absolute paths and unconventional file names.-i list.txt: Points to your formatted text file.-c copy: Copies the video and audio streams without re-encoding them, making the process extremely fast.