FFmpeg Concat Files with Different Sample Rates

This article explains how to merge audio or video files with different sample rates using FFmpeg’s concat filter. Because the concat filter requires all input streams to have identical parameters, attempting to merge files with mismatching sample rates directly will result in errors or corrupted playback. To resolve this, you must use the aresample filter to normalize the sample rates of all inputs within a filtergraph before concatenating them.

The Problem with Direct Concatenation

When using the FFmpeg concat demuxer or the concat filter, the inputs must share the same codec parameters, including channel layout and sample rate. If you try to merge a file with a 44,100 Hz sample rate with one that has a 48,000 Hz sample rate, FFmpeg will likely throw an error or output a file with distorted, sped-up, or slowed-down audio.

To bypass this limitation, you must resample the audio streams to a common sample rate before passing them to the concat filter.

How to Resample and Concatenate Using Filter Complex

The most efficient way to handle this on the fly is by using -filter_complex. This allows you to chain the aresample filter to each input stream, normalizing them to a target sample rate (such as 48,000 Hz) before piping them into the concat filter.

Here is the template command to merge two audio files with different sample rates:

ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex \
"[0:a]aresample=48000[a1]; \
 [1:a]aresample=48000[a2]; \
 [a1][a2]concat=n=2:v=0:a=1[outa]" \
-map "[outa]" output.mp3

Command Breakdown:

Concatenating Video Files with Different Audio Sample Rates

If you are merging video files that contain audio with different sample rates, you must resample the audio while passing the video streams straight to the concat filter.

Use the following command for video files:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:a]aresample=48000[a1]; \
 [1:a]aresample=48000[a2]; \
 [0:v][a1][1:v][a2]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4

Command Breakdown for Video: