Skip to main content
By default, yt-dlp tries to download the best available quality. This is generally equivalent to using -f bestvideo*+bestaudio/best. However, you have granular control over which formats to download.

Basic Format Selection

The general syntax for format selection is -f FORMAT (or --format FORMAT) where FORMAT is a selector expression.

Simple Format Codes

The simplest case is requesting a specific format by its code:
# Download format with code 22
yt-dlp -f 22 https://www.youtube.com/watch?v=VIDEO_ID

# List all available formats for a video
yt-dlp -F https://www.youtube.com/watch?v=VIDEO_ID
Format codes are extractor-specific and may vary between different video sites.

File Extension Selection

You can download by file extension to get the best quality format of that type:
# Download best quality WebM format
yt-dlp -f webm https://example.com/video

# Download best quality MP4 format
yt-dlp -f mp4 https://example.com/video
Supported extensions: 3gp, aac, flv, m4a, mp3, mp4, ogg, wav, webm

Special Format Selectors

yt-dlp provides special names to select particular formats:
  • b, best - Best quality format with both video and audio
  • bv, bestvideo - Best video-only format
  • ba, bestaudio - Best audio-only format
  • b*, best* - Best format that contains either video or audio
  • bv*, bestvideo* - Best format that contains video (may include audio)
  • ba*, bestaudio* - Best format that contains audio (may include video)
# Download and merge best video + best audio
yt-dlp -f "bestvideo+bestaudio" URL

# Download best combined format
yt-dlp -f "best" URL

Format Selection by Preference

Specify multiple formats in order of preference using slashes:
# Try format 22, then 17, then 18
yt-dlp -f 22/17/18 URL

# Try best mp4, otherwise best format
yt-dlp -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b" URL

Downloading Multiple Formats

Use commas to download several formats of the same video:
# Download formats 22, 17, and 18
yt-dlp -f 22,17,18 URL

# Download best video and best audio separately
yt-dlp -f "bv,ba" -o "%(title)s.f%(format_id)s.%(ext)s" URL

Merging Formats

Merge video and audio using the + operator (requires ffmpeg):
# Merge best video-only and best audio-only formats
yt-dlp -f "bestvideo+bestaudio" URL

# Merge specific formats
yt-dlp -f "136+140" URL

Filtering Formats

Filter formats by putting conditions in brackets:

Numeric Filters

Available numeric fields with comparisons <, <=, >, >=, =, !=:
  • filesize - Number of bytes (if known)
  • filesize_approx - Estimated number of bytes
  • width - Video width
  • height - Video height
  • tbr - Total bitrate in kbps
  • abr - Audio bitrate in kbps
  • vbr - Video bitrate in kbps
  • fps - Frame rate
  • audio_channels - Number of audio channels
# Download best format with max 720p height
yt-dlp -f "best[height<=720]" URL
The ? after an operator includes formats where the value is unknown. For example, [height<=?720] includes videos up to 720p AND videos where height is not known.

String Filters

Available string fields with comparisons =, ^= (starts with), $= (ends with), *= (contains), ~= (regex):
  • ext - File extension
  • acodec - Audio codec name
  • vcodec - Video codec name
  • container - Container format
  • protocol - Download protocol
  • language - Language code
  • format_id - Format identifier
# Download h264 or h265 video
yt-dlp -f "(bv*[vcodec~='^((he|a)vc|h26[45])']+ba) / (bv*+ba/b)" URL

Combining Filters

Use parentheses to group filters:
# Complex filter example
yt-dlp -f "((bv*[fps>30]/bv*)[height<=720]/(wv*[fps>30]/wv*)) + ba" URL

Sorting Formats

Change quality criteria using -S (--format-sort):

Available Sort Fields

  • quality - Quality of the format
  • res - Video resolution (smallest dimension)
  • fps - Frame rate
  • hdr - Dynamic range (DV > HDR12 > HDR10+ > HDR10 > HLG > SDR)
  • codec - Video/audio codec preference
  • size - Filesize (exact or approximate)
  • br - Bitrate (total/video/audio)
  • asr - Audio sample rate
  • proto - Protocol preference
  • ext - File extension preference
  • lang - Language preference
# Download with smallest resolution
yt-dlp -S "+res" URL

# Prefer <= 720p, but no larger
yt-dlp -S "res:720" URL

# Prefer closest to 480p
yt-dlp -S "res~480" URL

Sort Order

  • Fields are sorted in descending order by default
  • Prefix with + to reverse to ascending order
  • Suffix with :VALUE to prefer values up to that limit
  • Suffix with ~VALUE to prefer values closest to that limit
# Prefer larger videos but no bigger than 720p
yt-dlp -S "res:720" URL

# Prefer smallest resolution
yt-dlp -S "+res" URL

Practical Examples

# Download and merge best video + best audio
yt-dlp -f "bv+ba/b" URL

# Or simply (default behavior)
yt-dlp URL

Interactive Selection

Use -f - to interactively choose the format for each video:
yt-dlp -f - URL

Common Patterns

YouTube Best Quality

# Default (recommended)
yt-dlp URL

# Explicit format selection
yt-dlp -f "bv*+ba/b" URL

Save Bandwidth

# 480p or lower
yt-dlp -S "res:480" URL

# Smallest possible file
yt-dlp -S "+size" URL

Archive Quality

# Best available, prefer free formats
yt-dlp --prefer-free-formats -S "ext" URL

# Best with specific codec
yt-dlp -S "vcodec:h265,acodec:opus" URL