Merge mp4 files using ffmpeg

1. Problem description

There are the following two videos, we want to merge the following videos into one video, (1 in the front and 2 in the back)
Insert image description here

2. Solution

2.1

Go to the current folder and execute the command.
Convert all 1.mp4 and 2.mp4 to 1.mpg, 2.mpg, then merge 1.mpg, 2.mpg into output.mpg, and
then convert output.mpg into output.mp4.

ffmpeg -i 1.mp4 -qscale 4 1.mpg
ffmpeg -i 2.mp4 -qscale 4 2.mpg
ffmpeg -i "concat:1.mpg|2.mpg" -c copy output.mpg
ffmpeg -i output.mpg -y -qscale 0 -vcodec libx264 output.mp4

The effect is as follows.
Insert image description here

2.2 Merge multiple mp4 files

When there are multiple mp4 files that need to be merged, and the first method is too troublesome, you can use the method introduced below.
Put all mp4 file information into a txt file.
Insert image description here

file '1.mp4'
file '2.mp4'
file '3.mp4'

Excuting an order

ffmpeg -f concat -i videolist.txt -c copy out.mp4

It was executed in a flash.
Insert image description here

Guess you like

Origin blog.csdn.net/xdg15294969271/article/details/125163418