Generate Thumbnail Containers (Seek Preview Sprites) from Videos with Python and FFmpeg

Create YouTube-style thumbnail containers (sprite sheets of preview frames) and HLS video segments from your videos with vid2tc, a Python and FFmpeg tool.

What a thumbnail container is

When you hover over the progress bar on YouTube, a small preview of that moment appears. Those previews don’t come from the video itself. The player loads a thumbnail container: a single image holding a grid of small frames taken at regular intervals (for example, a 5×5 grid with one frame every few seconds). Showing the right tile of that grid is instant, so scrubbing feels smooth without downloading any video.

Thumbnail containers are also the core of my research on lightweight video summarization. Because they’re tiny compared to the video, a phone or edge device can analyze them to find the interesting parts of a long video.

Generate Thumbnail Containers (Seek Preview Sprites) from Videos with Python and FFmpeg

A thumbnail container (left) and how YouTube uses one to show seek previews (right).

This post shows how to generate thumbnail containers, plus HLS video segments, from your own videos with my tool vid2tc.

Setup

Clone the repository:

git clone https://github.com/iamgmujtaba/vid2tc.git
cd vid2tc

Create a conda environment and install the requirements:

conda create -n vid2tc python=3.8 -y
conda activate vid2tc
pip install -r requirements.txt

You also need FFmpeg installed and on your PATH. My HLS server guide covers installing it on Windows.

Options

python .\main.py -h

  -h, --help                         Show help
  -i INP_PATH, --inp_path INP_PATH   Folder with your input videos
  -o OUT_PATH, --out_path OUT_PATH   Folder for the output
  -s SEG_LEN,  --seg_len SEG_LEN     Video segment length in seconds
  -a AUDIO,    --audio AUDIO         Extract audio (True/False)
  -f FRAMES,   --frames FRAMES       Extract video frames (True/False)
  --thumb_width THUMB_WIDTH          Width of each thumbnail in pixels
  --thumb_height THUMB_HEIGHT        Height of each thumbnail in pixels
  --thumb_interval THUMB_INTERVAL    Seconds between thumbnails
  --thumb_container THUMB_CONTAINER  Grid size of each container (default: 5x5)

Example

Put your videos in an input folder and run:

python .\main.py -i .\input\ -o .\output\

The output folder will contain the thumbnail containers and the video segments for each video. To stream the segments, follow my HLS server guide.

The code is on GitHub.

Acknowledgement

The base code comes from Video Thumbnail Generator.