> ## 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 videos with AI

[![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-ai.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-ai.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-ai.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.

Create videos from text prompts or animate images using Google’s Gemini
Omni model.

## Problem

You need to generate video content programmatically for social media,
product demos, or creative applications.

## Solution

**What’s in this recipe:**

* Generate videos from text prompts
* Animate existing images into videos
* Store prompts and generated videos together

You generate videos with Google’s Gemini Omni model. Computed columns
store each generated video with its prompt. Updating the prompt
regenerates that row’s video.

### Setup

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

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import getpass
import os

if 'GEMINI_API_KEY' not in os.environ:
    os.environ['GEMINI_API_KEY'] = getpass.getpass(
        'Google AI Studio API Key: '
    )
```

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

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

<pre>
  Created directory 'video\_gen\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x12d80c190>
</pre>

### Generate videos from text prompts

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Create a table for text-to-video generation
videos = pxt.create_table(
    'video_gen_demo/text_to_video', {'prompt': pxt.String}
)

# Add computed column that generates videos
videos.add_computed_column(
    video=gemini.generate_video(
        videos.prompt,
        model='gemini-omni-1.1-flash',
        config={'aspect_ratio': '16:9', 'resolution': '720p'},
    )
)
```

<pre>
  Created table 'text\_to\_video'.
  Added 0 column values with 0 errors in 0.00 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Generate a video from a text prompt
videos.insert(
    [
        {
            'prompt': 'A serene mountain lake at sunrise with mist rising from the water'
        }
    ]
)

# View the result
videos.select(videos.prompt, videos.video).collect()
```

<pre>
  Inserted 1 row with 0 errors in 48.38 s (0.02 rows/s)
</pre>

### Animate images into videos

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Create a table for image-to-video generation
animated = pxt.create_table(
    'video_gen_demo/image_to_video',
    {'image': pxt.Image, 'description': pxt.String},
)

# Add computed column that animates images
animated.add_computed_column(
    video=gemini.generate_video(
        animated.description,
        images=[animated.image],
        model='gemini-omni-1.1-flash',
        config={'aspect_ratio': '9:16', 'resolution': '720p'},
    )
)
```

<pre>
  Created table 'image\_to\_video'.
  Added 0 column values with 0 errors in 0.00 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Animate an image
base_url = 'https://raw.githubusercontent.com/pixeltable/pixeltable/main/docs/resources/images'

animated.insert(
    [
        {
            'image': f'{base_url}/000000000030.jpg',
            'description': 'Beach scene.',
        }
    ]
)

# View the animated result
animated.select(animated.image, animated.video).collect()
```

<pre>
  Inserted 1 row with 0 errors in 37.17 s (0.03 rows/s)
</pre>

## Explanation

**Generation modes:**

**Gemini Omni model:**

**Tips:**

* Prompts work best when descriptive and specific
* Computed columns store generated videos; reading them does not repeat
  generation
* The prompt describes how to animate the reference images
* New rows automatically generate videos on insert

**Requirements:**

* Google AI Studio API key (set `GEMINI_API_KEY`); Gemini Omni requires
  the Gemini Developer API
* `pip install "google-genai>=2.22"`

## See also

* [Extract frames from
  videos](https://docs.pixeltable.com/howto/cookbooks/video/video-extract-frames.md) -
  Pull frames from generated videos
* [Add text
  overlays](https://docs.pixeltable.com/howto/cookbooks/video/video-add-text-overlay.md) -
  Add captions to videos


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