Repository: yt-dlp
Issue: [Discussion] Upcoming changes to format selection
Labels: discussion/announcement

### If you are here only to check for changes to the defaults, just read "Multistreams" and "Default selector for stdout" sections


---

Superseeds https://github.com/yt-dlp/yt-dlp/issues/389

## "maybe merge" operator

A **new operator** `+?` will be added. It is similar to `+`, but will always work as-if multistreams were disabled; i.e. The RHS will be added to the format only if the LHS doesn't already have the same kind (audio/video) of stream. This deprecates the need for `--(audio/video)-multistreams`

## "of each" operator

A **new operator** `<field>` will be added that is used to select the [best format for each value](https://github.com/yt-dlp/yt-dlp/pull/3562) of `field`; e.g. `bv<height>, ba<language>` will select the best video format of each height and [best audio of each language](https://github.com/yt-dlp/yt-dlp/issues/1176).

## "type" field

Supplementing to the "of each" operator, a **new field** `type` will be added to the format dict that can be used by the extractor [to separate the different types of formats](https://github.com/yt-dlp/yt-dlp/issues/389)

## Filterable groups

Currently, filters `[...]` applied on groups `(...)` are simply distributed over it's components. So it is not possible to, say, [download the "best format under 1G"](https://github.com/yt-dlp/yt-dlp/issues/2518). You may expect `(bv*+ba)[filesize<1G]` to work - but it translates to `bv*[filesize<1G]+ba[filesize<1G]` which is not what we want.

While I can simply fix this behavior, that would break compatibility and I am afraid some users may actually be making use of the above  "feature". So instead, a new type of grouping `{}` will be added. Then `{bv*+ba}[filesize<1G]` will work as expected, while `()` will retain it's old behavior.

## Multistreams <a id="multistreams"/>

youtube-dlc had added the ability for us to merge multiple audio (and video) formats into one file. So far, yt-dlp has kept this option behind the multistreams switches so that the default selector of `bv*+ba` can work correctly. However, [the way this works](https://github.com/yt-dlp/yt-dlp/blob/7657ec7ed6318dd66dd72cc100ba7bc5b911366e/README.md?plain=1#L1460-L1462) is confusing and so these options will be **enabled by default**. The default selector can now handle this using `+?` - see below.

## Default selector

The default selector will be changed to `bv*+?ba/b`. This means that the best video format will be selected, and if it doesn't have an audio stream, the best audio format will be merged with it. This is effectively the **same as the current default**, but works irrespective of whether multistreams are enabled or not.

## Default selector for stdout

Currently, if you use `-o -`, the default selector is `b/bv+ba`. However, yt-dlp has had the ability to stream multiple formats to stdout (using ffmpeg) for a while. So this default will also now be changed to `bv*+?ba/b`. Note that this will cause the download to happen **through ffmpeg**. If you don't want this, you will need to give `-fb`.

PS: This change may be postponed due to https://github.com/yt-dlp/yt-dlp/issues/4478

## Documentation

A lot of the [format selection documentation](https://github.com/yt-dlp/yt-dlp#format-selection) is a mess and it would be good to take this opportunity to rewrite it. But I suspect any documentation I write will end up even less user-friendly that the current one. So any help with this would be appreciated (make a PR). If no one wants to do this, I will abandon the idea and just add the new changes to the current documentation.

---

I have an inital implementation of most these, but they need a lot of cleanup. I will open a PR when ready. In the mean time, I would appreciate any **feedback** on the above changes, and am also open to suggestions for **better syntax for the new operators**. I am not too happy with the current ones, but couldn't think of anything better.

---
Related https://github.com/yt-dlp/yt-dlp/pull/4553