◆ AI All-in-One

Level 3 In-Depth AI · Generative AI

Video Generation

Video generators extend latent diffusion and diffusion Transformers from still images to moving ones. A 3-D autoencoder compresses the clip, it is cut into spacetime patches, and a Transformer denoises all frames together so that objects stay consistent over time. This chapter covers how they work, why they are so expensive, the "world simulator" idea, and where they still fail.

Level
●●●●● Intermediate
Reading
13 min
To learn it well
50 minutes to read, an hour to practise
↗ Plan a path here

Read first

Diffusion Transformers

This leads to

—
The full path from zero — 33 concepts before this one
  1. What Is AI?
  2. Probability Basics
  3. Vectors
  4. Derivatives and Slopes
  5. How Machines Learn
  6. Probability Distributions
  7. Partial Derivatives and Gradients
  8. Matrices and Matrix Multiplication
  9. The Chain Rule
  10. Dot Product, Norms and Similarity
  11. Supervised, Unsupervised and Reinforcement Learning
  12. Gradient Descent
  13. Supervised Learning
  14. Linear Regression
  15. The Perceptron
  16. Logistic Regression
  17. Neural Networks
  18. Convolutional Neural Networks
  19. Recurrent Neural Networks
  20. Backpropagation
  21. Activation Functions
  22. What Generative Models Do
  23. Vanishing and Exploding Gradients
  24. Normalization Layers: BatchNorm and LayerNorm
  25. Diffusion Models
  26. LSTMs and GRUs
  27. Residual Connections
  28. Sequence-to-Sequence Models
  29. Attention
  30. Self-Attention and Multi-Head Attention
  31. Positional Encodings
  32. The Transformer
  33. Diffusion Transformers
  34. Video Generation

Read them roughly in this order. See it on the concept map →

Why it matters

In February 2024 OpenAI showed Sora: minute-long, high-definition clips from text prompts, with moving cameras, reflections and crowds. Within a year, several systems could make short clips that most viewers can't tell from filmed footage at a glance. These included Google's Veo, Runway's Gen-3 and later models, Kuaishou's Kling, Meta's Movie Gen, and open models such as HunyuanVideo and Wan. By 2025 the leading systems (Veo 3, Sora 2) also generated synchronised sound and dialogue. Products come and go quickly: OpenAI shut down the Sora app in April 2026 and its API in September 2026.

Video generation is already used for advertising, previsualisation in film, social media content, game prototyping and education. It also raises the sharpest misuse concerns of any generative technology (Deepfakes and Misinformation). And some researchers see it as a route to world models: systems that have learned how the physical world behaves by watching it.

Technically, video generation is not a new kind of model. It is Latent Diffusion and Stable Diffusion with a diffusion Transformer, applied to a three-dimensional block of data instead of a two-dimensional one. What makes it hard is scale and consistency.

The intuition

Why not just generate frames one at a time with an image model? Try it and you get flicker. Each frame is a fresh, independent sample, so the character's shirt changes colour, the background jumps, and objects pop in and out. Even if you start each frame from the previous one, small errors pile up and the video drifts.

A video is not a stack of independent pictures. It is one object extended in time. So modern models treat it as one block of data, height × width × time, and generate the whole block at once. Every denoising step updates all frames together, and attention lets a patch in frame 50 look at the same object in frame 1. Consistency then isn't something enforced afterwards. It comes from denoising the whole clip jointly.

The recipe, as OpenAI's Sora report described it and as open models implement it:

  1. Compress the video with a 3-D autoencoder that shrinks space and time.
  2. Cut the compressed block into small spacetime patches, little cubes a few latent pixels wide and one or a few latent frames deep.
  3. Denoise the whole sequence of patches with a diffusion Transformer, conditioned on the text prompt (and optionally a first image).
  4. Decode the clean latent back into frames.
Video121 frames, 1280 × 720 × 3 5 s at 24 fps:≈ 335 million numbers 3-D VAE Latent video31 × 90 × 160 × 16 time ÷ 4, height and width ÷ 8≈ 7.1 million numbers (47× fewer) patchify Spacetime tokenseach 1 × 2 × 2 × 16 = 64 numbers 31 × 45 × 80 = 111,600 tokens … time → A diffusion Transformer denoises all 111,600 tokens together, attending across space and time. Because every frame is generated jointly, objects keep their identity and position from frame to frame. Example settings typical of recent open models (4× time and 8× space compression, 16 latent channels, 1 × 2 × 2 patches).
Fig. 1 A 5-second 720p clip (121 frames) is compressed by a 3-D VAE (4× in time, 8× in each spatial direction) into a 31 × 90 × 160 × 16 latent, 47 times fewer numbers. Cutting it into 1 × 2 × 2 spacetime patches gives 111,600 tokens, which a diffusion Transformer denoises together.

