Change FFmpeg Pad Color with Hex Code

This article explains how to change the default black padding bars in FFmpeg to a custom color using hex codes. You will learn the correct syntax for the pad filter, how to format hex codes to avoid command-line errors, and see practical examples of how to apply custom-colored borders to your videos.

To change the padding color in FFmpeg, you need to use the pad filter and define the color parameter. By default, FFmpeg pads videos with black, but you can specify any custom color using hex codes in either the 0xRRGGBB or #RRGGBB format.

The Pad Filter Syntax

The basic syntax for the padding filter is:

-vf "pad=width:height:x:y:color"

Formatting Hex Codes in FFmpeg

FFmpeg accepts hex color codes in two primary ways:

  1. Using 0x Prefix (Recommended): This format (e.g., 0x336699) is highly recommended because it prevents command-line interpreters (like bash or PowerShell) from treating the # symbol as a comment or special character.
  2. Using # Prefix: If you prefer standard hex codes (e.g., #336699), you must wrap the color value or the entire filter string in quotes to prevent shell parsing errors.

Code Examples

Example 1: Centering a Video on a Custom Hex Background (0x format)

To pad an input video to a 1920x1080 canvas, center it, and set the padding bars to a custom blue (#336699 / 0x336699):

ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=0x336699" output.mp4

Example 2: Using the Standard Hex Format (#)

If you prefer to use the # symbol, ensure the hex code is wrapped in single quotes inside your filtergraph:

ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color='#336699'" output.mp4

Example 3: Adding Transparency (RGBA Hex)

You can also specify transparency by adding an alpha channel to the hex code (using 0xRRGGBBAA or #RRGGBBAA). To pad a video with a semi-transparent red background (50% opacity):

ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=0xFF000080" output.mp4