To concatenate multiple videos into a single file with silent audio using FFmpeg, you must first ensure all source files share identical video and audio properties. This process involves creating a text file listing your inputs, generating a temporary combined stream, and then muxing the result while explicitly stripping the audio track to achieve the desired silent output.
Prerequisites and Environment Setup
Before attempting to merge any media files, it is critical to verify that your system has FFmpeg installed and accessible via the command line. You can verify this by running
ffmpeg -version in your terminal or command prompt. If the command returns a version number, you are ready to proceed. For Windows users, ensure the FFmpeg binary is added to your system PATH or navigate directly to the installation directory in your command prompt. Linux and macOS users typically have access through package managers like
apt,
yum, or
brew.
The most common reason for concatenation failures is mismatched container formats or codecs. Even if two videos look similar in a player, they may use different internal structures. To avoid complex transcoding steps later, try to use source files that are already encoded with the same codec (e.g., both H.264), resolution, frame rate, and pixel format. If your sources vary significantly, you will need to normalize them first, which adds processing time but ensures stability.
Preparing the Input List
FFmpeg’s concat demuxer requires a specific input file format to function correctly. You cannot simply pass a wildcard pattern like
*.mp4 to the concat demuxer; instead, you must create a plain text file that lists each video file individually. Create a new text file named
input.txt (or any name you prefer) and add lines following the syntax
file 'path/to/video.mp4'. Each line must point to an existing file on your disk.
For example, if you have three clips located in the current directory, your
input.txt might look like this:
file 'clip1.mp4'
file 'clip2.mp4'
file 'clip3.mp4'
Ensure there are no empty lines between entries and that the paths are correct relative to where you will run the command. If your files contain spaces in their names, enclose the path in single quotes as shown above. This list serves as the blueprint for FFmpeg to stitch the segments together sequentially.
Concatenating and Removing Audio
Once your input list is ready, you can execute the concatenation command. The core strategy here is to first create a temporary concatenated stream that includes audio, and then immediately remove that audio channel during the final muxing step. This approach is often more reliable than trying to filter audio out before concatenation because some containers require valid audio streams to maintain timing integrity during the join process.
Run the following command structure, replacing
input.txt with your actual list filename and
output.mp4 with your desired destination:
ffmpeg -f concat -safe 0 -i input.txt -c copy -an output.mp4
Let us break down these flags. The
-f concat flag tells FFmpeg to use the concat demuxer. The
-safe 0 option allows the use of absolute paths in your input list, which prevents errors if your files are stored outside the current working directory. The
-i input.txt points to your list file. The
-c copy instruction instructs FFmpeg to copy the streams without re-encoding, which makes the process extremely fast and lossless. Finally, the
-an flag is the crucial part; it disables audio recording, ensuring the output file contains only the video stream.
If you encounter issues with certain proprietary formats, such as MP4 files created by mobile devices, you might need to remux them into a standard MPEG-TS container first, as the concat demuxer sometimes struggles with fragmented MP4 files. In such cases, convert each clip individually using
ffmpeg -i input.mp4 -c copy -bsf:a aac_adtstoasc output.ts before creating your list.
Troubleshooting Common Errors
Users often face errors when the input files do not match perfectly. If FFmpeg complains about incompatible parameters, it means the video resolutions, frame rates, or pixel formats differ between your clips. You can diagnose this by running
ffprobe on your source files to inspect their headers. Look for discrepancies in width, height, r_frame_rate, and pix_fmt.
Another frequent issue arises from the
-safe 0 flag being omitted. Without it, FFmpeg blocks absolute paths for security reasons, throwing a "Unsafe file name" error. Always include this flag unless you are strictly using relative paths within the same directory. Additionally, if you see black frames at the beginning or end of the merged video, check your source clips for trailing silence or extra frames. Trimming each clip slightly before concatenation can often resolve visual glitches.
For those interested in manipulating other aspects of video processing, you might find our guide on
Fixing FFmpeg Color Number Extraction Issue helpful for resolving color space mismatches during complex edits. Similarly, understanding how to handle frame extraction can aid in debugging timing issues, as detailed in
Extracting Frames from a Video using FFmpeg.
Frequently Asked Questions
Can I concatenate videos with different resolutions?
No, the concat demuxer requires all input files to have identical video parameters, including resolution, frame rate, and codec. If your videos differ, you must resize and re-encode them to match before concatenation, which involves a slower transcoding process rather than a simple copy.
Why does my output file have no sound even though I didn't use -an?
If your source videos were recorded without audio tracks, the concatenated output will naturally be silent. However, if your sources have audio and the output is still silent, you may have accidentally included the
-an flag in your command, which forcibly removes all audio streams regardless of their presence in the input.
Is it possible to add music back after concatenating?
Yes, you can concatenate the videos silently first using the method described, and then add a background music track in a second step. Use the command
ffmpeg -i output.mp4 -i music.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 final_video.mp4 to mix the silent video with your chosen audio file.
What should I do if FFmpeg says the file is not a valid input?
This error usually indicates that the file path in your
input.txt is incorrect or the file is corrupted. Verify that every file listed exists at the specified location and is a valid media file. Using the
-safe 0 flag helps if you are using absolute paths, ensuring FFmpeg accepts them without security warnings.
Does this method preserve the original video quality?
Yes, because we use the
-c copy flag, FFmpeg performs a stream copy operation. This means no video data is re-encoded, so the quality remains identical to the source files. The only potential quality loss could come from minor container differences, but generally, the output is bit-for-bit identical to the sum of its parts.