Video Generation
After this lesson, you will be able to:
- Explain why video generation is fundamentally diffusion in space PLUS time, and what each new dimension costs in compute and memory
- Compare what is public about leading video systems (full papers for HunyuanVideo and CogVideoX, a short report for Sora, little for Veo and Runway) and pick which one fits a given use case
- Describe how a latent video VAE with 4x temporal and 8x8 spatial compression turns 60 frames of pixels into 15 frames of latents, and why this single trick makes multi-second video generation tractable
- Diagnose the three classic video-gen failure modes (flicker, character drift, and physics breakdown) and know which architectural choice mitigates each
Before you start
Video generation is image generation with an extra axis: time. Once you see how the compressor shrinks time, the rest follows.
One still picture in a video. A clip is many frames shown in order.
A small block of numbers that stands for a bigger picture or clip. The model works on latents, not on pixels.
A compressor with two halves. The encoder shrinks a clip into latents, and the decoder turns latents back into a clip.
The network that removes a little noise at each step until a clean latent is left.
One piece of the input that a transformer handles as a single item.
A small block of pixels that also spans a few frames. Each block becomes one token.
The step where every token looks at other tokens to decide what matters. Its cost grows fast with the token count.
One basic arithmetic operation. We count FLOPs to compare costs.
#From Image to Video: One More Dimension
Here is the whole path in one picture. The starting picture is optional; a text-only model starts from random noise alone.
#The DiT Backbone: Diffusion Transformers
The breakthrough Sora demonstrated: the DiT scales just like LLMs do. Train a bigger DiT on more video data, and quality keeps climbing — there's no obvious wall yet.
#Spacetime Patches and Factorized Attention
Sora's technical report describes inputs as "spacetime patches." A 60-frame, 256x256 video gets divided into a grid of 3D cubes (e.g., 4 frames x 16 pixels x 16 pixels per patch), and each cube becomes a single token in the transformer.
HunyuanVideo and CogVideoX use full 3-D attention over all spacetime tokens, while earlier work such as Video Diffusion Models (Ho et al.) factorized it. OpenAI and Google have not said which they use for Sora and Veo. The trade-off: full attention is more expressive but about 14x to 59x more attention work in the examples above.
Try the 15-frame clip, then drag the frame slider to 64 and compare the three attention types on the log plot.
- Do: Drag the frame slider from 15 up to 64, then switch between the three attention types.
- Notice: The full-attention line climbs far above the others on the log plot.
- Why: Full attention pairs every token with every other. Factorised attention looks inside each frame, then along time. Exact counts, no trained model.
#The Latent Video VAE: Compressing Time
Building a good video VAE is hard. The decoder must produce temporally coherent reconstructions — small errors in latent space can manifest as flicker. The open VAEs of CogVideoX, HunyuanVideo and Wan use about 4x temporal and 8x8 spatial compression; the closed systems have not published theirs. These VAEs also encode the first frame on its own, so a clip of 1 + 4k frames becomes 1 + k latent frames. The lesson uses 60 frames and 15 latent frames to keep the arithmetic clean.
#What one clip costs
The cost of a clip is a count of network calls times the cost of one call. The cost of one call has a part that grows with the number of tokens and a part that grows with its square.
#Extending a clip chunk by chunk
To get a long video from a short-clip model, each new chunk is conditioned on the last frames of the previous one. Ho et al. use a related idea they call reconstruction-guided sampling. Whole-clip quality is then scored with Fréchet Video Distance, whose formula is derived in the lesson "Evaluation Deep Dive".
#Flow Matching as the Default Training Objective
Several recent open models, among them SD3, FLUX, HunyuanVideo and Wan, were trained with one objective instead of the original DDPM noise prediction. Which would you pick?
- Flow matching admits straighter probability paths from noise to data, which empirically converges faster and produces better samples per training FLOP.
- The probability flow ODE view makes deterministic, fast samplers natural — useful for video where each step is expensive.
- Conditional flow matching lets you condition on text, image, or other video frames cleanly via the velocity field.
#Try It: Image-to-Video with Stable Video Diffusion
This lesson has two cells. The first needs a GPU, so it is a read-only copy for Google Colab. The second runs here in your browser with numpy: a toy video VAE that shows the cost of compressing time.
# Copy to Colab (needs a GPU, torch and diffusers; it cannot run in the browser)
# Image-to-Video with Stable Video Diffusion (SVD)
# Provide a still image, get back a 25-frame clip (the -xt checkpoint; the base checkpoint makes 14).
import torch
from diffusers import StableVideoDiffusionPipeline
from diffusers.utils import load_image, export_to_video
# 1. Load the model. SVD comes in two flavors: 14 frames or 25 frames.
# This loads in fp16 to fit on a 24GB GPU.
pipe = StableVideoDiffusionPipeline.from_pretrained(
"stabilityai/stable-video-diffusion-img2vid-xt",
torch_dtype=torch.float16,
variant="fp16",
).to("cuda")
# 2. Load an input image (must be 1024x576 for SVD-XT)
image = load_image("https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/svd/rocket.png")
image = image.resize((1024, 576))
# 3. Generate the video. Key parameters:
# - num_frames: 14 or 25 depending on the variant
# - motion_bucket_id: 0-255, higher = more motion
# - noise_aug_strength: how much noise to add to the input image
# - decode_chunk_size: lower if you OOM; trades speed for memory
generator = torch.manual_seed(42)
frames = pipe(
image,
decode_chunk_size=8,
generator=generator,
motion_bucket_id=127, # medium motion
noise_aug_strength=0.02, # very small noise on input
).frames[0]
# 4. Export to MP4 at 7 fps (SVD's native rate)
export_to_video(frames, "generated.mp4", fps=7)
print(f"Generated {len(frames)} frames -> generated.mp4")
# CHALLENGE: write a sweep that generates 4 clips with motion_bucket_id
# in {30, 80, 127, 200} from the same input image. Save each clip and
# compare: at what motion_bucket_id does temporal coherence start to break?Now the browser version. It builds a moving blob, shrinks it with the same 4x temporal and 8x8 spatial factors as real video VAEs, decodes it, and measures what the time compression lost.
Tests: Run the script. It should print the shapes (60, 64, 64) and (15, 8, 8), a compression of 256.0, then a table in which the extra error from time is 0 for a still scene and grows with speed, and finally 'All checks passed'. This is a drawn stand-in for a real video VAE: average pooling, not a trained model.
#Production Architecture Comparison
| Model | Org | Open weights? | Length | Architecture | Strengths | Notes |
|---|---|---|---|---|---|---|
| Stable Video Diffusion | Stability AI | Yes | 14 or 25 frames (about 2-4 s) | I2V latent diffusion | Open, hackable | Image-to-video only, no T2V |
| Sora | OpenAI | No | Product clips of about 10-25 s (as of Oct 2026, check) | Diffusion transformer (per OpenAI's report) | Long clips | Details not published |
| Veo 2 / Veo 3 | Google DeepMind | No | Veo 3 clips of 8 s (as of Oct 2026, check) | Not published | Veo 3 adds generated audio | Architecture not published |
| Runway Gen-3 Alpha | Runway | No | About 10 s (check) | Not published | Product with editing tools | Architecture not published |
| Kling | Kuaishou | No | 5-10s | Not published in detail | Text-to-video product | Check the current version |
| HunyuanVideo | Tencent | Yes | ~5s | Transformer, 13B params, full 3-D attention | Open weights and paper | Large open-weights model |
| Mochi-1 | Genmo | Yes | 5.4s @ 30fps | DiT | Open, prompt adherence | Apache 2.0 license |
| CogVideoX | THUDM | Yes | 6-10s | Transformer, full 3-D attention | Early open option | 5B parameter version available |
#Key Takeaways
- Video gen is diffusion in space + time. Add a temporal dimension to image diffusion and you get video diffusion. The math is the same; the cost is brutal.
- Latent video VAE is the make-or-break trick. Compressing both spatial and temporal dimensions before diffusion shrinks the numbers to denoise by about 48x in this lesson's example. Without it, multi-second video generation would be intractable.
- Transformers are the common backbone. Sora (per its report), SD3, FLUX, HunyuanVideo and CogVideoX use diffusion transformers or close relatives. The architecture scales with parameters and data the way LLMs do.
- Three failure modes recur. Flicker (insufficient temporal attention), character drift (weak long-range coherence), physics breakdown (insufficient world-model training). Each architectural choice mitigates a different one.
- Open-weights video models improved fast. HunyuanVideo, Mochi-1 and CogVideoX appeared in 2024. How they compare with closed models depends on your prompts, so test both on the same ones.
#Quick Check
Why does almost every modern video diffusion model use a latent VAE that compresses time as well as space?