How to Create a 5x5 Video Thumbnail Grid with FFmpeg

Creating a 5x5 thumbnail grid (often called a contact sheet) from a 2-hour movie is a quick way to preview and index video content using FFmpeg. This guide provides the exact command-line syntax required to extract 25 evenly spaced frames across a 120-minute video, scale them to a manageable size, and assemble them into a single 5x5 image using FFmpeg’s fps, scale, and tile video filters.

The Command

To generate a 5x5 thumbnail grid from a 2-hour (7,200-second) movie, open your terminal and run:

ffmpeg -i input.mp4 -vf "fps=1/288,scale=320:-1,tile=5x5" -frames:v 1 output.jpg

How the Calculation Works

A 5x5 grid requires exactly 25 individual frames (\(5 \times 5 = 25\)).

To distribute these 25 frames evenly across a 2-hour movie:

  1. Convert the duration to seconds: \(2 \text{ hours} \times 60 \text{ minutes} \times 60 \text{ seconds} = 7,200 \text{ seconds}\).
  2. Divide the total duration by the number of desired frames: \(7,200 / 25 = 288 \text{ seconds}\).

Setting the frame rate filter to fps=1/288 extracts one frame every 288 seconds (4 minutes and 48 seconds).

Command Breakdown

  • -i input.mp4: Defines the path to your source video file.
  • -vf "...": Applies the video filter chain:
    • fps=1/288: Samples one frame every 288 seconds to obtain 25 frames over the 2-hour runtime.
    • scale=320:-1: Resizes each individual thumbnail to 320 pixels wide while automatically maintaining the original aspect ratio for the height. Scaling down is recommended to prevent creating an excessively large output image.
    • tile=5x5: Arranges the captured frames into a grid of 5 columns and 5 rows.
  • -frames:v 1: Stops FFmpeg after rendering the first completed tiled sheet.
  • output.jpg: The filename and format for the final thumbnail sheet.

Adding Margins and Padding (Optional)

To improve readability, you can add borders between the thumbnails and background colors using the extended parameters of the tile filter:

ffmpeg -i input.mp4 -vf "fps=1/288,scale=320:-1,tile=5x5:padding=4:margin=4:color=black" -frames:v 1 output.jpg
  • padding=4: Adds a 4-pixel space between adjacent thumbnails.
  • margin=4: Adds a 4-pixel border around the outer edges of the grid.
  • color=black: Sets the color of the padding and margins (supports common color names or hex codes like 0x000000).