FFmpeg: Change the timing/easing of an XFade transition in FFmpeg - ffmpeg

Given an xfade transition filter such as this:
ffmpeg -loop 1 -t 5 -i 1.png -loop 1 -t 5 -i 2.png -filter_complex "[0][1]xfade=transition=slideleft:duration=1:offset=4,format=yuv420p" output.mp4
Is it possible to alter the timing/easing of the xfade transition? For instance, the above slideleft transition seems to be linear in the output video. How could one achieve a non-linear easing such as a cubic ease in for the transition between the two clips?

xfade custom transition, slideleft with easing
ffmpeg \
-loop 1 -t 1.1 -i in1.png \
-loop 1 -t 1.1 -i in2.png \
-filter_complex "
[0]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[v0];
[1]scale=-2:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1[v1];
[v0][v1]xfade=duration=1:offset=0.1:transition=custom:
expr='
if(lt(X+W*pow(1-P,3),W),
if(eq(PLANE,0),a0(X+W*pow(1-P,3),Y),0)
+if(eq(PLANE,1),a1(X+W*pow(1-P,3),Y),0)
+if(eq(PLANE,2),a2(X+W*pow(1-P,3),Y),0)
+if(eq(PLANE,3),a3(X+W*pow(1-P,3),Y),0)
,if(eq(PLANE,0),b0(X-W+W*pow(1-P,3),Y),0)
+if(eq(PLANE,1),b1(X-W+W*pow(1-P,3),Y),0)
+if(eq(PLANE,2),b2(X-W+W*pow(1-P,3),Y),0)
+if(eq(PLANE,3),b3(X-W+W*pow(1-P,3),Y),0)
)'
" -y /tmp/output.mp4
ffplay -loop 0 /tmp/output.mp4

Related

FFMPEG images to video + overlay video

I am trying to make 15 second video where the background layer is a video made up of 2 images, the first line creates a 15 second video from 2 images.
I chose a small framerate so it renders an mp4 quickly. I then overlay a webm video (which has transparency) over the images. The final video seems to keep the framerate of 2, but i would rather keep the 24 framerate of the webm video.
Is this possible? & is it also possible to turn the below into 1 statement.
ffmpeg -loop 1 -framerate 2 -t 11 -i image1.png -loop 1 -framerate 2 -t 4 -i image2.png -filter_complex "[0][1]concat=n=2" backgroundvideo.mp4;
ffmpeg -i backgroundvideo.mp4 -c:v libvpx-vp9 -i overlayvideo.webm -filter_complex overlay newvid.mp4
You can use the filter fps to adjust your background's framerate
ffmpeg \
-loop 1 -framerate 2 -t 11 -i image1.png \
-loop 1 -framerate 2 -t 4 -i image2.png \
-c:v libvpx-vp9 -i overlayvideo.webm \
-filter_complex '[0][1]concat,fps=24[bg];[2][bg]overlay' \
backgroundvideo.mp4

ffmpeg adjust contrast, show histogram

I'm trying to first adjust the contrast of a frame extracted from an mp4, then overlay the histogram of the resultant frame on top. My command here does all of this, but also adjusts the contrast of the histogram itself. Is there a single ffmpeg command that can do what I wish?
ffmpeg -ss 3.5 -i in.mp4 -an -y -vf \
"split=2[a][b],[b]eq=0.5:0:1:1:1:1:1,histogram=levels_mode=logarithmic:\
components=1:level_height=100, [a]overlay,eq=0.5:0:1:1:1:1:1" \
-vframes 1 -q:v 2 out.jpg
Use
ffmpeg -ss 3.5 -i in.mp4 -an -y -filter_complex \
"eq=0.5:0:1:1:1:1:1,split=2[a][b];[b]histogram=levels_mode=logarithmic:\
components=1:level_height=100[b];[a][b]overlay" -vframes 1 -q:v 2 out.jpg

ffmpeg image scrolling with background image

I have code
ffmpeg -loop 1 -t 24 -i "image.jpg" -filter_complex "color=000000:s=640x360[bg];[bg][0]overlay=shortest=1:y='min(0,-(t)*26)'" -qscale 1 -y out.mpg
How to change this code so that instead of a black base color there was a background in the form of an image?
I will be grateful for the help!
Add another image input and use it as the background in the overlay:
ffmpeg -y -i background.jpg -loop 1 -t 24 -i "image.jpg" -filter_complex "[0][1]overlay=y='min(0,-(t)*26)'" -qscale 1 out.mpg

How to add 'drawtext' to overlay in ffmpeg?

The command is ffmpeg -loop 1 -t 5 -i "demo_1.jpg" -filter_complex "nullsrc=size=640x360[background];[background][0:v]overlay=shortest=1:x='min(-(t)*20,0)'" -qscale 1 -y out.mp4
I am animating the image from right to left. In the above command, I need to add text, How to integrate the drawtext feature of ffmpeg to that.
The video animation is https://youtu.be/teXUiPKX83o.
Need to add text to that video.
Use
ffmpeg -loop 1 -t 5 -i "demo_1.jpg" -filter_complex
"nullsrc=size=640x360[background];
[background][0:v]overlay=shortest=1:x='min(-(t)*20,0)',
drawtext=fontfile='/path/to/font':fontsize=30:fontcolor=yellow:x=50:y=50:text='Text'"
-qscale 1 -y out.mp4
See drawtext docs for more info.

how to fade two images with ffmpeg

I have two images and I want to create a simple fading transition between them.
I also want the final output to be a sequence of images rather than a video?
So if the fading transition was 10 frames long I'd want the output to be a sequence of 10 images.
How can I achieve this with ffmpeg?
See the blend video filter:
ffmpeg -loop 1 -i input0.png -loop 1 -i input1.png -filter_complex "[1:v][0:v]blend=all_expr='A*(if(gte(T,3),1,T/3))+B*(1-(if(gte(T,3),1,T/3)))'" -t 4 frames_%04d.png
This example will make a 3 second cross-fade of input1.png over input0.png.
To crossfade/dip-to-black multiple images see Create video with 5 images with fade-in/out effect in ffmpeg.
To the best of my knowledge you cannot achieve this just with ffmpeg. Please take a look at MLT framework if you want to do it in scriprs; take a look at openshot if you want an interactive app.
Try this:
ffmpeg \
-loop 1 -t 3 -i input1.png \
-loop 1 -t 3 -i input2.png \
-loop 1 -t 3 -i input3.png \
-loop 1 -t 3 -i input4.png \
-loop 1 -t 3 -i input5.png \
-filter_complex \
"[1:v][0:v]blend=all_expr='A*(if(gte(T,3),1,T/3))+B*(1-(if(gte(T,3),1,T/3)))'[v0]; \
[2:v][1:v]blend=all_expr='A*(if(gte(T,3),1,T/3))+B*(1-(if(gte(T,3),1,T/3)))'[v1]; \
[3:v][2:v]blend=all_expr='A*(if(gte(T,3),1,T/3))+B*(1-(if(gte(T,3),1,T/3)))'[v2]; \
[4:v][3:v]blend=all_expr='A*(if(gte(T,3),1,T/3))+B*(1-(if(gte(T,3),1,T/3)))'[v3]; \
[v0][v1][v2][v3]concat=n=4:v=1:a=0[v]"
-map "[v]" out.mp4
Haven't tried with images, but you could try -t 12 frames_%04d.png at the end or whatever.

Resources