How to Concatenate Audio Files Using FFmpeg Concat

This guide provides a straightforward walkthrough on how to join multiple audio files into a single track using the FFmpeg concat demuxer. You will learn how to structure the required input text file, execute the appropriate terminal commands to merge files without re-encoding, and adapt the command if your source files have mismatched audio formats or sample rates.

Step 1: Create the File List

The FFmpeg concat demuxer requires a plain text file listing the audio files you want to join in sequential order.

Create a file named inputs.txt in the directory containing your audio files. Use the following format:

file 'audio1.mp3'
file 'audio2.mp3'
file 'audio3.mp3'

Auto-Generating the List

Instead of typing names manually, you can generate this file using your command line.

On Linux or macOS:

printf "file '%s'\n" *.mp3 > inputs.txt

On Windows (PowerShell):

Get-ChildItem -Filter *.mp3 | ForEach-Object { "file '$($_.Name)'" } | Out-File -Encoding ascii inputs.txt

Note: If you use relative paths with special characters or absolute file paths, always keep the single quotes around the file paths.

Step 2: Run the Concat Demuxer Command

If all your input files share the identical audio codec, sample rate, bit depth, and channel layout, you can concatenate them instantly without re-encoding by copying the stream.

Run the following command:

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

Breakdown of Parameters:

  • -f concat: Directs FFmpeg to use the concatenation demuxer.
  • -safe 0: Allows the use of absolute paths or filenames with spaces and special characters.
  • -i inputs.txt: Specifies your text file containing the list of inputs.
  • -c copy: Copies the audio streams directly without decoding and re-encoding, preserving original quality and finishing almost instantaneously.
  • output.mp3: The destination file for your concatenated audio.

Handling Mismatched Audio Formats

The stream copy method (-c copy) fails or creates corrupted files if the input files differ in encoding parameters (such as different bitrates, sample rates like 44.1 kHz vs 48 kHz, or mono vs stereo).

To merge files with different specifications, remove -c copy so FFmpeg decodes and re-encodes the audio into a uniform stream:

ffmpeg -f concat -safe 0 -i inputs.txt -c:a aac -b:a 192k output.m4a

For standard MP3 output:

ffmpeg -f concat -safe 0 -i inputs.txt -c:a libmp3lame -q:a 2 output.mp3

FFmpeg will process each track, convert them to the matching target specification, and combine them into the final output file seamlessly.