Change FFmpeg Tile Filter Background Color
Generating a video contact sheet or image grid using FFmpeg’s
tile filter is a highly efficient way to preview video
files, but the default black background may not suit your needs. This
guide explains how to customize the background color of your generated
contact sheet using the color option within the
tile filter, complete with direct, practical examples.
Using the
color Option in the tile Filter
The tile filter accepts a color parameter
that allows you to define the background color of the margins, padding,
and any empty grid slots. You can specify colors by their names (e.g.,
white, red, blue) or by
hexadecimal color values (e.g., 0xFFFFFF or
#FFFFFF).
Basic Command Syntax
To change the background color, append the color option
to your tile filter chain:
ffmpeg -i input.mp4 -vf "tile=layout=3x3:color=white" output.pngIn this command: * tile=layout=3x3: Creates a 3-column,
3-row grid. * color=white: Sets the background color of any
blank spaces in the grid to white.
Adding Padding, Margins, and Custom Colors
By default, tiles are placed directly next to each other. To make the
background color visible between the thumbnails, you need to add
padding (space between tiles) and margin
(outer border around the grid).
Example: White Background with Padding
The following command extracts frames, scales them down, and places them into a grid with a white background and a 10-pixel border/padding:
ffmpeg -i input.mp4 -vf "select=not(mod(n\,100)),scale=320:-1,tile=3x3:padding=10:margin=10:color=white" -vframes 1 output.pngselect=not(mod(n\,100)): Selects every 100th frame of the video.scale=320:-1: Resizes each thumbnail to a width of 320 pixels while maintaining the aspect ratio.padding=10: Adds 10 pixels of space between the individual thumbnails.margin=10: Adds a 10-pixel border around the outer edge of the entire sheet.color=white: Fills the padding and margin spaces with white.
Example: Using Hexadecimal Color Codes
If you want a specific custom color (for example, a light gray background), you can use a hexadecimal color code:
ffmpeg -i input.mp4 -vf "tile=3x3:padding=10:margin=10:color=0xF0F0F0" output.pngSetting a Transparent Background
If you are exporting to a format that supports transparency (such as PNG) and want to overlay the contact sheet onto another design, you can make the background transparent.
To do this, use a hex value with an alpha channel (RGBA) or use the
color name transparent:
ffmpeg -i input.mp4 -vf "tile=3x3:padding=10:margin=10:color=transparent" output.pngAlternatively, you can write this with a hex code and alpha value
(e.g., 0x000000@0 for transparent black):
ffmpeg -i input.mp4 -vf "tile=3x3:padding=10:margin=10:color=black@0" output.png