Dip/fade to black
Scroll down for crossfade method.
![fade example](https://cdn.statically.io/img/i.sstatic.net/PbhPC.gif)
Example where each image displayed for 5 seconds and each has a fade that lasts 1 second. Each image input has the same width, height, and sample aspect ratio. If they vary in size see example #3 below.
MP4 output
See the examples in Resizing videos to fit into static sized player if you want to crop (fill the screen) instead of pad (letterbox/pillarbox), or if you want to prevent upscaling.
GIF output
Adds the filters from How do I convert a video to GIF using ffmpeg, with reasonable quality?
ffmpeg \
-framerate 10 -loop 1 -t 5 -i input0.png \
-framerate 10 -loop 1 -t 5 -i input1.png \
-framerate 10 -loop 1 -t 5 -i input2.png \
-framerate 10 -loop 1 -t 5 -i input3.png \
-framerate 10 -loop 1 -t 5 -i input4.png \
-filter_complex \
"[0:v]fade=t=out:st=4:d=1[v0]; \
[1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
[2:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
[3:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
[4:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
[v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,split[v0][v1]; \
[v0]palettegen[p];[v1][p]paletteuse[v]" -map "[v]" out.gif
Use the -loop
output option to control the number of times the GIF loops. Default is infinite loop if this option is not used. A value of -1
is no loop.
Options and filters used:
-t
to set duration in seconds of each input.
-loop 1
loops the image otherwise it would have a duration of 1 frame.
-framerate
to set input image frame rate (default when undeclared is 25). Useful for making GIF.
scale with pad to fit the input images into a specific, uniform size (used in example #3).
fade to fade in and out. d
is the duration of the fade. st
is when it starts.
concat to concatenate (or "join") each image.
format to output a chroma subsampling scheme that is compatible with non-FFmpeg based players if outputting MP4 and encoding with libx264 (the default encoder for MP4 output if it is supported by your build).
split to make copies of a filter output. Needed by the palette* filters to do everything in one command.
palettegen and paletteuse for making nice looking GIF.
Example where each image displayed for 5 seconds and each has a crossfade that lasts 1 second. Each image input has the same width, height, and sample aspect ratio. If they vary in size then adapt example #3 above.
MP4 output
ffmpeg \
-loop 1 -t 5 -i 1.png \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \
-filter_complex \
"[1]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
[2]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
[3]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
[4]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
[0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
[bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -movflags +faststart out.mp4
With audio
ffmpeg \
-loop 1 -t 5 -i 1.png \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \
-i music.mp3 \
-filter_complex \
"[1]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
[2]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
[3]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
[4]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
[0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
[bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -map 5:a -shortest -movflags +faststart out.mp4
GIF output
ffmpeg \
-framerate 10 -loop 1 -t 5 -i 1.png \
-framerate 10 -loop 1 -t 5 -i 2.png \
-framerate 10 -loop 1 -t 5 -i 3.png \
-framerate 10 -loop 1 -t 5 -i 4.png \
-framerate 10 -loop 1 -t 5 -i 5.png \
-filter_complex \
"[1]format=rgba,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
[2]format=rgba,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
[3]format=rgba,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
[4]format=rgba,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
[0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3];[bg3][f3]overlay,split[v0][v1]; \
[v0]palettegen[p];[v1][p]paletteuse[v]" -map "[v]" out.gif
Use the -loop
output option to control the number of times the GIF loops. Default is infinite loop if this option is not used. A value of -1
is no loop.