Configure FFmpeg Tile Filter Grid Margin and Padding
This article provides a quick guide on how to use the FFmpeg
tile video filter to combine multiple video frames into a
single grid. You will learn how to define the grid layout (columns and
rows), set the outer margin around the grid, adjust the internal padding
between individual tiles, and customize the background color.
The FFmpeg tile filter uses a specific syntax to control
the layout, margins, and padding of the generated grid. The most
straightforward way to configure these settings is by using named
parameters in the filter string:
tile=layout=ColsxRows:margin=Pixels:padding=Pixels:color=ColorName
Key Parameters Explained
layout: Defines the grid size using the formatColumnsxRows(e.g.,3x2creates a grid with 3 columns and 2 rows).margin: Sets the outer border around the entire grid in pixels. By default, this is 0.padding: Sets the inner spacing between individual tiles in pixels. By default, this is 0.color: Specifies the background color for the margin and padding areas. You can use standard color names (likeblack,white,red) or hex codes (like0x00FF00). The default color is white.
Example Configurations
1. Basic Grid with Margin and Padding
To create a 4x3 grid with a 10-pixel outer margin, 5-pixel inner padding, and a black background, use the following command:
ffmpeg -i input.mp4 -vf "tile=layout=4x3:margin=10:padding=5:color=black" output.png2. Position-Based Syntax
You can also specify the parameters without named keys by keeping
them in the exact order: tile=layout:margin:padding. The
command below produces a 3x3 grid with a 20-pixel margin and a 10-pixel
padding:
ffmpeg -i input.mp4 -vf "tile=3x3:20:10" output.png3. Creating a Video Contact Sheet
If you want to generate a single image showing a grid of frames
sampled at regular intervals, combine the select filter
with the tile filter. This command samples one frame every
10 seconds and arranges them into a 5x5 grid with a 15-pixel margin and
8-pixel padding:
ffmpeg -i input.mp4 -vf "select='not(mod(n,300))',scale=320:-1,tile=layout=5x5:margin=15:padding=8:color=gray" -vframes 1 output.png