How to Draw a Border Around Video with FFmpeg drawbox

This article explains how to use the FFmpeg drawbox video filter to add a colored border around your video. You will learn the essential command syntax, the parameters required to position and style the border, and practical examples for applying inner borders of various thicknesses and colors.

The Basic FFmpeg drawbox Syntax

To draw a border around the entire edge of a video, you need to define a box that starts at the top-left corner (coordinate 0,0) and spans the full width (iw or input width) and height (ih or input height) of the video.

The basic command structure is:

ffmpeg -i input.mp4 -vf "drawbox=x=0:y=0:w=iw:h=ih:color=red:t=10" -c:a copy output.mp4

Parameter Breakdown

Practical Examples

1. Drawing a Thin Black Border

If you want to add a subtle 5-pixel black border to your video, use the following command:

ffmpeg -i input.mp4 -vf "drawbox=x=0:y=0:w=iw:h=ih:color=black:t=5" -c:a copy output.mp4

2. Drawing a Semi-Transparent Border

To draw a thick, semi-transparent white border (e.g., 25 pixels wide with 50% opacity), format the color option with @0.5:

ffmpeg -i input.mp4 -vf "drawbox=x=0:y=0:w=iw:h=ih:color=white@0.5:t=25" -c:a copy output.mp4

3. Using Hex Color Codes

If you need to match a specific brand color using a hex code, replace the color name with your hex value (without the # symbol, prefixed with 0x):

ffmpeg -i input.mp4 -vf "drawbox=x=0:y=0:w=iw:h=ih:color=0x1A5276:t=15" -c:a copy output.mp4

Note on Video Re-encoding

Because the drawbox filter modifies the visual pixels of the video, the video stream must be re-encoded. The audio stream, however, does not need to be modified and can be copied directly using -c:a copy to save processing time and maintain original audio quality.