Monday 4 December 2017

Creating an FFmpeg image slideshow with zoompan and fade in/out


I've been trying FFmpeg through whatever tutorials I can find over the internet and I'm a bit puzzled as to how to combine a zoompan effect with fade in and fade out of a series of images.


A got to the following after combining bits and pieces of examples I found but it looks like the result I get is sequential and not what I thought it would be.


Any pointers to point me to the right direction would be appreciated.


ffmpeg \ 
-loop 1 -t 5 -i input/slideshow/img0001.jpeg
-loop 1 -t 5 -i input/slideshow/img0002.jpeg \
-loop 1 -t 5 -i input/slideshow/img0003.jpeg \
-loop 1 -t 5 -i input/slideshow/img0004.jpeg \
-filter_complex \
"[0:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=out:st=4:d=1[v0]; \
[1:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
[2:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
[3:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
[v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v]" -map "[v]" -s "800x450" -t 40 output/out_fade.mp4

Answer




The example you gave with ffmpeg actually worked with very little modification (keeping -loop in caused a segfault: "Error in 'ffmpeg': double free or corruption (!prev): 0x0000000008dffa00").


So we have:



ffmpeg \
-t 5 -i 1.jpg \
-t 5 -i 2.jpg \
-t 5 -i 3.jpg \
-t 5 -i 4.jpg \
-filter_complex \
"[0:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=out:st=4:d=1[v0]; \
[1:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
[2:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
[3:v]zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
[v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v]" -map "[v]" -s "800x450" -t 40 ./out_fade.mp4

Example Output:


zoompan and fade example


Potato quality- I need to figure out gif optimisation better! Artifacts and distortion are result of trying to get file size < 2MB and are not present in original video output- it should be enough to give you an idea of whether it fits your use-case. Images are my own.





added based on comments


Even with this minimal example, the filtergraph gets quite complex quite quickly, and it's tedious to change things. A different library might do better.


MLT / MELT


For example,MELT for the MLT Framework might do:



Melt was developed as a test tool for the MLT framework. It can be thought of as a powerful, if somewhat obscure, multitrack command line oriented video editor.



and is frequently suggested.


MoviePy


However, MoviePy (GitHub page) might suit your needs better, as it is slightly more concise and (I'd suggest) more user-friendly, insofar as a command-line video editor can be user-friendly.


You probably are most interested in the sections on compositing and transitions/effects




I suggest the above two based on my own experience of trying to crowbar in transitions with ffmpeg; it's doable and capable of producing some very decent effects, but the pain is not worth it. The script above should answer your question about a continuous zoom-out with a fade in/out.


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...