> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Generate thumbnails from videos

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/video/video-generate-thumbnails.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/video/video-generate-thumbnails.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/cookbooks/video/video-generate-thumbnails.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

Automatically create preview thumbnails from video files at specific
timestamps or intervals.

## Problem

You have video files that need preview thumbnails for galleries, search
results, or video players. Manually extracting frames doesn’t scale.

## Solution

**What’s in this recipe:**

* Extract thumbnail at a specific timestamp
* Generate multiple thumbnails per video
* Resize thumbnails to standard dimensions

You add computed columns that extract frames from videos. Thumbnails are
generated automatically when you insert new videos.

### Setup

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable
```

### Load videos

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
import pixeltable.functions as pxtf

# Create a fresh directory
pxt.drop_dir('thumbnail_demo', force=True)
pxt.create_dir('thumbnail_demo')
```

<pre>
  Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
  Created directory 'thumbnail\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x14d3a1990>
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Create table for videos
videos = pxt.create_table('thumbnail_demo/videos', {'video': pxt.Video})
```

<pre>
  Created table 'videos'.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Insert sample videos from public S3 bucket
s3_prefix = 's3://multimedia-commons/'
video_paths = [
    'data/videos/mp4/ffe/ffb/ffeffbef41bbc269810b2a1a888de.mp4',
    'data/videos/mp4/ffe/feb/ffefebb41485539f964760e6115fbc44.mp4',
]

videos.insert([{'video': s3_prefix + path} for path in video_paths])
```

<pre>
  Inserting rows into \`videos\`: 2 rows \[00:00, 382.20 rows/s]
  Inserted 2 rows with 0 errors.
  2 rows inserted, 4 values computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View videos
videos.collect()
```

### Extract thumbnail at timestamp

Extract a single frame at a specific time (e.g., 1 second into the
video):

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Extract frame at 1 second as thumbnail
videos.add_computed_column(
    thumbnail=pxtf.video.extract_frame(videos.video, timestamp=1.0)
)
```

<pre>
  Added 2 column values with 0 errors.
  2 rows updated, 2 values computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View thumbnails
videos.select(videos.video, videos.thumbnail).collect()
```

### Resize thumbnails

Create standard-sized thumbnails for consistent display:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Resize thumbnail to 320x180 (16:9 aspect ratio)
videos.add_computed_column(
    thumbnail_small=videos.thumbnail.resize((320, 180))
)
```

<pre>
  Added 2 column values with 0 errors.
  2 rows updated, 2 values computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View resized thumbnails with dimensions
videos.select(
    videos.thumbnail_small,
    videos.thumbnail_small.width,
    videos.thumbnail_small.height,
).collect()
```

### Multiple thumbnails with `frame_iterator`

For preview strips or timeline thumbnails, use `frame_iterator` to
extract multiple frames:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Create a view with frames extracted at 0.5 fps (one frame every 2 seconds)
frames = pxt.create_view(
    'thumbnail_demo/frames',
    videos,
    iterator=pxtf.video.frame_iterator(videos.video, fps=0.5),
)
```

<pre>
  Inserting rows into \`frames\`: 17 rows \[00:00, 9736.88 rows/s]
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View extracted frames (multiple per video)
frames.select(frames.frame, frames.pos).head(10)
```

## Explanation

**Thumbnail extraction methods:**

**Common thumbnail sizes:**

## See also

* [Extract frames from
  videos](https://docs.pixeltable.com/howto/cookbooks/video/video-extract-frames.md) -
  Detailed frame extraction guide
* [Load media from
  S3](https://docs.pixeltable.com/howto/cookbooks/data/data-import-s3.md) -
  Import videos from cloud storage
* [Transform images with
  PIL](https://docs.pixeltable.com/howto/cookbooks/images/img-pil-transforms.md) -
  Resize and crop images


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.