FFmpeg is a powerful video processing program that helps users change video/audio formats, concatenate files, trim video length, compress video size, etc. This article is focused on FFmpeg merging videos and offers different approaches for that goal. Just keep reading.
Preparation: Download and install the latest FFmpeg on your Windows, Mac, or Linux from the official website: https://ffmpeg.org/download.html
(The version of FFmpeg used in this tutorial is Microsoft Windows v6.0.1.)
At the core of FFmpeg is the command-line tool. You can use different commands to let FFmpeg merge videos in various cases. Below are some commonly used methods.
Step 1: Put all video files in one folder and name it “MP4” (or something like this).
Step 2: Open the MP4 folder and duplicate the FFmpeg.exe application here.
Step 3: Type “CMD” in the address bar to replace the original path.
Step 4: Press “Enter” to open the Command Prompt window.
Step 5: Type this command and press “Enter” to run it:
for %i in (*.mp4) do @echo file '%i') > mylist.txt
The mylist.txt file will contain a list of all the MP4 files.
Step 6: Finally, run the command to make FFmpeg merge videos to MP4:
ffmpeg -f concat -i mylist.txt -c copy output.mp4
Then, you will receive a final merged video named ‘output.mp4’ in the MP4 folder.
Tips: -c copy will copy all the streams. It makes FFmpeg merge videos without re-encoding.
Hot Search: Join Videos without Re-encoding | Merge Videos without Losing Quality
Method 1. Use FFmpeg “concat” demuxer
Step 1: In the Command Prompt window, create a .txt file and list the paths of the video files you want to combine, like the example here:
merge_video.txt
File /Users/Video/input1.mp4
File /Users/Video/input2.mp4
You can add two or more video files to the .txt list.
Step 2: Run the FFmpeg command:
ffmpeg -f concat -safe 0 -i join_video.txt -c copy output_demuxer.mp4
Method 2. Use FFmpeg “concat” protocol
The “concat” protocol works only for video formats that support five-level concatenation like MPEG-2 TS:
ffmpeg -i "concat:input1.ts|input2.ts" -c copy output_protocol.ts
Many people want to merge videos of different formats or codecs into an MP4 file, but the methods above don’t work for this case. So, here shows you how to combine an MP4 video and a WMV video using the FFmpeg “concat” filter.
Run this FFmpeg command:
ffmpeg -i input1.mp4 -i input2.wmv -filter_complex "[0:0][0:1][1:0][1:1]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4
Pro-tips:
-filter_complex lets you use the concat filter with multiple inputs and outputs.
[0:0][0:1] and [1:0][1:1] take video stream 0 and audio stream 1 from the first input video and the second input video separately.
n=2 refers to the number of segments (input videos).
v=1 and a=1 are the number of output video streams and audio streams.
[outv] and [outa] are the resulting video and audio streams.
Make sure the videos are in the same dimension and frame rate.
The “concat” filter will re-encode your videos, thus taking a long time to merge them.
To concatenate MP4 files having intermediate formats, follow the below steps.
Step 1: Name the two videos to the same, except for the file extension.
Step 2: Open the Command Prompt window and run this command:
ffmpeg -i input.mp4 -i input.mkv -c:v copy -c:a copy output.mp4
You can use a similar command to let FFmpeg combine other files with intermediate formats, such as merging MP4 and M4A: ffmpeg -i input.mp4 -i input.m4a -c:v copy -c:a copy output.mp4
FFmpeg can also put two videos side by side using the “hstack” filter. Here’s the command:
ffmpeg -i input1.mp4 -i input 2.mp4 –filter_complex "[1:v][0:v]scale2ref[wm][base];[base][wm]hstack=2" output.mp4
FFmpeg hstack filter inputs both videos horizontally. To use this command, all import streams must have the same height.
To merge audio in FFmpeg, run this command:
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" output.mp3
You can add more than two audio files.
FFmpeg converts, records, and streams video and audio files in command lines, and it’s very likely to make mistakes typing those complicated elements. You may meet kinds of errors when processing videos in FFmpeg. Therefore, I recommend you use the easy video combiner – WonderFox Free HD Video Converter Factory.
This software is completely free and allows you to merge videos or audio files from different formats, codecs, resolutions, and frame rates. Whether you are a professional or a beginner in video editing, you can finish the process in several simple clicks!
DownloadDownload the free video merger for Windows and follow the simple steps below.
Step 1: Run Free HD Video Converter Factory and open the “Converter”.
Step 2: Click “Add Files” (or “Add Video Folder”) to import the videos you want to combine.
Step 3: Click the “Merge” button.
Step 4: Select all clips in the Video List and click “Merge”. You can drag the video to adjust the order in the Pack. Then, press the bottom “Merge” button.
Step 5: Choose an output video format from the profile menu (“Video” > “MP4”).
Step 6: Specify an output path and tap “Run” to finalize the process.
Pro-tips: WonderFox Free HD Video Converter Factory has a Pro version. You can upgrade to enjoy more features, such as combining videos side by side, recording, and downloading videos. Get it here:
That is how to concatenate multiple videos using FFmpeg and its alternative. Compared with FFmpeg, WonderFox Free HD Video Converter Factory is much easier without dealing with complex command lines. Get the free software, or try the advanced version now!
Also Read: 5 Best Video Mergers without Watermark
Terms and Conditions | Privacy Policy | License Agreement | Copyright © 2009-2024 WonderFox Soft, Inc.All Rights Reserved