FFmpeg has two main ways to join videos. If every clip came from the same camera with the same settings, the concat demuxer joins them in seconds without re-encoding: ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4. If the clips differ in size, frame rate or format, use the concat filter, which re-encodes everything into one consistent video.

Which method do you need?

Your clips Method Re-encodes? Speed
Same camera, same settings (GoPro chapters, dashcam loops, one phone) Concat demuxer No Seconds
Different sizes, frame rates or codecs, or some without sound Concat filter Yes As long as encoding the whole video
MPEG-TS files (.ts, .mts, .m2ts) from one recording Concat protocol No (video) Seconds

Step 1: check whether your clips match

Run these two commands on each clip. The first describes the video, the second the sound:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height,pix_fmt,r_frame_rate -of csv=p=0 clip1.mp4
ffprobe -v error -select_streams a:0 -show_entries stream=codec_name,sample_rate,channels -of csv=p=0 clip1.mp4

A typical phone clip prints something like:

h264,1920,1080,yuv420p,30/1
aac,48000,2

That's the codec, width, height, pixel format and frame rate, then the audio codec, sample rate and number of channels. If every clip prints the same two lines, use the concat demuxer. If anything differs, or a clip prints no audio line at all because it has no sound, use the concat filter.

Method 1: the concat demuxer (no re-encoding)

The demuxer reads a list of files and copies their compressed video and sound into one file, one after another. Nothing is decoded, so it's fast and loses no quality.

  1. In the folder with your clips, make a plain text file called list.txt, with one line per clip, in order:

    file 'clip1.mp4'
    file 'clip2.mp4'
    file 'clip3.mp4'
    
  2. Open a terminal in that folder and run:

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

What each part does:

  • -f concat tells FFmpeg that list.txt is a list of files to join, not a video.
  • -safe 0 lets the list contain full paths and unusual file names. Without it, FFmpeg refuses them. It has to come before -i.
  • -c copy copies the streams as they are instead of re-encoding them.

Paths in the list are relative to the folder list.txt is in, not to wherever you run the command from.

Make the list automatically

On a Mac or Linux:

printf "file '%s'\n" *.mp4 > list.txt

In the Windows Command Prompt:

(for %i in (*.mp4) do @echo file '%i') > list.txt

In a .bat file, write %%i instead of %i. On a Mac or Linux, *.mp4 doesn't match .MP4, so use *.MP4 if your camera writes capitals. A file name containing an apostrophe breaks the list, so rename any that do.

Both commands list files in alphabetical order, which isn't always the order they were filmed. Open list.txt and check it before you run FFmpeg. GoPro names are the classic trap: GX010001.MP4, GX020001.MP4 and GX030001.MP4 are the chapters of one recording, but GX010002.MP4, the start of the next recording, sorts between the first two. GoPro file names and chapters explains the naming.

When the demuxer goes wrong

If the clips don't match, FFmpeg usually doesn't refuse. It makes a file that plays the first clip properly and then breaks: the picture freezes or turns to blocks, the sound garbles or disappears, or the video is the wrong length. The warning sign while it runs is a long stream of messages like this:

Non-monotonic DTS; previous: 44872, current: 37704; changing to 44873. This may result in incorrect timestamps in the output file.

One of these at a join is common and usually harmless: it just means one clip's sound ran a fraction longer than its video. Dozens of them mean the clips don't match, and you need the concat filter.

