How to Configure FFmpeg Concat Demuxer Text File

This article provides a straightforward guide on how to create and configure the input text file required by the FFmpeg concat demuxer to merge multiple video or audio files seamlessly. You will learn the exact syntax rules, file path formatting, and the terminal command needed to concatenate your media files quickly without re-encoding.

Step 1: Create the Text File

To use the concat demuxer, you must list your input files in a plain text file (commonly named inputs.txt or filelist.txt).

Every media file you want to join must be specified on a new line using the file keyword, followed by the path to the file enclosed in single quotes.

Here is the standard format for the text file:

# This is a comment
file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'

Path Formatting Rules

  • Single Quotes: Always wrap the file path in single quotes ('path'). This prevents errors if your file names contain spaces or special characters.
  • Escaping Characters: If a filename contains a single quote, you must escape it. For example, for a file named video's.mp4, write it as: file 'video\'s.mp4'.
  • Relative vs. Absolute Paths: By default, FFmpeg expects relative paths to the files from the directory where the text file is located. If you want to use absolute paths (e.g., file '/Users/username/videos/video1.mp4'), you must explicitly tell FFmpeg to allow them using a specific command-line flag.

Step 2: Run the FFmpeg Command

Once your text file is saved, open your terminal or command prompt in the directory containing your text file and media files, then run the following command:

ffmpeg -f concat -safe 0 -i inputs.txt -c copy output.mp4

Command Flags Explained

  • -f concat: Forces FFmpeg to use the concat demuxer.
  • -safe 0: Disables file path safety checks. This flag is highly recommended because it allows the use of absolute paths, relative paths that go up directories (like ../video.mp4), and complex file names. Without -safe 0, FFmpeg will often reject valid files.
  • -i inputs.txt: Specifies your configured text file as the input source.
  • -c copy: Copies the audio and video streams directly without re-encoding them. This process is nearly instantaneous and preserves original quality. Note that for -c copy to work seamlessly, all input files should have the same codecs, resolution, and frame rate.