A
A
Andrey Minisol2016-07-12 13:46:41
linux
Andrey Minisol, 2016-07-12 13:46:41

How to merge video in ffmpeg?

Good afternoon, the task was to merge several videos into one (the number of videos is always different (i.e. maybe 1, maybe 2, maybe n), actually googled such an example:

ffmpeg -i new_1.mp4 -i new_2.mp4 -i new_3.mp4 -i new_4.mp4 -filter_complex "nullsrc=size=640x480 [base]; [0:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft]; [1:v] setpts=PTS-STARTPTS, scale=320x240 [upperright]; [2:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft]; [3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerright]; [base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][upperright] overlay=shortest=1:x=320 [tmp2]; [tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3]; [tmp3][lowerright] overlay=shortest=1:x=320:y=240" -c:v output.mp4

in this example, 4 videos are merged, but I don’t quite understand whether it’s possible to write the position of the video instead of upperright?
example. Let's say the canvas we're working on is 1280x768 and we have 6 videos (all videos are the same size but have different durations, let's say the size of one video is 1024x768). We are trying to place them in two lines, three videos per line. we get the following dimensions for the video: width : 1280
/ 3 = 426 pixels
height: 768 / 2 = 384, where 2 - the number of lines , scale=320x240[upperleft]; and like this for example: [0:v] setpts=PTS-STARTPTS, scale=426x384 [0,384]; [1:v] setpts=PTS-STARTPTS, scale=426x384 [426,384];
or somehow differently? how to make a grid in ffmpeg?
2) in the case of videos that are different in time, after the shortest video has elapsed, the picture will continue to slow down, but the audio track goes on, how to solve this issue? adjust the timing of a short video to the longest one? then how is it done? something like filling the rest with 4 frames?
thanks for the help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question