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.mp4Parameter Breakdown
x=0andy=0: Sets the starting point of the box at the top-left corner of the video.w=iw: Sets the width of the box to the input video’s full width (iw).h=ih: Sets the height of the box to the input video’s full height (ih).color=red: Specifies the color of the border. You can use standard color names (e.g.,red,blue,black,white) or hex codes (e.g.,0xFF00FF). You can also append opacity, such asblack@0.5for a semi-transparent black border.t=10: Sets the thickness of the border in pixels. In this example, the border is 10 pixels wide. The thickness grows inward from the specified boundary.
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.mp42. 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.mp43. 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.mp4Note 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.