Join videos with FFmpeg without errors
FFmpeg joins videos two ways: the concat demuxer for files that share codec, size and frame rate, and a re-encode for files that do not. This page shows the command for each case, the error messages you will meet and how to check the joined file. Each command is shown with the clip it was run on.
Pick the right method first
FFmpeg has two ways to join files, and picking the wrong one is the main cause of join errors. The concat demuxer joins files without re-encoding, but only when they match. The concat filter re-encodes, and it can fix files that do not match.
| Method | Use it when | Re-encodes? |
|---|---|---|
| Concat demuxer (-f concat) | Every file has the same codec, size, frame rate and audio settings, for example clips cut from one source. | No, fast, no quality loss |
| Concat filter (-filter_complex concat) | Files differ in size, frame rate or audio sample rate, or you want one clean re-encode. | Yes, slower, one generation of quality loss |
Our three test files: a.mp4 is 10 s, 1280x720, 30 fps, 48000 Hz audio. b.mp4 is 6 s with the same settings but a different picture. c.mp4 is 5 s, 640x360, 25 fps, 44100 Hz audio. a.mp4 and b.mp4 match; c.mp4 does not match either. The commands to make them are in Method and limits.
Join files with the same codec and size
Write a text file that lists the clips in order, one per line.
file 'a.mp4'
file 'b.mp4'ffmpeg -f concat -i list.txt -c copy joined.mp4On our test files the result was 16.021 s long (10 + 6 = 16, plus a 21 ms audio tail), with 480 video frames, 1280x720 at 30 fps, and a decode check that printed no errors. FFmpeg printed one line saying it auto-inserted the h264_mp4toannexb bitstream filter, which is normal for MP4, and one warning about non-monotonic DTS on the audio stream at the join (previous 480256, current 480000), where it adjusted the timestamp. That warning did not cause any decode errors in this test.
The same join with the concat filter re-encodes and gave the same length and frame count:
ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -pix_fmt yuv420p -c:a aac filter_same.mp4We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Join files that do not match
First, what not to do. Joining a.mp4 and c.mp4 with the demuxer and -c copy:
file 'a.mp4'
file 'c.mp4'ffmpeg -f concat -i list_mismatch.txt -c copy bad_mix.mp4FFmpeg did not stop. It finished with exit code 0, printed 89 non-monotonic DTS warnings, and wrote a file that ffprobe said was 13.803 s long when 15.000 s was expected. Decoding that file printed errors such as "Application provided invalid, non monotonically increasing dts". A join that finishes without an error is not a good join, so always check the result.
The fix is to make every input match, then join. This command scales each clip to 1280x720, pads if the shape differs, sets 30 frames per second and 48000 Hz audio, then joins:
ffmpeg -i a.mp4 -i c.mp4 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,fps=30,setsar=1[v0];[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,fps=30,setsar=1[v1];[0:a]aresample=48000[a0];[1:a]aresample=48000[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -pix_fmt yuv420p -c:a aac mixed.mp4Measured result: container length 15.021 s, video stream 15.000 s, 450 frames at 30/1, 1280x720, audio at 48000 Hz, and a decode check with no errors. What each piece does:
- scale with force_original_aspect_ratio=decrease: fit inside 1280x720 without stretching.
- pad: fill the rest with black bars, centered. Our c.mp4 is 16:9, so no bars were needed here; a vertical clip would get bars.
- fps=30: give every clip the same frame rate.
- setsar=1: make pixels square so sizes compare equal.
- aresample=48000: give every clip the same audio sample rate.
We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Fix audio sync and frame rate problems
Mismatched frame rates were the problem we could measure. We joined a.mp4 (30 fps) and c.mp4 (25 fps) with the concat filter but only scaled, leaving out fps=30:
ffmpeg -i a.mp4 -i c.mp4 -filter_complex "[0:v]scale=1280:720,setsar=1[v0];[1:v]scale=1280:720,setsar=1[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -pix_fmt yuv420p -c:a aac scaleonly.mp4The output had 425 frames instead of 450, and ffprobe reported an average frame rate of 53125/1874, about 28.35 fps, so the video was variable frame rate. The video stream was 14.992 s and the audio 15.021 s. With fps=30 in the command above, we got exactly 450 frames, a steady 30/1, and a video stream of 15.000 s. Variable frame rate is what makes some editors and players drift or stutter, so normalize the frame rate before you join.
Audio sample rate: our c.mp4 used 44100 Hz and a.mp4 used 48000 Hz. Even in the scale-only test, FFmpeg 8.1.2 resampled the audio on its own and the output was 48000 Hz. We still keep aresample=48000 in the command so the target is explicit and does not depend on the version.
The 21 ms difference between audio (15.021 s) and video (15.000 s) appeared in both outputs and comes from the AAC encoder's padding. We did not hear or measure any drift in these tests, and we did not test long files, where a small error can grow. To check sync yourself, compare the two stream durations:
ffprobe -v error -show_entries stream=codec_type,duration -of compact mixed.mp4ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate,avg_frame_rate,nb_frames -of compact scaleonly.mp4If the two durations differ by more than a fraction of a second, or the average frame rate differs from the nominal one, normalize first.
Common error messages and what they mean
Unsafe file name
We triggered this by listing files with full paths in the list file and running the demuxer without -safe 0:
file 'C:/videos/a.mp4'
file 'C:/videos/b.mp4'ffmpeg -f concat -i list_abs.txt -c copy abs.mp4FFmpeg printed "Unsafe file name" followed by the path, then "Error opening input: Operation not permitted". The demuxer refuses absolute paths by default. Fixes: use paths relative to the list file (as in list.txt above), or allow it:
ffmpeg -f concat -safe 0 -i list_abs.txt -c copy abs.mp4Input link ... do not match the corresponding output link
We triggered this by running the concat filter on a.mp4 and c.mp4 with no normalizing:
ffmpeg -i a.mp4 -i c.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" bad_filter.mp4FFmpeg printed "Input link in0:v0 parameters (size 640x360, SAR 1:1) do not match the corresponding output link in0:v0 parameters (1280x720, SAR 1:1)", then "Failed to configure output pad on Parsed_concat_0", and stopped with "Invalid argument" (error -22), leaving an empty 0-byte output file. The concat filter needs every segment to have the same size. Fix: scale and pad each input to one size first, as in the mixed.mp4 command above.
Non-monotonic DTS
A warning, not an error: "Non-monotonic DTS; previous: ..., current: ...; changing to ...". It means timestamps went backward at a join and FFmpeg adjusted them. In our matching-files join it appeared once and the file decoded cleanly. In our mismatched join it appeared 89 times and the file was damaged. One warning at the join of matching files is usually fine; a stream of them is a sign the inputs do not match.
Check the result
After every join, check the length against the sum of your inputs, count the frames, and decode the whole file.
ffprobe -v error -show_entries format=duration:stream=codec_type,codec_name,width,height,r_frame_rate,sample_rate -of compact joined.mp4ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 joined.mp4ffmpeg -v error -i joined.mp4 -f null -Our results: joined.mp4 (demuxer) 480 frames and clean; mixed.mp4 (filter, normalized) 450 frames and clean; bad_mix.mp4 (demuxer on mismatched files) 13.803 s and decode errors. Then watch the join point with sound on. A length that adds up proves nothing about what the viewer sees.
Method and limits
All tests ran on FFmpeg 8.1.2 (a full Windows build) and ffprobe 8.1.2, on Windows 11. We made the test files ourselves with FFmpeg's built-in test sources, so there is no camera footage in any test. The files were made with these commands:
ffmpeg -f lavfi -i testsrc2=duration=10:size=1280x720:rate=30 -f lavfi -i sine=frequency=440:duration=10:sample_rate=48000 -c:v libx264 -pix_fmt yuv420p -g 60 -keyint_min 60 -sc_threshold 0 -c:a aac -shortest a.mp4ffmpeg -f lavfi -i mandelbrot=size=1280x720:rate=30 -f lavfi -i sine=frequency=660:duration=6:sample_rate=48000 -t 6 -c:v libx264 -pix_fmt yuv420p -g 60 -keyint_min 60 -sc_threshold 0 -c:a aac -shortest b.mp4ffmpeg -f lavfi -i smptebars=duration=5:size=640x360:rate=25 -f lavfi -i sine=frequency=880:duration=5:sample_rate=44100 -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest c.mp4Limits: tests used short synthetic files, one run each. We did not test camera footage, long files, files with several audio tracks, or other codecs. Messages and defaults can change between FFmpeg versions. We ran each command with -y added, so it could overwrite old test files. It is left out below; add it if you want FFmpeg to overwrite without asking.
Related: FFmpeg trim video: accurate cuts by time, FFmpeg command builder and FFmpeg for video editors.
Every command is shown with the input files, the exact output and a check that confirms the join, so you can compare against your own result. The FFmpeg version used is stated on the page.
- Behaviour can differ between FFmpeg versions, so check the version noted next to each command.
- Commands here cover common formats and are not a guide to every codec.
Page checked on Oct 10, 2026.