To merge two AVI files using FFmpeg, follow these steps:
First, ensure FFmpeg is installed on your computer. Verify the installation by entering ffmpeg -version in the command line.
Next, use FFmpeg's concat protocol to merge files. There are two primary methods: using the concat filter or the concat protocol. Below, I'll provide examples for both approaches.
Using concat filter
This method works best when the video files share similar encoding and formats.
-
Create a list file containing the paths to the video files to be merged, for example
inputs.txt, with the following content:shellfile '/path/to/first.avi' file '/path/to/second.avi'Replace
/path/to/first.aviand/path/to/second.aviwith your actual file paths. -
Run the following command to merge the videos:
shffmpeg -f concat -safe 0 -i inputs.txt -c copy output.aviHere,
-f concatspecifies the concat format,-safe 0enables absolute paths,-i inputs.txtdefines the input file list,-c copycopies video and audio streams without re-encoding, andoutput.aviis the merged output filename.
Using concat protocol
This method is simpler but requires all video files to have identical encoding, resolution, and frame rate.
-
Use the
concatprotocol directly in the command line with the following command:shffmpeg -i "concat:/path/to/first.avi|/path/to/second.avi" -c copy output.aviHere,
concat:/path/to/first.avi|/path/to/second.avispecifies the files to merge, separated by the pipe|.-c copysimilarly instructs FFmpeg to copy streams without re-encoding.
In the above command, the -c copy parameter ensures FFmpeg avoids re-encoding video and audio streams when possible, providing faster processing and preserving original quality. However, if encoding or format differences exist, remove -c copy to allow FFmpeg to re-encode for compatibility.
Finally, note that when merging videos, ensure all files are compatible in video encoding, resolution, and frame rate; otherwise, the merged video may not play correctly. If necessary, convert the video files first to ensure consistent encoding and format.