Key idea A video generator is a latent diffusion Transformer over spacetime patches. Generating all frames jointly, with attention across time, is what keeps objects consistent. The price is enormous token counts: a few seconds of HD video is over 100,000 tokens.

How it works

1. The video autoencoder

An image Variational Autoencoders compresses 8× in each spatial direction. A video autoencoder also compresses time, typically 4×, using 3-D convolutions. Neighbouring frames are nearly identical, so time compresses well. Many recent ones are causal: the first frame is encoded on its own, and each later group of 4 frames is encoded using only the past. The same model can then encode a still image as a one-frame video, which lets models train on images and videos together.

Worked example (settings typical of 2025 open models):

  • A 5-second clip at 24 frames per second has 5×24+1=1215 \times 24 + 1 = 121 frames of 1280×7201280 \times 720 pixels with 3 colours: 121×1280×720×3≈335121 \times 1280 \times 720 \times 3 \approx 335 million numbers.
  • The latent has 1+120/4=311 + 120/4 = 31 frames of 720/8×1280/8=90×160720/8 \times 1280/8 = 90 \times 160 positions with 16 channels: 31×90×160×16≈7.131 \times 90 \times 160 \times 16 \approx 7.1 million numbers, about 47 times smaller.

2. Spacetime patches

As in an image DiT, the latent is cut into patches, but now the patches have a time extent too. With patches of 1×2×21 \times 2 \times 2 (one latent frame, 2×2 positions), the number of tokens is:

