Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
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 Veo 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
Use Google’s Veo model to generate videos. Videos are cached—regeneration only happens if the prompt changes.

Setup

%pip install -qU pixeltable google-genai
import os
import getpass

if 'GEMINI_API_KEY' not in os.environ:
    os.environ['GEMINI_API_KEY'] = getpass.getpass('Google AI Studio API Key: ')
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')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘video_gen_demo’.
<pixeltable.catalog.dir.Dir at 0x14b2a9050>

Generate videos from text prompts

# 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_videos(
        videos.prompt,
        model='veo-2.0-generate-001'
    )
)
Created table ‘text_to_video’.
Added 0 column values with 0 errors.
No rows affected.
# 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()
Inserting rows into `text_to_video`: 1 rows [00:00, 190.68 rows/s]
Inserted 1 row with 0 errors.

Animate images into videos

# 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_videos(
        image=animated.image,
        model='veo-2.0-generate-001'
    )
)
Created table ‘image_to_video’.
Added 0 column values with 0 errors.
No rows affected.
# 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()
Inserting rows into `image_to_video`: 1 rows [00:00, 291.88 rows/s]
Inserted 1 row with 0 errors.

Explanation

Generation modes:
Veo model options:
Tips:
  • Prompts work best when descriptive and specific
  • Generated videos are cached - same prompt returns cached result
  • Image-to-video preserves the composition of the input image
  • New rows automatically generate videos on insert
Requirements:
  • Google AI Studio API key (set GEMINI_API_KEY)
  • pip install google-genai

See also