Draw a Solid Red Rectangle in FFmpeg Using drawbox

This article provides a straightforward guide on how to use the FFmpeg drawbox video filter to overlay a solid red rectangle onto a specific region of a video. You will learn the exact command syntax, how to define the box's coordinates and dimensions, and how to configure the filter to fill the shape completely rather than drawing a simple outline.

To draw a solid red rectangle over a specific region of a video, you need to use the drawbox video filter (-vf) and set its thickness parameter to fill.

The FFmpeg Command

Here is the basic command template to achieve this:

ffmpeg -i input.mp4 -vf "drawbox=x=100:y=150:w=300:h=200:color=red:t=fill" -c:a copy output.mp4

Parameter Breakdown

  • -i input.mp4: Specifies your input video file.
  • -vf: Tells FFmpeg to apply a video filter.
  • drawbox=...: Invokes the drawbox filter with the following parameters:
    • x=100: The horizontal coordinate of the top-left corner of the rectangle (in pixels from the left edge of the video).
    • y=150: The vertical coordinate of the top-left corner of the rectangle (in pixels from the top edge of the video).
    • w=300: The width of the rectangle in pixels.
    • h=200: The height of the rectangle in pixels.
    • color=red: Sets the color of the rectangle. You can use standard color names like red, or hex codes like 0xFF0000.
    • t=fill (or thickness=fill): This is the key setting that makes the rectangle solid. If omitted, FFmpeg will only draw a 3-pixel-wide outline.
  • -c:a copy: Copies the audio stream without re-encoding to save time and preserve audio quality.
  • output.mp4: The name of the resulting output video file.

Advanced Formatting Options

If you want to make the solid red rectangle semi-transparent, you can append an opacity value to the color parameter using the @ symbol:

ffmpeg -i input.mp4 -vf "drawbox=x=100:y=150:w=300:h=200:color=red@0.5:t=fill" -c:a copy output.mp4

In this variation, red@0.5 sets the opacity of the solid red rectangle to 50%, allowing the underlying video to remain partially visible.