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
- Builds on
- 33 concepts →
- Quiz
- 4 questions ↓
Read first
Diffusion TransformersThis leads to
—The full path from zero — 33 concepts before this one
- What Is AI?
- Probability Basics
- Vectors
- Derivatives and Slopes
- How Machines Learn
- Probability Distributions
- Partial Derivatives and Gradients
- Matrices and Matrix Multiplication
- The Chain Rule
- Dot Product, Norms and Similarity
- Supervised, Unsupervised and Reinforcement Learning
- Gradient Descent
- Supervised Learning
- Linear Regression
- The Perceptron
- Logistic Regression
- Neural Networks
- Convolutional Neural Networks
- Recurrent Neural Networks
- Backpropagation
- Activation Functions
- What Generative Models Do
- Vanishing and Exploding Gradients
- Normalization Layers: BatchNorm and LayerNorm
- Diffusion Models
- LSTMs and GRUs
- Residual Connections
- Sequence-to-Sequence Models
- Attention
- Self-Attention and Multi-Head Attention
- Positional Encodings
- The Transformer
- Diffusion Transformers
- 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:
- Compress the video with a 3-D autoencoder that shrinks space and time.
- Cut the compressed block into small spacetime patches, little cubes a few latent pixels wide and one or a few latent frames deep.
- Denoise the whole sequence of patches with a diffusion Transformer, conditioned on the text prompt (and optionally a first image).
- Decode the clean latent back into frames.
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 frames of pixels with 3 colours: million numbers.
- The latent has frames of positions with 16 channels: 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 (one latent frame, 2×2 positions), the number of tokens is:
where are the latent's frames, height and width, and the patch size along each. Each token carries 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.
Hence the engineering behind every video model: memory-efficient attention kernels that never store the full 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:
- Train on images first, a huge and cheap source of visual knowledge, treated as one-frame videos.
- Train jointly on images and short, low-resolution videos.
- 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
- Music and Voice Generation: the sound side, now often generated jointly with video.
- Video Understanding: the reverse task, reading and describing videos, which also supplies the captions video generators train on.
- Model-Based RL and World Models: learned world models used for planning and for training agents.
- Multimodal LLMs: models that take video in and, increasingly, produce it.
- Deepfakes and Misinformation: detection, watermarking and provenance.
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
- Use
video_tokensto 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?- Modify the patchify code to use spacetime patches (two latent frames per patch). How many tokens and how many numbers per token result for the 5-second clip?
- 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, 2as well, and remember that 31 is odd. Real models handle the extra first frame separately.
Learn more
Hand-picked courses, books, videos and tutorials for going deeper. See all resources →
Diffusion Models for Video Generation
A survey of how image diffusion is extended to video: architectures, temporal layers, training on images and videos, and adapting image models.
Video generation models as world simulators
OpenAI's technical report on Sora: spacetime patches of compressed video, a diffusion Transformer, and emergent 3-D consistency and its failures.
Movie Gen: A Cast of Media Foundation Models
A detailed technical report on a 30-billion-parameter flow-matching Transformer for video, plus video editing and synchronised audio.
Video Diffusion Models
Extends the image diffusion U-Net to video with space-time factorised attention and joint image-video training.
Diffusers documentation
The official guide to the diffusers library: pipelines for text-to-image, img2img, inpainting, ControlNet, LoRA loading, schedulers and training scripts.
Scalable Diffusion Models with Transformers
DiT: replacing the diffusion U-Net with a Transformer.
Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/generative/video-generation.md