Concatenate Videos with Different Sample Rates in FFmpeg
To concatenate two videos with different audio sample rates in
FFmpeg, you cannot use the basic “demuxer” concat method, as it requires
identical stream properties. Instead, you must re-encode the files using
FFmpeg’s filter_complex tool. This process resamples the
audio tracks to a matching frequency (such as 48,000 Hz) and
standardizes the video streams before merging them into a single,
seamless output file.
The FFmpeg Command
If your video dimensions match but the audio sample rates differ, use the following command to resample the audio to 48 kHz (48000 Hz) and concatenate the files:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:a]aresample=48000[a0]; \
[1:a]aresample=48000[a1]; \
[0:v][a0][1:v][a1]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" output.mp4How the Command Works
-i input1.mp4 -i input2.mp4: Defines the two input video files.[0:a]aresample=48000[a0]: Takes the audio stream of the first input (0:a), resamples it to 48,000 Hz, and labels the temporary output stream as[a0].[1:a]aresample=48000[a1]: Takes the audio stream of the second input (1:a), resamples it to 48,000 Hz, and labels it as[a1].concat=n=2:v=1:a=1[v][a]: Concatenates the streams. It takes the video from the first file[0:v], the resampled audio[a0], the video from the second file[1:v], and the resampled audio[a1].n=2tells FFmpeg there are two segments,v=1outputs one video stream, anda=1outputs one audio stream.-map "[v]" -map "[a]": Instructs FFmpeg to use the newly created concatenated video ([v]) and audio ([a]) streams for the final output file.
Handling Different Resolutions and Sample Rates
If your videos also have different resolutions or aspect ratios in addition to different sample rates, you must scale the video streams alongside resampling the audio to prevent playback errors. Use this expanded command:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]scale=1920:1080,setsar=1[v0]; \
[0:a]aresample=48000[a0]; \
[1:v]scale=1920:1080,setsar=1[v1]; \
[1:a]aresample=48000[a1]; \
[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" output.mp4This version forces both video streams to a standard 1080p resolution
(1920:1080) and sets a 1:1 Sample Aspect Ratio
(setsar=1), guaranteeing a smooth transition between the
two clips.