11

I want to set a rectangle in a video to black, so that each frame in the video will have this black rectangle. Is it possible ?

I want something similar to this: "How to put border around video to prevent clipping of content" but instead of a black border I want a black rectangle like this

3
  • You can check this Q/A: superuser.com/questions/869117/… Jun 22, 2017 at 6:52
  • Ok, looking at the duck example I was able to do what I want: ./ffmpeg -y -i sample.mp4 -f lavfi -i color=c=black:s=30x40 -filter_complex "[1:v]scale=w=iw:h=ih[scaled]; [0:v][scaled]overlay=x=0.20*main_w:y=0.10*main_h:eof_action=endall[out]; [0:a]anull[aud]" -map "[out]" -map "[aud]" -strict -2 outputfile.mp4 Jun 22, 2017 at 8:43
  • In such case you can answer your own question :) Jun 22, 2017 at 8:49

1 Answer 1

16

Ok, looking at the duck example I was able to do what I want:

./ffmpeg -y -i sample.mp4 -f lavfi -i color=c=black:s=30x40 -filter_complex "[1:v]scale=w=iw:h=ih[scaled]; [0:v][scaled]overlay=x=0.20*main_w:y=0.10*main_h:eof_action=‌​endall[out]; [0:a]anull[aud]" -map "[out]" -map "[aud]" -strict -2 outputfile.mp4 

this puts a 30X40 rectangle on the video.

also "drawbox" works:

ffmpeg -y -i sample.mp4 -vf "drawbox=x=10:y=10:w=100:h=100:color=pink@0.5:t=fill"  outputfile.mp4
2
  • 7
    I found the drawbox example easier to understand. At some point after your answer, an update to ffmpeg now mandates that you replace t=max with t=fill. I'll go ahead and update your answer to reflect this. Dec 6, 2018 at 17:31
  • rest of parameters: @0.5 is alpha/transparency channel (0.0-transparent, 1.0 opaque), t=fill -- thickness of the box edge, fill means filled box. Source: man ffmpeg-filters or ffmpeg.org/ffmpeg-filters.html#drawbox
    – MariusM
    Feb 4 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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