FFmpeg is effective video-editing software that not only resizes, rotates videos but also merges them. This software is a boon if you consider it to work with your audio-video files. Merging videos is as important of a function when it comes to editing. After we go step by step through the methods, you'll learn how to merge files with the use of this software available for Windows & Mac.
Part 1: Step-to-Step Guide- How to Concatenate Two MP4 Videos with FFmpeg easily ？
Now, let us look at a systematic method by which we can merge videos.
Step 1: Firstly, you have to store all the mp3 files you want to combine in a single folder. For example, the path of a folder is:
Step 2: Now, you have to download the FFmpeg file from the given website
Download the version that suits your computer. For example- My PC is best suited with the 64-bit latest version.
Step 3: Then, by right-clicking the Command Prompt window on the Windows icon or press'Windows + R on your keyboard, typecmd.exe. Now, press Enter to open it.
Step 4: After the command prompt window has opened, you have to replace the destination folder path or type in the mp4 files.
Step 5: Then, you have to create a .txt folder that will contain a list of all the mp4 files that you wish to merge together. You, now, have to type this given command and press Enter:
(for %i in (*.mp4) do @echo file '%i') > mylist.txt
You can now see that amylist. txt file has been created in the mp4 folder with a list of all the mp4 files.
Step 6: To complete the process, you have to type a command to integrate all the chosen mp4 files by using FFmpeg ––
ffmpeg -f concat -i mylist.txt -c copy output.mp4
This process is a way of concatenating the files and not re-encoding. Hence, it should be done speedily & conveniently. If there is no error message, you are sure to receive a final merged video named by 'output.mp4' in the MP4 folder.
Fans of FFmpeg also like to read: Rotate Videos using FFmpeg
Part 2: Advanced Tutorial- Three Ways to Concatenate MP4 Videos with FFmpeg Like a Pro
As we know that merging videos is quite an important function when it comes to video editing. Here's an advanced tutorial explaining how to merge mp4 videos on FFmpeg like a pro. Make your videos graceful by adding transitions, filters, effects, and much more.
Also, we looked into how to concatenate videos using FFmpeg. Here are innovative ways in which we can concatenate videos on FFmpeg.
1. Concatenate videos in a directory
This is a commonly used function and it has more to do with shell scripting than FFmpeg usage. First off, you have to take here is to find all the mp4/ avi/ Wav files in your directory, add them to a file. Then, you can easily concatenate them as shown earlier.
for f in *.mp4 ; do echo file \'$f\' >> fileList.txt;
And, then you can concatenate them using the contact command we learned about earlier as follows:
./ffmpeg -f concat -safe 0 -i fileList.txt -c copy mergedVideo.mp4
2. Concatenate mp4 Files of Different Codecs, resolutions
If the pixel formats, different video codecs or height, and width of the video differ, then, you'll have to re-encode it.
1. Re-encode the files before joining them- This technique is where you've to re-encode all the files to the desired format and then use the 'concat' command to join all of them together. It is helpful for a large set of videos & to control their quality precisely before joining them together.
2. Concatvideo filter –– The second option where you can re-encode your content and also preserve the filtering option of the videos before concatenating them. Let's look at this option in detail now.
Here's a sample of a command line ––
ffmpeg -i file1.mp4 -i file2.mp4 -i file3.mp4 \
-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a]
concat=n=3:v=1:a=1 [v] [a]" \
-map "[vv]" -map "[aa]" mergedVideo.mp4
To break down this command line:
Firstly, we provide the input file names to FFmpeg-
-i file1.mp4 -i file2.mp4 -i file3.mp4
Then, we've to use the'filter_complexfiltergraph'parameter to instruct from where to take the audio and video in FFmpeg.[0:v][0:a]denotes FFmpeg to take the audio and video from the0thvideo (file1.mp4). Then, you've to tell FFmpeg to concat three files i.e., (n=3). Thev=1:a=1infers that there's one stream for the audio and one stream for the video.
And at the end,[vv] [aa] stand for the names we've chosen for the output video and audio.
-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] concat=n=3:v=1:a=1 [vv] [aa]"
The ultimate step is to map the audio and video outputs to the final video container. This can be done as follows ––
-map "[vv]" -map "[aa]" mergedVideo.mp4
Note: This stage is where you have the merged audio and video in[vv] [aa]and you may either write them out to the final container, use them in another filter to further process them.
3. Concatenate mp4 videos using file formats
Some container formats like mp4 cannot be directly concatenated with Linux's use of kernel's cat command or FFmpeg'sconcatcommand. An alternative for this is to convert the files into an intermediate file format, then, concatenate them easily. The format for an intermediate file ists(Transport Stream).
Here's a one-liner to convert mp4 files tots
ffmpeg -i file1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts fileIntermediate1.ts
After completing the conversions, you have to simply cat them together with the Linux terminal or the concat command in FFmpeg. Both should work.
cat fileIntermediate1.ts fileIntermediate2.ts > output.ts OR
ffmpeg -i "concat:fileIntermediate1.ts|fileIntermediate2.ts" -c copy -bsf:a aac_adtstoasc mergedVideo.mp4
These may feel like a lot of steps to keep in mind. Therefore, there's an alternative that can save you the hard work of going over so many steps. It is called iMyFone.
If you are a fan of FFmpeg, you may also want to know: Use FFmpeg To Resize/Scale Video
Part 3: Best FFmpeg Alternative to Merge Videos Easily on Windows/Mac
This software transforms normal videos into scenic pieces of work without too much hassle. That is Filme for you. If you wish to instantly change the looks of your videos, consider this software. With resizing, cropping and rotation of videos, this software also involves merging of videos. Combining videos is another necessary function with regards to video-editing. Here are a few steps that may seem complicated but if followed correctly, merging videos can be easily achieved without any technical operation.
170+ video effects. Enables plentiful Effects resources to add enhancing filters and animations to produce vivid and refined digital stories.
50+ audio provided and editable soundtrack. Helps in achieving the effect of a mixing room of a recording studio. Allows playing 7 or more audio tracks simultaneously.
Easy multi-layering.For videos, text, images, audio, transitions, overlays and animations.
20+ Fast video modes. Slideshows and Vlogs for weddings, birthdays, traveling and team building are just a matter of a few clicks.
Features of iMyFone Filme
Step 1: Firstly, launch Filme on your computer. Head to File>New Project and select the aspect ratio.
Step 2: Click theImportbutton. Now, you have four options to import video clips. Importing files and folders from the PC is easier now. Besides, you can directly import files from your Android phone. This software supports wired & wireless imports from mobile phones.
Step 3: You will see the imported files inMy Media. Drag them to the timeline. The videos can be arranged in the timeline as necessary. Filme also provides you to match all video resolutions.
Step 4: After dragging videos to the timeline, you have to import the audio files. You can easily mute the original sounds of the video and use other music tracks. Now, Import the file and move them to the timeline. Filme also enables you to directly record the sound from the microphone and use it in the video. Tap on the microphone icon above the timeline to record audio.
Step 5: When you are done, see the preview. In the 'Export' menu, click on'Export Video'. Select the settings of the video you need and click on 'Export'.
Part 4: Frequently Asked Questions
1. What software can I use in Linux for trimming and concatenating videos?
For trimming and concatenating videos in Linux, you can use ffmpeg. Following is the command line for the same:
ffmpeg -f concat -i input.txt -c copy "--with:fade:out-in" output.ogg
In case, you find this method difficult, you can go forward with Joyoshare Video Joiner as it is easy-to-use. It combines videos with the same format and codec promising to maintain the video quality.
2. How can I introduce a fade-in and fade-out to the video being inserted?
While operating ffmpeg, it is easy to apply the fade in and fade out feature to video using the 'fade' filter. For audio, the a fade filter can be used to achieve a similar effect.
ffmpeg -i video.mp4 -vf "fade=t=in:st=0:d=3" -c:a copy out.mp4
A black screen will appear and fade in to full view over 3 seconds.
ffmpeg -i video.mp4 -vf "fade=t=out:st=10:d=5" -c:a copy out.mp4
The video starts fading to black over 5 seconds towards the 10 second mark.
ffmpeg -i music.mp3 -af "afade=t=in:st=0:d=5" out.mp3
The audio file starts at a low volume and fades into full over 5 seconds.
ffmpeg -i music.mp3 -af "afade=t=out:st=5:d=5" out.mp3
The audio file starts fading to zero volume over 5 seconds starting at the 5 second mark.
ffmpeg -i video.mp4 -vf "fade=t=in:st=0:d=10,fade=t=out:st=10:d=5" -c:a copy out.mp4
Applying both fade in and out effects at the same time is possible to avoid re-encoding twice.
3. Is it possible to program a list of concatenations to do?
For example I have 50 videos, and I want to merge each of them with the same intro video with my brand. Do I have to do 50 times the same operation, or can I program it?
Yes, there are three ways to do this.
1. The concat demuxer approach
This is a very fast method as it avoids transcoding.
It only works if the files have the same video and audio encoding, otherwise, artifacts will be introduced.
2. File-level concatenation approach
Few encodings support file-level concatenation, just like just applying caton two files in the terminal.
Very few encodings can do this, the only one widely used is the MPEG-2 Transport Stream codec (.ts)
3. A complex filter graph with the concat filter
This method concats videos with different encodings.
It causes transcoding, so it takes time and may degrade quality.
The syntax here is hard to understand if you haven't ever written complex filter graphs for ffmpeg.
4. How to concatenate videos without losing video quality?
Yes, it can be done using this command line:
ffmpeg -i output1.mp4 -scodec copy -vbsf h264_mp4toannexb i0.ts
However, it can sometimes be a task to understand the command lines and use FFmpeg with the command lines. We're here to make it easier for you. But if this method turns out to be more difficult, you can always use iMyFone Filmeas an alternative method.
To sum up, merging videos has become efficient with the help of iMyFone Filme. Consider installing the software for pro video outputs!
Fast Video mode: create your stunning video in 1 single click.Download Now