# yt-dlp format selection explained

List available formats with yt-dlp, download a specific resolution like 1080p, grab the highest quality or audio only, set the format from Python, and fix 'requested format is not available'.

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`.

```bash
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

```bash
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

```bash
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:

```bash
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:

```bash
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

```bash
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](/guides/extract-audio-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".

```python
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:

```python
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](/guides/yt-dlp-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"]`:

```python
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":

```python
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`](https://www.importly.io/docs/features/metadata?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=format-selection-menu&utm_term=%2Fguides%2Fyt-dlp-format-selection) 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](/guides/run-yt-dlp-server) and [what to do when downloads get blocked on a server](/guides/yt-dlp-blocked-on-server). A hosted import API takes the same choices as options on one request. In [Importly's import options](https://www.importly.io/docs/features/downloads?utm_source=ytdlp.org&utm_medium=referral&utm_campaign=doc-cta&utm_content=format-selection-options&utm_term=%2Fguides%2Fyt-dlp-format-selection#quality), 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` |

```json
{
  "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.

<DocCta variant="default" />

<Faq />

## Related guides

- [MP4 won't play? Get H.264 instead of AV1](/guides/yt-dlp-mp4-wont-play-av1-h264)
- [Fix ffmpeg not found](/guides/fix-ffmpeg-not-found)
- [Extract audio as MP3](/guides/extract-audio-mp3)
- [Fix common yt-dlp errors](/guides/fix-yt-dlp-errors)
- [Browse commands](/guides/yt-dlp-commands)
- [Record a YouTube live stream](/guides/yt-dlp-download-youtube-live)
- [Run yt-dlp on a server](/guides/run-yt-dlp-server)
- [Use yt-dlp as an API](/guides/yt-dlp-api)