Repository: yt-dlp
Issue: Difficulty getting format sorting to work
Labels: enhancement,triage

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm asking a question and **not** reporting a bug or requesting a feature
- [X] I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar questions **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Please make sure the question is worded well enough to be understood

Hi,

I am having difficulty setting up a configuration file that will sort video codecs from best to worst in the following (custom) order:
av01>h265>h264>vp9>vp9.2 

Basically I want yt-dlp to download YouTube videos preferably in av01, but failing that h265, or h264 and so with the highest possible resolution. For some reason it keeps downloading vp9 or vp9.2 codec videos which quick time player can't playback (I prefer to use QuickTime over VLC).

This is my configuration file at present:

#Save videos to sensible directory
-o ~/YouTube/%(title)s.%(ext)s

-S "res:1440,hdr:dv,vcodec:av01>avc,ext,proto"

Any help would be appreciated.

PS: I have tried on both stable and nightly builds - makes no difference.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [ ] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
yt-dlp -vU https://youtu.be/akefhbjWAXc -v -F
[debug] Command-line config: ['-vU', 'https://youtu.be/akefhbjWAXc', '-v', '-F']
[debug] Home config "yt-dlp.conf": ['-o', '~/YouTube/%(title)s.%(ext)s', '-S', 'res:1440,hdr:dv,vcodec:avc,ext,proto']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2024.04.09 from yt-dlp/yt-dlp [ff0779267] (pip)
[debug] Python 3.12.3 (CPython arm64 64bit) - macOS-14.4.1-arm64-arm-64bit (OpenSSL 3.2.1 30 Jan 2024)
[debug] exe versions: ffmpeg 7.0 (setts), ffprobe 7.0
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, mutagen-1.47.0, requests-2.31.0, sqlite3-3.45.2, urllib3-2.2.1, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1810 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: stable@2024.04.09 from yt-dlp/yt-dlp
yt-dlp is up to date (stable@2024.04.09 from yt-dlp/yt-dlp)
[youtube] Extracting URL: https://youtu.be/akefhbjWAXc
[youtube] akefhbjWAXc: Downloading webpage
[youtube] akefhbjWAXc: Downloading ios player API JSON
[youtube] akefhbjWAXc: Downloading android player API JSON
[youtube] akefhbjWAXc: Downloading m3u8 information
[debug] Sort order given by user: res:1440, hdr:dv, vcodec:avc, ext, proto
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, res:1440(1440.0), hdr:dv(8), vcodec:avc(7), vext, aext, proto, quality, fps, source, channels, acodec, lang, size, br, asr, hasaud, id
[info] Available formats for akefhbjWAXc:
ID      EXT   RESOLUTION FPS CH │   FILESIZE    TBR PROTO │ VCODEC           VBR ACODEC      ABR ASR MORE INFO
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
sb3     mhtml 48x27        0    │                   mhtml │ images                                   storyboard
sb2     mhtml 80x45        0    │                   mhtml │ images                                   storyboard
sb1     mhtml 160x90       0    │                   mhtml │ images                                   storyboard
sb0     mhtml 320x180      0    │                   mhtml │ images                                   storyboard
233     mp4   audio only        │                   m3u8  │ audio only           unknown             [en] Default, IOS
234     mp4   audio only        │                   m3u8  │ audio only           unknown             [en] Default, IOS
600-drc webm  audio only      2 │    2.68MiB    35k https │ audio only           opus        35k 48k [en] ultralow, DRC, ANDR, webm_dash
600     webm  audio only      2 │    2.68MiB    35k https │ audio only           opus        35k 48k [en] ultralow, ANDR, webm_dash
249-drc webm  audio only      2 │    3.93MiB    52k https │ audio only           opus        52k 48k [en] low, DRC, ANDR, webm_dash
250-drc webm  audio only      2 │    5.19MiB    68k https │ audio only           opus        68k 48k [en] low, DRC, ANDR, webm_dash
249     webm  audio only      2 │    3.93MiB    52k https │ audio only           opus        52k 48k [en] low, ANDR, webm_dash
250     webm  audio only      2 │    5.21MiB    68k https │ audio only           opus        68k 48k [en] low, ANDR, webm_dash
251-drc webm  audio only      2 │    9.66MiB   127k https │ audio only           opus       127k 48k [en] medium, DRC, ANDR, webm_dash
251     webm  audio only      2 │    9.71MiB   127k https │ audio only           opus       127k 48k [en] medium, ANDR, webm_dash
599-drc m4a   audio only      2 │    2.35MiB    31k https │ audio only           mp4a.40.5   31k 22k [en] ultralow, DRC, ANDR, m4a_dash
599     m4a   audio only      2 │    2.35MiB    31k https │ audio only           mp4a.40.5   31k 22k [en] ultralow, ANDR, m4a_dash
139-drc m4a   audio only      2 │    3.72MiB    49k https │ audio only           mp4a.40.5   49k 22k [en] low, DRC, IOS, m4a_dash
139     m4a   audio only      2 │    3.72MiB    49k https │ audio only           mp4a.40.5   49k 22k [en] low, IOS, m4a_dash
140-drc m4a   audio only      2 │    9.87MiB   129k https │ audio only           mp4a.40.2  129k 44k [en] medium, DRC, IOS, m4a_dash
140     m4a   audio only      2 │    9.87MiB   129k https │ audio only           mp4a.40.2  129k 44k [en] medium, IOS, m4a_dash
313     webm  3840x2160   30    │  894.71MiB 11741k https │ vp09.00.50.08 11741k video only          2160p, IOS, webm_dash
625     mp4   3840x2160   30    │ ~  1.40GiB 18791k m3u8  │ vp09.00.50.08 18791k video only          IOS
598     webm  256x144     15    │    1.75MiB    23k https │ vp9              23k video only          144p, ANDR, webm_dash
278     webm  256x144     30    │    4.77MiB    63k https │ vp09.00.11.08    63k video only          144p, IOS, webm_dash
602     mp4   256x144     15    │ ~  6.74MiB    89k m3u8  │ vp09.00.10.08    89k video only          IOS
603     mp4   256x144     30    │ ~ 13.83MiB   181k m3u8  │ vp09.00.11.08   181k video only          IOS
269     mp4   256x144     30    │ ~ 12.98MiB   170k m3u8  │ avc1.4D400C     170k video only          IOS
597     mp4   256x144     15    │    2.29MiB    30k https │ avc1.4d400b      30k video only          144p, ANDR, mp4_dash
160     mp4   256x144     30    │    2.94MiB    39k https │ avc1.4D400C      39k video only          144p, IOS, mp4_dash
242     webm  426x240     30    │    7.19MiB    94k https │ vp09.00.20.08    94k video only          240p, IOS, webm_dash
604     mp4   426x240     30    │ ~ 23.10MiB   303k m3u8  │ vp09.00.20.08   303k video only          IOS
229     mp4   426x240     30    │ ~ 23.71MiB   311k m3u8  │ avc1.4D4015     311k video only          IOS
133     mp4   426x240     30    │    5.94MiB    78k https │ avc1.4D4015      78k video only          240p, IOS, mp4_dash
243     webm  640x360     30    │   16.48MiB   216k https │ vp09.00.21.08   216k video only          360p, IOS, webm_dash
605     mp4   640x360     30    │ ~ 51.68MiB   679k m3u8  │ vp09.00.21.08   679k video only          IOS
230     mp4   640x360     30    │ ~ 61.18MiB   803k m3u8  │ avc1.4D401E     803k video only          IOS
134     mp4   640x360     30    │   11.10MiB   146k https │ avc1.4D401E     146k video only          360p, IOS, mp4_dash
18      mp4   640x360     30  2 │   32.20MiB   423k https │ avc1.42001E          mp4a.40.2       44k [en] 360p, ANDR
244     webm  854x480     30    │   24.89MiB   327k https │ vp09.00.30.08   327k video only          480p, IOS, webm_dash
606     mp4   854x480     30    │ ~ 90.05MiB  1182k m3u8  │ vp09.00.30.08  1182k video only          IOS
231     mp4   854x480     30    │ ~103.15MiB  1354k m3u8  │ avc1.4D401F    1354k video only          IOS
135     mp4   854x480     30    │   17.76MiB   233k https │ avc1.4D401F     233k video only          480p, IOS, mp4_dash
247     webm  1280x720    30    │   47.35MiB   621k https │ vp09.00.31.08   621k video only          720p, IOS, webm_dash
609     mp4   1280x720    30    │ ~161.62MiB  2122k m3u8  │ vp09.00.31.08  2122k video only          IOS
232     mp4   1280x720    30    │ ~151.27MiB  1986k m3u8  │ avc1.4D401F    1986k video only          IOS
22      mp4   1280x720    30  2 │ ≈ 39.75MiB   522k https │ avc1.64001F          mp4a.40.2       44k [en] 720p, ANDR
136     mp4   1280x720    30    │   29.92MiB   393k https │ avc1.4D401F     393k video only          720p, IOS, mp4_dash
248     webm  1920x1080   30    │   86.60MiB  1136k https │ vp09.00.40.08  1136k video only          1080p, IOS, webm_dash
614     mp4   1920x1080   30    │ ~249.26MiB  3272k m3u8  │ vp09.00.40.08  3272k video only          IOS
270     mp4   1920x1080   30    │ ~356.89MiB  4685k m3u8  │ avc1.640028    4685k video only          IOS
137     mp4   1920x1080   30    │  114.54MiB  1503k https │ avc1.640028    1503k video only          1080p, IOS, mp4_dash
271     webm  2560x1440   30    │  300.17MiB  3939k https │ vp09.00.50.08  3939k video only          1440p, IOS, webm_dash
620     mp4   2560x1440   30    │ ~719.69MiB  9448k m3u8  │ vp09.00.50.08  9448k video only          IOS
```