---
name: video-encoding-basics
description: Pick a codec, bitrate strategy, and container for video encoding, then produce working ffmpeg commands (software and hardware) with verified settings. Triggers on "encode this video", "transcode for streaming/sharing/archive", "what bitrate for 1080p", "H.264 vs H.265 vs AV1", "NVENC vs x264", or any ffmpeg video-encoding question.
---

# Video Encoding Basics

## Purpose

Turn a "make this video work somewhere" request into concrete, correct ffmpeg commands: the right codec, rate control, bitrate ladder, and container for the delivery target. Covers software encoders (libx264, libx265, SVT-AV1, libvpx-vp9) and hardware encoders (NVENC, QSV, AMF, VAAPI, VideoToolbox).

## Workflow

1. **Pin down the delivery target.** Streaming (live or VOD), downloadable share, archival copy, or editing intermediate. Each wants different tradeoffs: streaming cares about ladder and keyframe interval, archive cares about efficiency, editing wants intra-frame codecs.
2. **Pick the codec.** H.264 for universal playback. H.265 for 4K/HDR and efficient archives on modern devices. AV1 for royalty-free streaming at scale with plenty of encode time. VP9 only for WebM/YouTube legacy paths. Default to H.264 unless the target clearly calls for otherwise.
3. **Pick rate control.** CRF/CQ for one-off files (quality-constant, no file-size target). Two-pass VBR for fixed-size or streaming ladders. Never CBR for general streaming; it wastes bits on simple scenes and starves complex ones.
4. **Pick the container.** MP4 for H.264/HEVC/AV1 delivery, MKV when anything must go in one file, WebM for VP9/AV1 + Opus on the web. Match codec to container, do not remux incompatible pairs.
5. **Build the command.** Start from a recipe in `references/ffmpeg-recipes.md`, adapt bitrate/resolution to the source, and keep compatibility flags (`-pix_fmt yuv420p` for H.264, `-vtag hvc1` for HEVC in MP4 on Apple devices).
6. **Verify the output.** Probe with `ffprobe` for codec, resolution, and bitrate; play the file or check the first GOP. Never hand off an encode you have not at least probed.

## Output Contract

Every encoding job returns:
- the chosen codec, container, and rate-control mode, with one line on why
- the exact ffmpeg command(s), ready to run
- for ladders: each rung (resolution, video bitrate, audio bitrate) in a table
- a `ffprobe` verification command and what to check in its output

## Operating Rules

- Every number comes from a verified source or the references in this skill. Never invent bitrates, CRF values, or codec support claims. If unsure whether a device decodes a codec, say so and default to H.264.
- Hardware vs software: default to CPU encoders for quality work; switch to hardware when encode time is the bottleneck. GPU encodes at slow CPU presets do not exist; do not promise them.
- Compatibility defaults: H.264 output gets `-pix_fmt yuv420p`; HEVC in MP4 gets `-vtag hvc1` for Apple players.
- Two-pass is required for accurate fixed-bitrate targets; one pass with a bitrate flag does not hit a target reliably.
- Bulky detail lives in `references/`: `codec-guide.md` (codec and encoder comparison), `bitrate-ladders.md` (rung tables), `containers.md` (codec/container matrix and Apple quirks), `ffmpeg-recipes.md` (copy-paste commands).
