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.

TrackContainerCodecRangemimeTypeTypical itags
VideoMP4H.264 (avc1)144p to 1080p, up to 60 fpsvideo/mp4160 133 134 135 136 137 298 299
VideoMP4AV1 (av01)144p to 2160pvideo/mp4394 395 396 397 398 399 400 401
VideoWebM*VP9144p to 2160pvideo/webm278 242 243 244 247 248 271 313
AudioM4AAAC (mp4a)48 to 128 kbpsaudio/mp4139 140
AudioWebM*Opus50 to 160 kbpsaudio/webm249 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 wantitag
Audio, M4A (AAC, 128 kbps)140
Audio, WebM (Opus, about 160 kbps)251
Video, MP4 (H.264), 1080p137
Video, MP4 (H.264), 720p136
Video, WebM (VP9), 1080p248

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.json
const 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.