8.7Video generation basics
A video is an image with a time axis. Compress it in space and time, cut it into spacetime patches, and a diffusion transformer can generate it, if you can afford the attention bill.
From one frame to many
A 5-second clip at 24 frames per second is 120 images. You could generate each one with an image model, but you’d get 120 unrelated pictures: the character’s shirt changes color, the background jumps, the ball teleports. The defining challenge of video is that every frame must agree with every other frame: same objects, same lighting, motion that obeys something like physics.
Early approaches took a pretrained image model and inserted extra layers that attend across frames. That worked for short, wobbly clips. The breakthrough came from treating video as what it is, a 3D block of data, and generating the whole block at once with a Transformer. OpenAI’s technical report on Sora (February 2024), titled Video generation models as world simulators, popularized that recipe, and open models such as CogVideoX, HunyuanVideo and Wan followed with published details.
Everything in this lesson builds on latent diffusion and Diffusion Transformers & flow matching. The new ingredient is time.
Take a flipbook and glue all its pages into a solid block. Now saw the block into small cubes: each cube holds a little square of the picture across a few consecutive pages. A cube with a ball in it shows a tiny clip of the ball moving.
The flipbook is the video, gluing it into a block is treating time as a third dimension, and each cube is a spacetime patch, one token. The generator’s job is to arrange thousands of these cubes so that, flipped through, they tell one continuous story. Bigger cubes mean fewer pieces to coordinate but coarser detail; tiny cubes mean exquisite detail and a staggering number of pieces that all have to agree.
Step 1: compress space and time with a 3D VAE
Raw video is enormous: 5 seconds of 720p is about 335 million numbers. Image models shrink images with a VAE (see Autoencoders, VAEs & latent space); video models use a 3D VAE that also compresses along time, since neighboring frames are highly redundant.
CogVideoX and HunyuanVideo both report VAEs that compress 4× in time and 8×8 in space; HunyuanVideo’s latent has 16 channels. So 121 frames of 720×1280 become a latent of 31 × 90 × 160. The VAE is usually causal in time: each latent frame only depends on current and earlier video frames, and the very first frame is encoded on its own. That’s why frame counts like 121 (1 + 4·30) are common, and why the same VAE can encode a single image as a one-frame video, letting models train on images and videos together.
Step 2: cut the latent into spacetime patches
Exactly as a Vision Transformer cuts an image into squares, a video DiT cuts the latent into small 3D blocks, spacetime patchesSpacetime patchA small block of video covering a few pixels (or latents) in height and width and a few frames in time, used as one token., and linearly embeds each as a token. A common choice is 1 latent frame × 2 × 2 latent pixels. Positional information now needs three coordinates (time, height, width); 3D variants of RoPE are a popular way to provide it.
The Sora report stresses a practical benefit: because the model just sees a variable-length set of patches, one network can train on and generate videos of different durations, resolutions and aspect ratios, instead of cropping everything to a fixed square.
Each highlighted tube is one token: a 8×8-pixel square across 2 frames. Halving the spatial patch quadruples the tokens and multiplies full-attention cost by 16.
Things to try:
- Spatial 8×8, temporal 2 frames. The toy clip becomes 8 × 4 × 4 = 128 tokens. The highlighted tube follows one square through two frames: one token “sees” a little piece of motion.
- Spatial 4×4, temporal 1. 1,024 tokens: 8× more, and full attention cost rises 64×. Detail is cheap to want and expensive to buy.
- Switch to “5 s of 720p video”. After 4×8×8 compression and 1×2×2 patches you get about 112,000 tokens, and full 3D attention compares about 12.5 billion pairs per layer, per denoising step.
- Compare the bars. Factorized space-then-time attention is roughly 30× cheaper at that scale, and attention within single frames only is cheaper still, but it cannot model motion at all.
Step 3: a Transformer that attends across space and time
There are two main ways to let tokens talk:
- Factorized attention. Alternate spatial attention (tokens attend within their own frame) with temporal attentionTemporal attentionAttention along the time axis only: each spatial position attends to itself in other frames. Cheaper than full spacetime attention. (each spatial position attends to itself across frames). Cost is about for time steps and tokens per frame, much less than full attention. This was the standard way to turn image U-Nets into video models, because the spatial layers could start from pretrained image weights.
- Full 3D attention. Every token attends to every other token. Cost grows as , but information can flow directly between, say, a hand in frame 3 and the same hand in frame 28. CogVideoX and HunyuanVideo both describe full 3D attention, and the trend in large models has been toward it, paying the cost with heavy compression, FlashAttention-style kernels and many GPUs.
Text conditioning works as in image models. Some designs use cross-attentionCross-attentionAttention where queries come from one sequence (e.g. image latents) and keys/values from another (e.g. text tokens). from video tokens to text tokens; others concatenate text and video tokens in an MMDiT-style joint attention (HunyuanVideo describes dual-stream blocks followed by single-stream blocks). Text encoders have grown: T5-style encoders are common, and some models use a multimodal LLM’s representations. Most recent open models train with flow matching rather than the original DDPM objective.
Why consistency is hard
A video model has to learn, from pixels alone, regularities we take for granted:
- Object permanence. A dog that walks behind a tree should come out the other side, the same dog. Tokens behind the occluder carry no evidence of it, so the model must “remember” through attention.
- Physics and causality. Glass should shatter when dropped, liquid should pour downward, a bitten cookie should keep its bite mark. The Sora report explicitly lists such failures, noting the model can mishandle basic interactions like glass shattering.
- Identity and long-range consistency. Faces, text and fine textures drift over long clips, and errors compound when long videos are generated chunk by chunk.
The Sora report frames scaled-up video generation as a path toward “general purpose simulators of the physical world”, while also documenting these limitations. Whether pixel-level generation alone yields robust physical understanding is still an open question.
Beyond text: image-to-video and training data
Text is not the only way to start a video. Image-to-video models take a first frame (often generated by an image model) and animate it. A common approach encodes the image with the same causal VAE and feeds its latent alongside the noisy video latent, for example concatenated as extra channels on the first frame, so the model only has to invent what happens next. This is popular in practice because it separates two problems: get the look right with an image model, then get the motion right with a video model. The same trick extends to video-to-video editing, keyframe interpolation, and extending a clip forward in time. Because the causal VAE encodes a single image as a one-frame video, the plumbing is the same for all of these.
Training data shapes what these models can do. Video-text pairs are scarce and their original captions are short, so labs recaption their clips with a vision-language model to produce long, detailed descriptions; the Sora report describes doing this, following the approach used for DALL·E 3. Data is also heavily filtered for motion, quality and duplicates, and models are usually trained on images first, then short low-resolution clips, then longer high-resolution ones: a curriculum that spends the expensive token budget only once the model already knows what things look like.
The compute bill
Video multiplies every cost of image generation. More tokens per sample (often 10–100× an image), quadratic attention over them, dozens of denoising steps, and usually classifier-free guidance doubling each step. Generating a few seconds of high-resolution video with a large open model can take minutes on a top-end GPU. That’s why research focuses on stronger VAEs (fewer tokens), sparse or windowed attention, step distillation, and caching computations across steps.
MATH CORNER · optionalCounting tokens and attention pairs
For a latent with frames of and patches of size :
where tokens per time step and time steps.
Worked example: 5 s of 720p.
| quantity | computation | value |
|---|---|---|
| raw video | 121 × 720 × 1280 × 3 | ≈ 335M numbers |
| VAE latent (4× time, 8× space, causal) | (1 + 120/4) × 90 × 160 | 31 × 90 × 160 |
| tokens (patch 1×2×2) | 31 × 45 × 80 | 111,600 |
| full attention pairs | ≈ 12.5 billion | |
| factorized | ≈ 405 million |
Full attention costs about 31× more here, which is roughly : the price of letting every frame see every other frame directly. Doubling the clip length doubles and quadruples full-attention cost.
In code
Patchifying a video latent is a reshape, just like ViT patchification with one extra axis:
import torch
def patchify_video(z, pt=1, p=2):
# z: (B, C, T, H, W) latent from a 3D VAE
B, C, T, H, W = z.shape
z = z.reshape(B, C, T // pt, pt, H // p, p, W // p, p)
z = z.permute(0, 2, 4, 6, 1, 3, 5, 7) # (B, T', H', W', C, pt, p, p)
tokens = z.reshape(B, (T // pt) * (H // p) * (W // p), C * pt * p * p)
return tokens # then a Linear layer embeds each token
z = torch.randn(1, 16, 31, 90, 160) # 5 s of 720p after a 4x8x8 VAE
print(patchify_video(z).shape) # torch.Size([1, 111600, 64])
- “Video models generate one frame at a time, like an LLM generates tokens.” Most current diffusion-based video models denoise all frames of a clip jointly. Autoregressive frame-by-frame generation exists, but the systems in this lesson generate the whole block.
- “A video model is just an image model run many times.” Without cross-frame attention, frames don’t agree. Temporal or full 3D attention, and a VAE that compresses time, are what make motion coherent.
- “Realistic-looking video means the model understands physics.” Models produce plausible motion statistically but still fail at object permanence and physical interactions, as their own technical reports acknowledge.
- “Doubling the video length doubles the cost.” Tokens double, but full attention is quadratic in tokens, so that part of the cost roughly quadruples.
Check your understanding
Q1.What is a spacetime patch?
Q2.Why do video VAEs compress along time as well as space?
Q3.A model uses full 3D attention. You double the number of tokens (e.g. a clip twice as long). Roughly how does attention cost change?
Q4.What is the main trade-off of factorized (space then time) attention versus full 3D attention?
Q5.Which is a commonly reported failure mode of current video generators?
Further reading
- blogVideo generation models as world simulators (OpenAI, 2024) — The Sora technical report: spacetime patches, video compression network, limitations.
- paperCogVideoX: Text-to-Video Diffusion Models with An Expert Transformer (Yang et al., 2024) — 3D causal VAE, expert adaptive LayerNorm, full 3D attention.
- paperHunyuanVideo: A Systematic Framework For Large Video Generative Models (Tencent, 2024) — A 13B-parameter open video model with a detailed report.
- paperWan: Open and Advanced Large-Scale Video Generative Models (Alibaba, 2025) — 1.3B and 14B open models, a new video VAE, data curation.
- paperScalable Diffusion Models with Transformers (Peebles & Xie, 2022) — The DiT backbone that video models extend to spacetime.