Method 2: the concat filter (for clips that don't match)

The concat filter decodes every clip, so you can make them match first. This example joins a 1080p landscape clip, a 720p clip at 25 fps and a vertical phone clip with no sound, into one 1920×1080 video at 30 fps with black bars where a clip doesn't fill the frame:

ffmpeg -i clip1.mp4 -i clip2.mov -i clip3.mp4 \
  -f lavfi -t 12 -i anullsrc=r=48000:cl=stereo \
  -filter_complex "\
[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30[v0];\
[1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30[v1];\
[2:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30[v2];\
[v0][0:a][v1][1:a][v2][3:a]concat=n=3:v=1:a=1[v][a]" \
  -map "[v]" -map "[a]" -c:v libx264 -crf 18 -preset medium \
  -c:a aac -b:a 192k -movflags +faststart output.mp4

That's for a Mac or Linux terminal. On Windows, put the whole command on one line and drop the backslashes.

What each part does:

  • scale=1920:1080:force_original_aspect_ratio=decrease resizes each clip to fit inside 1920×1080 without changing its shape.
  • pad=1920:1080:(ow-iw)/2:(oh-ih)/2 adds black bars around it to fill the frame, centred.
  • setsar=1 marks the pixels as square. The filter refuses clips whose pixel shapes differ. Old DV and DVD footage is stored with non-square pixels, and scale ignores that, so for those clips start the line with scale=iw*sar:ih,setsar=1, or people come out looking too thin or too wide.
  • fps=30 gives every clip the same frame rate.
  • -f lavfi -t 12 -i anullsrc=r=48000:cl=stereo makes 12 seconds of silence to stand in for the third clip's missing sound. Set -t to that clip's length, which ffprobe -v error -show_entries format=duration -of csv=p=0 clip3.mp4 tells you. The silence is input 3, so it appears as [3:a].
  • concat=n=3:v=1:a=1 joins three segments, each with one video and one audio stream, in the order listed.
  • -crf 18 sets the quality. Lower numbers mean higher quality and bigger files; 18 looks practically identical to the source, and 23 is FFmpeg's default for this encoder.
  • -movflags +faststart puts the file's index at the start, so it can begin playing before it has fully downloaded.

For a vertical video, swap every 1920:1080 for 1080:1920. To join more clips, add an -i, a matching scale line and a [vN][N:a] pair before concat, and raise n=. Inputs are numbered from 0 in the order you list them, so the silence input's number moves up too.

You don't need to match the sound settings yourself: the filter converts all the audio to a common sample rate and channel layout. It also pads a clip's sound with silence if it's shorter than its video. The concat filter documentation has the full details.

Method 3: the concat protocol for .ts and .mts files

MPEG transport stream files, which include camcorder MTS and M2TS files, can be joined end to end at the byte level:

ffmpeg -i "concat:00000.MTS|00001.MTS|00002.MTS" -c:v copy -c:a aac -b:a 192k joined.mp4

This copies the video and converts the sound to AAC, because many camcorders record Dolby Digital (AC-3), which plenty of players can't handle in an MP4. The protocol only works for formats that can be joined byte by byte, such as transport streams and DVD VOB files. Never use it for MP4 or MOV files: use the demuxer for those.

Common errors and what they mean

Unsafe file name '/Users/you/Videos/clip1.mp4' followed by Operation not permitted. The list has full paths, or names with unusual characters (even a space counts). Add -safe 0 before -i list.txt.

Impossible to open 'clip2.mp4'. FFmpeg can't find that file. Check the spelling, and remember that paths are relative to the list file's folder.

Input link in1:v0 parameters (size 1280x720, SAR 1:1) do not match the corresponding output link in0:v0 parameters (1920x1080, SAR 1:1). You fed the concat filter clips of different sizes. Add the scale, pad and setsar=1 steps above to every clip.

Stream specifier ':a' in filtergraph description ... matches no streams. One of the clips has no sound. Give it a silent track with anullsrc, as in the example.

Could not find tag for codec wmv2 in stream #0, codec not currently supported in container. You used -c copy on a codec MP4 can't hold, here an old WMV video. Re-encode instead, with -c:v libx264 -crf 18 -c:a aac.

The output plays the first clip, then freezes or garbles. The clips didn't match, so -c copy couldn't join them cleanly. Use the concat filter. If only the sound goes wrong, see keeping audio in sync when merging.

Without the command line

If you'd rather not type commands, a browser tool does the concat filter's job for you. ClipMerge fits clips of different shapes with black bars, gives silent clips silence so later sound stays in sync, and lets you put photos between clips. It always re-encodes, at a high quality setting, and makes the video as tall as the shortest clip. When your clips match and you want a lossless join, the demuxer is the better tool: how to join videos without losing quality covers that in more depth.