N=T′pt⋅H′ph⋅W′pw=311⋅902⋅1602=111,600N = \frac{T'}{p_t} \cdot \frac{H'}{p_h} \cdot \frac{W'}{p_w} = \frac{31}{1} \cdot \frac{90}{2} \cdot \frac{160}{2} = 111{,}600

where T′,H′,W′T', H', W' are the latent's frames, height and width, and pt,ph,pwp_t, p_h, p_w the patch size along each. Each token carries 1×2×2×16=641 \times 2 \times 2 \times 16 = 64 numbers, projected to the model width. Positions are encoded in three dimensions (often 3-D rotary embeddings, Positional Encodings), so the model knows when as well as where each patch is.

The Sora report stressed a practical benefit: because a clip is just a variable-length list of tokens, one model can train on videos of any duration, resolution and aspect ratio (vertical phone videos, widescreen film, square clips) without cropping them all to one shape.

3. Attention across space and time

The Transformer must relate every patch to the others: the same object in other frames (time) and other parts of the scene in the same frame (space). There are two main designs.

  • Factorised attention. Alternate spatial attention (within each frame) with temporal attention (each position across frames). This is much cheaper. It was used by early video diffusion models (Ho and colleagues, 2022) and by adaptations of image models that add temporal layers to a pretrained image U-Net, such as Stable Video Diffusion.
  • Full spacetime attention. Every token attends to every other token. This is better at long-range motion and consistency, and it is used by most large 2024–2025 models, but the cost grows with the square of the token count.
Clip lengthSpacetime tokens (720p)Attention cost vs a 5 s clip 2 s49 frames 46,800 0.2× 5 s121 frames 111,600 1.0× 10 s241 frames 219,600 3.9× 20 s481 frames 435,600 15× 60 s1441 frames 1,299,600 136× Tokens grow in proportion to length. Full self-attention compares every token with every other,so its cost grows with the square of the length.Same settings as the previous figure: 24 fps, 1280 × 720, 4× time and 8× space compression, 1 × 2 × 2 patches.
Fig. 2 How sequence length and attention cost grow with clip length, at 720p with the settings of the previous figure. Doubling the length doubles the tokens and quadruples the cost of full attention. A one-minute clip has 1.3 million tokens and costs about 136 times as much attention compute as a 5-second clip.

Hence the engineering behind every video model: memory-efficient attention kernels that never store the full N×NN \times N matrix, splitting one sequence across many GPUs, generating at low resolution and then upscaling, and producing long videos as overlapping chunks that are stitched together.

4. Training and conditioning

Training uses exactly the objectives you have seen: noise prediction (Diffusion Models) or, increasingly, Normalizing Flows and Flow Matching (Movie Gen and several open models). The text condition comes in through cross-attention or joint text–video attention, as in MM-DiT. Typical training stages:

  1. Train on images first, a huge and cheap source of visual knowledge, treated as one-frame videos.
  2. Train jointly on images and short, low-resolution videos.
  3. Increase resolution and duration, and fine-tune on a smaller set of high-quality, well-captioned clips.

Captions matter enormously. Most web video has poor or no descriptions, so labs use a vision-language model to write detailed captions for every training clip. The Sora report describes this "re-captioning", borrowed from DALL·E 3. At inference, a language model often expands the user's short prompt into a detailed one.

Image-to-video adds a first frame (or first and last frames) as an extra condition. The model then animates a given picture, which is the most common professional workflow because it fixes the look and the characters in advance.

Movie Gen's report gives a sense of scale: a 30-billion-parameter flow-matching Transformer that generates up to 16 seconds at 16 frames per second, with a separate 13-billion-parameter model for synchronised audio. Sizes of closed models are mostly undisclosed.

"World simulators" and their limits

OpenAI titled its Sora report Video generation models as world simulators. It described abilities that emerged from scale without being built in: 3-D consistency as the camera moves, objects that persist when briefly hidden, and simple interactions such as a bite leaving a mark on food. The argument is that predicting realistic video requires learning something about geometry, physics and behaviour. That makes video models candidates for world models, systems that can predict what happens next in an environment and could be used to train robots or agents (Model-Based RL and World Models). Google DeepMind's Genie models pursue the interactive version: generated worlds that respond to user actions in real time.

The same reports are frank about failures, which were common in 2025-era models and still occur:

  • Physics. Liquids, collisions and breaking glass often behave wrongly. Objects merge, multiply, or appear from nowhere.
  • Cause and effect. Actions don't always leave lasting results. A bitten cookie can be whole again a moment later.
  • Long-range consistency. Characters' faces, clothes and surroundings drift over longer clips and across cuts.
  • Counting, text and hands, as with image models.
  • Cost and speed. Generating seconds of HD video can take minutes on large GPUs.

A model that makes plausible-looking video has not necessarily learned correct physics. It has learned what looks right in its training data. Whether scaling up will close that gap is an open research question.

In code

The sizes in this chapter are easy to check. This runnable script counts spacetime tokens for clips of different lengths, estimates the memory a naive attention matrix would need, and patchifies a latent video tensor exactly as a video DiT's first layer does:

import torch

def video_tokens(seconds, fps=24, height=720, width=1280, t_down=4, s_down=8, channels=16, patch=(1, 2, 2)):
    frames = seconds * fps + 1                       # causal video VAEs keep the first frame separately
    lt, lh, lw = 1 + (frames - 1) // t_down, height // s_down, width // s_down
    pt, ph, pw = patch
    return frames, (lt, lh, lw, channels), (lt // pt) * (lh // ph) * (lw // pw)

for s in [2, 5, 10, 60]:
    frames, latent, n = video_tokens(s)
    attn_gb = n * n * 2 / 1e9                        # one bf16 attention matrix for one head, if stored
    print(f"{s:3d} s: {frames:5d} frames -> latent {latent} -> {n:>9,} tokens, "
          f"attention matrix {attn_gb:,.0f} GB per head")

# Patchify a small latent video into spacetime tokens: (T, H, W, C) -> (tokens, 1*2*2*C)
z = torch.randn(31, 90, 160, 16)                    # 5 s of 720p video, after the VAE
T, H, W, C = z.shape
tokens = (z.reshape(T, H // 2, 2, W // 2, 2, C)
            .permute(0, 1, 3, 2, 4, 5)               # group each 2x2 spatial patch together
            .reshape(T * (H // 2) * (W // 2), 2 * 2 * C))
print(tokens.shape)

#   2 s:    49 frames -> latent (13, 90, 160, 16) ->    46,800 tokens, attention matrix 4 GB per head
#   5 s:   121 frames -> latent (31, 90, 160, 16) ->   111,600 tokens, attention matrix 25 GB per head
#  10 s:   241 frames -> latent (61, 90, 160, 16) ->   219,600 tokens, attention matrix 96 GB per head
#  60 s:  1441 frames -> latent (361, 90, 160, 16) -> 1,299,600 tokens, attention matrix 3,378 GB per head
# torch.Size([111600, 64])

No GPU has 25 GB to spare for every attention head in every layer, which is why fused attention kernels that never store the matrix are essential, and why a minute of HD video is still out of reach for a single pass.

Generating a real clip with an open model through diffusers looks like this (it needs a multi-gigabyte download and a large GPU, so it is not run here; written against the 2025 API):

import torch
from diffusers import AutoencoderKLWan, WanPipeline
from diffusers.utils import export_to_video

model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16).to("cuda")

frames = pipe(
    prompt="a red fox trotting through fresh snow at dawn, low tracking shot",
    negative_prompt="blurry, distorted, flickering",
    height=480, width=832, num_frames=81, guidance_scale=5.0,
).frames[0]
export_to_video(frames, "fox.mp4", fps=16)            # 81 frames at 16 fps ≈ 5 seconds

Common pitfalls

  • Asking for too much in one clip. Several actions, several characters and camera moves in one prompt usually fail. Generate short shots with one action each and edit them together.
  • Expecting continuity across clips. Separate generations don't share characters or sets. Use image-to-video from a consistent reference frame, or character-reference features where the tool offers them.
  • Ignoring frame rate and length limits. Models are trained on specific lengths and rates. Asking for longer clips without a chunking method degrades quality.
  • Judging from one sample. Video outputs vary a lot between seeds. Generate several and pick.
  • Underestimating cost. Each clip can take minutes of GPU time. Prototype at low resolution and few steps.

Watch out Realistic video of real people saying or doing things they never did is the most harmful kind of synthetic media. Don't generate it without consent. Label synthetic video clearly, keep provenance metadata (C2PA Content Credentials, and invisible watermarks such as Google's SynthID where present), and know the law: the EU AI Act requires deepfakes to be disclosed, and many jurisdictions now criminalise non-consensual sexual deepfakes. See Deepfakes and Misinformation and AI Regulation and Governance.

Where it leads

A bit of history

Early neural video generation used GANs and autoregressive models and managed only tiny, blurry, seconds-long clips (VideoGAN, 2016; later DVD-GAN). In 2022 diffusion arrived. Video Diffusion Models (Ho and colleagues, April) extended the image U-Net with temporal attention. Later that year Meta's Make-A-Video and Google's Imagen Video and Phenaki showed text-to-video, and Runway released Gen-1 and Gen-2 in 2023. Stable Video Diffusion (November 2023) added temporal layers to an image model and released the weights.

The step change came with diffusion Transformers. OpenAI's Sora (announced February 2024) generated up to a minute of 1080p video and popularised spacetime patches. Kling, Gen-3, Veo and Movie Gen followed in 2024, then open models such as HunyuanVideo (December 2024) and Wan (2025). In 2025 Veo 3 and Sora 2 added generated speech, music and sound effects in sync with the picture. Video generation is moving fast. Treat any specific capability or ranking as a snapshot.

Try it

  1. Use video_tokens to find the longest 1080p clip (1920 × 1080) that stays under 111,600 tokens with the same compression. Then change the spatial patch to 4 × 4. How long can the clip be now, and what would you expect to lose?
  2. Modify the patchify code to use 2×2×22 \times 2 \times 2 spacetime patches (two latent frames per patch). How many tokens and how many numbers per token result for the 5-second clip?
  3. Find a published AI-generated video and list three physical or consistency errors in it. Which of the failure types above do they belong to?

Hint for 2: reshape time as T // 2, 2 as well, and remember that 31 is odd. Real models handle the extra first frame separately.

Check your understanding

4 quick questions. Pick an answer to see whether you were right and why. Your best score is saved on this device.

  1. Why does generating a video frame by frame with an image model usually fail?

  2. A 5-second 720p latent of 31 × 90 × 160 × 16 is cut into 1 × 2 × 2 spacetime patches. How many tokens is that?

  3. You double a clip's length from 5 to 10 seconds with full spacetime attention. What happens to attention cost?

  4. A marketing team needs the same character in several short shots. What workflow does the chapter recommend?

Finished this chapter?

Learn more

Hand-picked courses, books, videos and tutorials for going deeper. See all resources →

Article

Diffusion Models for Video Generation

Lilian Weng · 2024 · Advanced · Free

A survey of how image diffusion is extended to video: architectures, temporal layers, training on images and videos, and adapting image models.

Article

Video generation models as world simulators

OpenAI · 2024 · Intermediate · Free

OpenAI's technical report on Sora: spacetime patches of compressed video, a diffusion Transformer, and emergent 3-D consistency and its failures.

Paper

Video Diffusion Models

Ho et al. (Google) · 2022 · Advanced · Free

Extends the image diffusion U-Net to video with space-time factorised attention and joint image-video training.

Docs

Diffusers documentation

Hugging Face · Intermediate · Free

The official guide to the diffusers library: pipelines for text-to-image, img2img, inpainting, ControlNet, LoRA loading, schedulers and training scripts.

Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/generative/video-generation.md