1

I tried to run the following code, but it didn't work.

ffmpeg -i input.mp4 -filter_complex [0:v]drawbox=x=100:y=100:w=100:h=100:color='r=66-ceil(48*Y/H):g=74-ceil(59*Y/H):b=199-ceil(72*Y/H)':t=fill -c:a copy output.mp4

Please teach me how to overlay a rectangular shape with a vertical gradient onto a video, with a constant duration.
I mean that I want to place an image similar to the one shown below over a video.
enter image description here

1 Answer 1

1

geq, overlay

ffmpeg -i input.mp4 -lavfi "
color=black:size=100x100,geq=r=0:g=0:b='lerp(255,127,Y/H)'[o];
[0:v][o]overlay=100:100:shortest=1
" -y out.mp4

drawtext, geq, overlay

ffmpeg -i "in 1.mp4" -lavfi "
color=black@0:size=1280x720,
drawtext=text='Some text'
:box=1
:boxborderw=30
:boxcolor=blue
:borderw=5
:bordercolor=red
:fontsize=h/4
:fontcolor=white
:x=(w-text_w)/2
:y=(h-text_h)/2,
format=rgba,geq=
r='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,r(X,Y))'
:g='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,g(X,Y))'
:b='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),lerp(63,255,Y/H),b(X,Y))'
:a='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),0),0,255)'[t];
[0][t]overlay=(W-w)/2:(H-h)/2
" -c:a copy out.mp4 -y
4
  • Thank you! It works! Apr 17, 2023 at 7:07
  • Actually, I want to use the box above as a background for the text. Is it possible to resize the box to fit the width of the text? Apr 20, 2023 at 8:28
  • added drawtext. not tested as well Apr 20, 2023 at 10:03
  • Thank you very much! You have just made it possible for me to achieve exactly what I wanted to do. Apr 20, 2023 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.