> ## 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.

# Add text overlays to 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-add-text-overlay.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-add-text-overlay.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-add-text-overlay.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.

Burn text, captions, or watermarks directly into video files.

## Problem

You need to add text to videos—captions, watermarks, titles, or dynamic
labels. Manual video editing doesn’t scale for batch processing.

## Solution

**What’s in this recipe:**

* Add simple text overlays
* Create styled captions with backgrounds
* Position text with alignment options
* Crop a rectangular region from a video

Use `video.overlay_text()` to burn text into videos with full control
over styling and position, and `video.crop()` to extract a rectangular
region.

### Setup

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

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

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

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

### Load sample videos

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

# Insert a sample video
videos.insert(
    [
        {
            'video': 's3://multimedia-commons/data/videos/mp4/ffe/ffb/ffeffbef41bbc269810b2a1a888de.mp4',
            'title': 'Sample Video',
        }
    ]
)
```

<pre>
  Created table 'videos'.
  Inserted 1 row with 0 errors in 3.21 s (0.31 rows/s)
  1 row inserted.
</pre>

### Add a simple text overlay

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add a simple watermark in the corner
videos.add_computed_column(
    watermarked=videos.video.overlay_text(
        'My Brand',
        font_size=24,
        color='white',
        opacity=0.7,
        horizontal_align='right',
        horizontal_margin=20,
        vertical_align='top',
        vertical_margin=20,
    )
)
```

<pre>
  Added 1 column value with 0 errors in 1.25 s (0.80 rows/s)
  1 row updated.
</pre>

### Add YouTube-style captions

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add a caption with a semi-transparent background box
videos.add_computed_column(
    captioned=videos.video.overlay_text(
        'This is a sample caption',
        font_size=32,
        color='white',
        box=True,  # Add background box
        box_color='black',
        box_opacity=0.8,
        box_border=[6, 14],  # Padding: [top/bottom, left/right]
        horizontal_align='center',
        vertical_align='bottom',
        vertical_margin=70,  # Distance from bottom
    )
)
```

<pre>
  Added 1 column value with 0 errors in 1.08 s (0.92 rows/s)
  1 row updated.
</pre>

### Add dynamic titles from table columns

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add video title as an overlay (dynamic per video)
videos.add_computed_column(
    titled=videos.video.overlay_text(
        videos.title,  # Use the title column!
        font_size=48,
        color='yellow',
        opacity=1.0,
        horizontal_align='center',
        vertical_align='top',
        vertical_margin=30,
    )
)
```

<pre>
  Added 1 column value with 0 errors in 1.15 s (0.87 rows/s)
  1 row updated.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View all versions
videos.select(
    videos.title,
    videos.video,
    videos.watermarked,
    videos.captioned,
    videos.titled,
).collect()
```

### Crop a region from a video

Use `video.crop()` to extract a rectangular region from a video. This is
useful for focusing on a specific area of interest, removing borders, or
preparing clips for object-specific analysis.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Crop using xywh format (default): [x, y, width, height]
videos.add_computed_column(cropped=videos.video.crop([100, 50, 320, 240]))

# Crop using xyxy format (common in object detection pipelines):
# videos.add_computed_column(
#     cropped_xyxy=videos.video.crop([100, 50, 420, 290], bbox_format='xyxy')
# )
```

<pre>
  Added 1 column value with 0 errors in 0.56 s (1.78 rows/s)
  1 row updated.
</pre>

## Explanation

**Positioning options:**

**Styling options:**

**Background box options:**

**Requirements:**

* FFmpeg must be installed and in PATH

## See also

* [Generate
  thumbnails](https://docs.pixeltable.com/howto/cookbooks/video/video-generate-thumbnails.md) -
  Create preview images
* [Detect scene
  changes](https://docs.pixeltable.com/howto/cookbooks/video/video-scene-detection.md) -
  Find cuts and transitions


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