Reference
Formats
/player lists every format YouTube offers for the video. Video and audio are separate
tracks. Which ones exist depends on the video: a 720p upload has no 1080p track, and older
uploads often have no AV1.
| Track | Container | Codec | Range | mimeType | Typical itags |
|---|---|---|---|---|---|
| Video | MP4 | H.264 (avc1) | 144p to 1080p, up to 60 fps | video/mp4 | 160 133 134 135 136 137 298 299 |
| Video | MP4 | AV1 (av01) | 144p to 2160p | video/mp4 | 394 395 396 397 398 399 400 401 |
| Video | WebM* | VP9 | 144p to 2160p | video/webm | 278 242 243 244 247 248 271 313 |
| Audio | M4A | AAC (mp4a) | 48 to 128 kbps | audio/mp4 | 139 140 |
| Audio | WebM* | Opus | 50 to 160 kbps | audio/webm | 249 250 251 |
* WebM formats are listed when you call /player with webm=true. Which itags exist depends on the video.
itag
The itag is YouTube’s ID for one combination of container, codec and quality. It is the
easiest way to ask for a specific format:
| You want | itag |
|---|---|
| Audio, M4A (AAC, 128 kbps) | 140 |
| Audio, WebM (Opus, about 160 kbps) | 251 |
| Video, MP4 (H.264), 1080p | 137 |
| Video, MP4 (H.264), 720p | 136 |
| Video, WebM (VP9), 1080p | 248 |
mimeType
mimeType names container and codec. The part before ; is the container, the codecs
value is the codec:
video/mp4; codecs="avc1.640028" MP4, H.264
video/mp4; codecs="av01.0.08M.08" MP4, AV1
video/webm; codecs="vp9" WebM, VP9
audio/mp4; codecs="mp4a.40.2" M4A, AAC
audio/webm; codecs="opus" WebM, Opus
WebM is opt in
WebM formats are left out unless you call /player with webm=true:
https://api.ytbro.net/player?id=aqz-KE-bpKQ&webm=true
Picking a format
Pick the best format of a kind instead of hard-coding an itag that a video might not have:
# Best MP4 video by height, then the M4A audio
jq -r '[.adaptiveFormats[] | select(.mimeType | startswith("video/mp4"))] | max_by(.height) | .downloadUrl' player.json
jq -r 'first(.adaptiveFormats[] | select(.mimeType | startswith("audio/mp4"))) | .downloadUrl' player.jsonconst formats = player.adaptiveFormats;
const video = formats
.filter((f) => f.mimeType.startsWith('video/mp4'))
.sort((a, b) => b.height - a.height || b.bitrate - a.bitrate)[0];
const audio = formats
.filter((f) => f.mimeType.startsWith('audio/mp4'))
.sort((a, b) => b.bitrate - a.bitrate)[0];formats = player["adaptiveFormats"]
video = max(
(f for f in formats if f["mimeType"].startswith("video/mp4")),
key=lambda f: (f["height"], f["bitrate"]),
)
audio = max(
(f for f in formats if f["mimeType"].startswith("audio/mp4")),
key=lambda f: f["bitrate"],
)let formats = player["adaptiveFormats"].as_array().ok_or("no formats")?;
let starts = |f: &serde_json::Value, p: &str| f["mimeType"].as_str().is_some_and(|m| m.starts_with(p));
let video = formats
.iter()
.filter(|f| starts(f, "video/mp4"))
.max_by_key(|f| (f["height"].as_i64(), f["bitrate"].as_i64()));
let audio = formats
.iter()
.filter(|f| starts(f, "audio/mp4"))
.max_by_key(|f| f["bitrate"].as_i64());On videos with several audio languages, the same itag appears once per language. Check
audioTrack before you take the highest bitrate. See
/player.
Video with sound
There is no single file with both. Download one video and one audio format and merge them. This copies the streams and does not re-encode:
# MP4 video + M4A audio
ffmpeg -i video.mp4 -i audio.m4a -c copy out.mp4
# WebM video + Opus audio
ffmpeg -i video.webm -i audio.webm -c copy out.webm
For playback in the browser, /dash combines them in the player instead.