FFmpeg filter: make picture video stream

iPhone photo album has a "recommended for you" function, it will select some photos to form a theme, click it to play like a video. So, how can we convert multiple photos into one video file?

Use FFmpeg to do this:

ffmpeg -f image2 -framerate 0.5 -i D:\MTest\IMG%02d.jpg -s 720x480 -r 15 D:\MTest\outimgs.mp4

First of all, you have to put the source pictures in the same folder, and control the order in which each picture appears in the video through the file name. The file name must be in a unified format, like IMG%02d.jpg. Specifically, they are: IMG01.jpg, IMG02.jpg, ... IMG99.jpg. Small numbers precede large numbers. The first half of the file name is not important, just keep the same. The key is that the numbers in the second half must use the same format and be continuous.

The above FFmpeg command line means: make all the IMGxx.jpg files under the D:\MTest folder into a video file outimgs.mp4, and display each picture for 2 seconds (converted to a frame rate of 0.5fps, Expressed as -framerate 0.5 ), the image is scaled to a uniform size of 720x480, and the frame rate of the target video file is 15fps.

Here comes the question: how to add transition effects when switching pictures?

There is a "stupid way". The general idea is: first generate a temporary video file from a single picture, and then add fade-in and fade-out effects at the beginning and end of the video; after all the pictures are generated in this way, the corresponding video file Connect each video file in turn and merge into one big file. Let's look at the specific steps below.

First deal with the first picture like this:

ffmpeg -f image2 -framerate 0.33 -i D:\MTest\IMG01.jpg  -s 720x480 -r 15 -y D:\MTest\tmp.mp4

ffmpeg -i D:\MTest\tmp.mp4 -vf fade=t=in:st=0:d=1,fade=t=out:st=2:d=1 D:\MTest\outimg1.mp4

Means: First generate a video file tmp.mp4 with a length of 3 seconds from IMG01.jpg, and then add a fade filter to this video file, that is, add a fade-in effect (t=in) in the period of 0~1 seconds, at 2 ~3 seconds plus the fade-out effect (t=out), and finally generate the video file outimg1.mp4.

Suppose we have three pictures in total. The processing methods for the other two pictures are similar, as follows:

ffmpeg -f image2 -framerate 0.33 -i D:\MTest\IMG02.jpg  -s 720x480 -r 15 -y D:\MTest\tmp.mp4

ffmpeg -i D:\MTest\tmp.mp4 -vf fade=t=in:st=0:d=1,fade=t=out:st=2:d=1 D:\MTest\outimg2.mp4

ffmpeg -f image2 -framerate 0.33 -i D:\MTest\IMG03.jpg  -s 720x480 -r 15 -y D:\MTest\tmp.mp4

ffmpeg -i D:\MTest\tmp.mp4 -vf fade=t=in:st=0:d=1,fade=t=out:st=2:d=1 D:\MTest\outimg3.mp4

Finally, merge outimg1.mp4, outimg2.mp4 and outimg3.mp4 into one video file. The command line is as follows:

ffmpeg -i D:\MTest\outimg1.mp4 -i D:\MTest\outimg2.mp4 -i D:\MTest\outimg3.mp4 -filter_complex "[0:0][1:0][2:0]concat=n=3:v=1:a=0" D:\MTest\outimg_all.mp4

The concat filter is used here. The previous parameter specifies the video streams of the three video files as input, and the latter parameters: n means that there are 3 videos participating in the connection, v means the number of output video streams, and a means the output audio stream Quantity.

That's it. Quickly play outimg_all.mp4 to see the effect!

Guess you like

Origin blog.csdn.net/happydeer/article/details/88726151