question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[youtube] Video codec selected by yt-dlp doesn't provide the highest quality

See original GitHub issue

Checklist

  • I’m reporting a broken site support issue
  • I’ve verified that I’m running yt-dlp version 2021.06.23
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar bug reports including closed ones
  • I’ve read bugs section in FAQ

Verbose log

[debug] Command-line config: ['--skip-download', 'https://www.youtube.com/watch?v=Dnw6-ntk3SY', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] yt-dlp version 2021.06.23 
[debug] Python version 3.9.5 (CPython 64bit) - Linux-5.12.7-gnu-hardened1-1-hardened-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4, ffprobe 4.4, rtmpdump 2.4
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=Dnw6-ntk3SY
[youtube] Dnw6-ntk3SY: Downloading webpage
[youtube] Dnw6-ntk3SY: Downloading MPD manifest
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] Dnw6-ntk3SY: Downloading 1 format(s): 303+251

Description

By default yt-dlp seems to download videos encoded with the VP9 codec first which from my tests doesn’t seem to offer the best possible quality when downloading from youtube. When youtube only offers a video in VP9 and H.264 then H.264 has the highest quality: comparison-redone https://www.youtube.com/watch?v=Dnw6-ntk3SY

comparison https://www.youtube.com/watch?v=fy16LjNLWjk

And in the case when youtube also offers the video in AV1, then it seems that AV1 > VP9 > H.264 in terms of quality: comparison https://www.youtube.com/watch?v=spcauG9AnGI

comparison https://www.youtube.com/watch?v=RAhqxvgQYn0

My guess is that the quality depends on which codec was used by the original video. I think that most people use H.264 so the version reencoded to VP9 has lower quality and when a video is available in AV1 then it was the original codec used to encode the video so it has the highest quality. VBR reported by youtube doesn’t seem to play a role here, because when comparing the quality of these videos: https://www.youtube.com/watch?v=spcauG9AnGI (Highest VBR - H.264) https://www.youtube.com/watch?v=rXHpFOG-fcY (Highest VBR - VP9) https://www.youtube.com/watch?v=RAhqxvgQYn0 (Highest VBR - AV1) all of them seem to have the highest quality in AV1 even though the codec with the highest VBR seem to be different for every video.

It should be possible to solve this by changing the format sort used by the youtube extractor to first check for AV1 then for H.264 and only then for VP9.

Command I’ve used to download videos for comparison:

yt-dlp VIDEO_URL -f FORMAT

All of the screenshots were taken using mpv with screenshot-format=png

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pukkandancommented, Sep 5, 2021

The readme was recently edited to clarify this.

the default order used is: lang,quality,res,fps,codec:vp9.2,...

Note that the default has codec:vp9.2; i.e. av1 is not prefered

I will make AV1 default only after atleast all major OSes start supporting it See this list. Hopefully, most new devices will also have hardware support for it by then

I don’t understand why people complain about this. You have the option to just put something like -S res,vcodec:av1 in a config file and forget about it.

The default option should work for the most non-techie users and a codec that is still not natively supported on popular OSes is not a good default

0reactions
chrizillacommented, Jan 8, 2022

@pukkandan said: Currently, the only way to do av1>h264>vp9 is to use -f

like -f "(bv*+ba/b)[vcodec=av01] / (bv*+ba/b)[vcodec=h264] / (bv*+ba/b)[vcodec=vp9] / (bv*+ba/b)" ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

yt-dlp how to choose codec? (don't want VP9) - Reddit
I realised every video I download is VP9 format. This wasn't like this in youtube-dl. But it seems like yt-dlp works different.
Read more >
Downloading YouTube videos as audio with yt-dlp - write
How to Download audio from a YouTube video using yt-dlp. ... best quality audio the format ( -f ) selector will be for...
Read more >
How to select video quality from youtube-dl? - Ask Ubuntu
These commands will ensure you download the highest quality mp4 video and m4a audio from the video as a single file or will...
Read more >
Yt dlp A YouTube dl fork with additional features and fixes
yt -dlp is a youtube-dl fork based on the now inactive youtube-dlc. ... have been changed so that higher resolution and better codecs...
Read more >
yt-dlp - Easily download YouTube videos in the Terminal.
yt -dlp is a fork of the now-inactive YouTube-dl tool, which was primarily used to ... will automatically download the best quality video...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found