Command guide
yt-dlp format selection explained
The biggest format mistake is guessing. Good yt-dlp usage starts with looking at the actual formats available on the specific media you are downloading, then choosing the stream or combination that matches your goal.
Quick answer
Start with this before you touch -f.
yt-dlp -F "URL"That command lists the real formats available for that one video. If you skip this step, you are basically guessing.
Choose one exact format
yt-dlp -f 22 "URL"Use this when you want one specific format code from the list. This is common when you already know a format exists and want a predictable result.
Best video plus best audio
yt-dlp -f "bv*+ba/b" "URL"This is the most useful practical pattern for high quality downloads. It prefers the best separate video and audio streams, then falls back to a combined stream when needed.
Download a specific resolution
To cap the download at a resolution, filter on height. This takes the best video at 1080p or lower plus the best audio, then merges them:
yt-dlp -f "bv*[height<=1080]+ba/b" "URL"Change 1080 to 720 for smaller files or 2160 for 4K. If you would rather state a preference and let yt-dlp pick the closest match instead of a hard limit, sort by resolution:
yt-dlp -S "res:1080" "URL"Use -S res on its own to always take the highest resolution available. Merging separate video and audio streams needs ffmpeg installed.
Just the audio
yt-dlp -f ba "URL"ba downloads the best audio-only stream in its original container, usually m4a or webm, with no video. If you want an MP3 specifically, see extract audio as MP3, which adds the conversion step.
Format selection in Python
If yt-dlp runs inside your app, the format option takes the same selector as -f. Always end it with a fallback: some sites only offer combined streams, and a selector with no fallback fails the job with "Requested format is not available".
import yt_dlp
ydl_opts = {
"format": "bv*[height<=720]+ba/b[height<=720]/b",
"quiet": True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
print(info["format_id"], info.get("height"), info.get("ext"))download=False resolves the format without downloading, so you can log or check the choice first, then call ydl.download([url]). On a source whose best stream is 480p, this prints something like hls-1017+hls-audio0-medium 480 mp4: the cap is a ceiling, not a promise.
To state a preference rather than a rule, use format_sort, the Python form of -S. It never fails for lack of a match; it just ranks what exists:
ydl_opts = {"format_sort": ["res:720", "ext:mp4:m4a"]}The same check on the command line is --print "%(format_id)s %(height)s %(ext)s", which prints the chosen format and skips the download. For the rest of the Python API, see using yt-dlp from Python.
Let your app's users choose the quality
When the download runs inside an app, you usually want to show users the resolutions this particular video actually has, let them pick one, then cap the download there. Get that list without downloading by reading the distinct heights off info["formats"]:
import yt_dlp
def available_heights(url):
with yt_dlp.YoutubeDL({"quiet": True, "no_warnings": True}) as ydl:
info = ydl.extract_info(url, download=False)
heights = {
f["height"] for f in info["formats"]
if f.get("vcodec") not in (None, "none") and f.get("height")
}
return sorted(heights)
print(available_heights(url)) # e.g. [184, 288, 480, 720, 1080]Show those as the menu. When the user picks a height H, download with the cap plus a fallback, so a source that only offers one combined stream still succeeds instead of failing with "Requested format is not available":
ydl_opts = {"format": f"bv*[height<={H}]+ba/b[height<={H}]/b"}The cap is a ceiling: if the source has nothing at or below H, the fallback takes the closest it has.
On a server where you would rather not keep yt-dlp and ffmpeg running, Importly's POST /metadata returns every format the source exposes with its height, so your app builds the same menu from one call, then passes the user's choice as videoQuality on the import below. It's free to try, no card required.
The same selection in an app, without running yt-dlp
If your app downloads media for its users on a server, the format selector is the easy part. The work is keeping yt-dlp and ffmpeg current on the box and getting past the blocks datacenter IPs hit. That side of it is its own job: see running yt-dlp on a server and what to do when downloads get blocked on a server. A hosted import API takes the same choices as options on one request. In Importly's import options, the selectors on this page map like this:
| yt-dlp | Importly option |
|---|---|
-f "bv*[height<=1080]+ba/b" | "videoQuality": "1080p" |
-f "bv*+ba/b" | "videoQuality": "best" |
-f ba | "includeVideo": false |
-S "vcodec:h264,acodec:aac" | "compatibleCodecs": true |
{
"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
"videoQuality": "720p",
"compatibleCodecs": true,
"webhookUrl": "https://example.com/webhooks/importly"
}Each quality is a ceiling, like [height<=720], with the fallback built in: when a source has nothing at or below it, the import takes the closest resolution above instead of failing. The merge happens before you get the file, and the result reports videoCodec and audioCodec so your app can check what it got. It's free to try, no card required.
What the format list is telling you
- format code: the ID you can target with
-f - resolution: video size like 720p or 1080p
- extension/container: mp4, webm, m4a, and so on
- note fields: often reveal whether a stream is video-only or audio-only
The important thing is not memorizing every field. It is understanding whether you are choosing a combined stream, video-only stream, or audio-only stream.
Common format mistakes
- using an old format code from a random blog post
- assuming every site exposes the same format layout
- choosing video-only and forgetting audio
- asking for a merge without ffmpeg installed
- forcing a format that is not available on that exact media item
If you see "requested format is not available"
Stop reusing the failing command. Run yt-dlp -F "URL" again, inspect the current list, then choose a format that actually exists now. That error usually means your command is stale, not that yt-dlp is being weird.
For builders
Using yt-dlp inside an app or script?
Paste a link to see what a managed media-import API returns — no install, no signup.
Building this into an app? See the API your backend calls instead
Frequently asked questions
How do I list the available formats in yt-dlp?
Run yt-dlp -F "URL" (the long form is --list-formats). It prints every format the site offers for that link, with its ID, extension, resolution, file size, codecs and bitrate, and downloads nothing. Pick an ID from the first column and pass it with -f, for example yt-dlp -f 137+140 "URL".
How do I download a video in 1080p with yt-dlp?
Cap the height with a format filter: yt-dlp -f "bv*[height<=1080]+ba/b" "URL". That takes the best video at 1080p or lower, plus the best audio, and merges them. Change 1080 to 720 or 2160 for other resolutions.
How do I get the highest quality download?
Use yt-dlp -f "bv*+ba/b" "URL". It picks the best separate video and audio streams and falls back to the best combined stream. You need ffmpeg installed for the merge.
How do I download only the audio?
yt-dlp -f ba "URL" grabs the best audio-only stream in its original container (often m4a or webm). To convert it to MP3, see the extract-audio guide.
What does bv*+ba mean in yt-dlp?
bv* is the best video stream (including video-only streams), ba is the best audio stream, and the + merges them into one file. The /b at the end falls back to a single combined stream if a merge is not possible.
How do I set the format in yt-dlp's Python API?
Pass the same selector you would give -f as the "format" option: yt_dlp.YoutubeDL({"format": "bv*[height<=720]+ba/b[height<=720]/b"}). For a preference instead of a hard rule, use "format_sort", for example ["res:720", "ext:mp4:m4a"], which is the Python form of -S.
How can I check which format yt-dlp will pick before downloading?
In Python, call ydl.extract_info(url, download=False) and read info["format_id"]. On the command line, add --print "%(format_id)s %(height)s %(ext)s" to your command, which prints the choice without downloading.