yt-dlp / yt-dlp

A feature-rich command-line audio/video downloader
https://discord.gg/H5MNcFW63r
The Unlicense
90.99k stars 7.07k forks source link

Cannot easily download h264 1080p video from YT if I set AV1 as my highest quality codec in config file #4189

Closed Mahir007 closed 2 years ago

Mahir007 commented 2 years ago

Checklist

Question

In my 'yt-dlp.conf' file, I've added the format sort option and changed the default order so that AV1 is preferred as the highest quality codec. This has worked just fine expect I've now ran into an issue whereby if I try to download a MP4 file (with the command: "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]"), I get one with AV1 video (which I usually download as MKV) when I am instead expecting H264 video when downloading from YouTube.

I looked through the readme and found I probably need to specify the video codec, and so I did by changing the first part of the command to: "bv*[vcodec=h264]". This works in that I get H264 video, but the issue is that the video is then limited to 720p (specifically the version that includes both audio and video in the same stream) even though a 1080p video-only stream is available. I've tried messing about with a few more options to no success (bar outright specifying the id each time).

Any ideas on how I can get this to work while keeping AV1 as preferred in my config?

Verbose log

No response

pukkandan commented 2 years ago

In my 'yt-dlp.conf' file, I've added the format sort option and changed the default order so that AV1 is preferred as the highest quality codec. This has worked just fine expect I've now ran into an issue whereby if I try to download a MP4 file (with the command: "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]"), I get one with AV1 video (which I usually download as MKV) when I am instead expecting H264 video when downloading from YouTube.

So, you told yt-dlp that av1 is better than h264, and to download the best mp4 - Then you expect it to download h264!?

I looked through the readme and found I probably need to specify the video codec, and so I did by changing the first part of the command to: "bv*[vcodec=h264]". This works in that I get H264 video, but the issue is that the video is then limited to 720p (specifically the version that includes both audio and video in the same stream) even though a 1080p video-only stream is available. I've tried messing about with a few more options to no success (bar outright specifying the id each time).

Show verbose log

Any ideas on how I can get this to work while keeping AV1 as preferred in my config?

You can pass -S vcodec:h264 in the cmd to override the one in the config file

Mahir007 commented 2 years ago

So, you told yt-dlp that av1 is better than h264, and to download the best mp4 - Then you expect it to download h264!?

As I've only seen AV1 videos in MKV containers (and is how I setup my batch file for yt-dlp), I wasn't even aware you could put them in MP4's 😅

Show verbose log

C:\Users\user\AppData\Roaming\yt-dlp>yt-dlp -v --sub-langs en --embed-subs -f bv*[vcodec=h264]+ba[ext=m4a]/b[ext=mp4] https://www.youtube.com/watch?v=WxjeV10H1F0
[debug] Command-line config: ['-v', '--sub-langs', 'en', '--embed-subs', '-f', 'bv*[vcodec=h264]+ba[ext=m4a]/b[ext=mp4]', 'https://www.youtube.com/watch?v=WxjeV10H1F0']
[debug] Portable config "C:\Users\user\AppData\Roaming\yt-dlp\yt-dlp.conf": ['-o', 'E:/Downloads/%(title)s.%(ext)s', '--geo-bypass', '--no-mtime', '--add-metadata', '--embed-thumbnail', '--compat-options', 'no-live-chat', '--convert-thumbnails', 'png', '--sponsorblock-remove', 'sponsor,selfpromo', '--format-sort', 'lang,quality,res,fps,hdr:12,codec:av01,size,br,asr,proto,ext,hasaud,source,id']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.06.22.1 [a86e01e] (win32_exe)
[debug] Compatibility options: no-live-chat
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg N-107244-g0744c84792-20220625 (setts), ffprobe N-107244-g0744c84792-20220625
[debug] Optional libraries: Cryptodome-3.14.1, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=WxjeV10H1F0
[youtube] WxjeV10H1F0: Downloading webpage
[youtube] WxjeV10H1F0: Downloading android player API JSON
[youtube] WxjeV10H1F0: Downloading tv embedded player API JSON
[youtube] WxjeV10H1F0: Downloading web embedded client config
[youtube] WxjeV10H1F0: Downloading player 9c24c545
[youtube] WxjeV10H1F0: Downloading web embedded player API JSON
[debug] Loading youtube-nsig.9c24c545 from cache
[debug] [youtube] Decrypted nsig 5eoQo75iCfO0sTNLW0g => 3ixh2lhdJb0F_A
[debug] [youtube] Decrypted nsig tBfGznwO86S_BHZiRgP => r4bWZRcQrfmaNA
[debug] Sort order given by user: lang, quality, res, fps, hdr:12, codec:av01, size, br, asr, proto, ext, hasaud, source, id
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:av01(11), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[debug] Downloading subtitles: en
[SponsorBlock] Fetching SponsorBlock segments
[debug] SponsorBlock query: https://sponsor.ajay.app/api/skipSegments/96b9?service=YouTube&categories=%5B%22sponsor%22%2C+%22selfpromo%22%5D&actionTypes=%5B%22skip%22%2C+%22poi%22%5D
[SponsorBlock] No segments were found in the SponsorBlock database
[info] WxjeV10H1F0: Downloading 1 format(s): 22
[info] Writing video subtitles to: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt
[debug] Invoking http downloader on "https://www.youtube.com/api/timedtext?v=WxjeV10H1F0&caps=asr&xoaf=5&xosf=1&hl=en&ip=0.0.0.0&ipbits=0&expire=1656264211&sparams=ip%2Cipbits%2Cexpire%2Cv%2Ccaps%2Cxoaf&signature=315374DCFB62395CB153570A3426FA598A158830.48DF1F5C667B796F1C32D20B63210B70BC7A7C22&key=yt8&lang=en&fmt=vtt"
[debug] File locking is not supported. Proceeding without locking
[download] Destination: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt
[download] 100% of 1.57KiB in 00:00
[info] Downloading video thumbnail 45 ...
[info] Writing video thumbnail 45 to: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp
[ThumbnailsConvertor] Converting thumbnail "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp" to png
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -f image2 -pattern_type none -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.png"
Deleting original file E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp (pass -k to keep)
[debug] Invoking http downloader on "https://rr1---sn-jvhh4pcgx-ajte.googlevideo.com/videoplayback?expire=1656260611&ei=ozO4YsC0JMf1xwKamrvoCg&ip=147.12.237.126&id=o-ALDA1_OFhsEEBfYNXOQfifSgUdIcb3Y1iEauuztA1HsK&itag=22&source=youtube&requiressl=yes&mh=32&mm=31%2C29&mn=sn-jvhh4pcgx-ajte%2Csn-aigl6n7z&ms=au%2Crdu&mv=m&mvi=1&pl=18&initcwndbps=2728750&vprv=1&mime=video%2Fmp4&ns=DlebHkZB5J_qB7ir6zhMrs8G&cnr=14&ratebypass=yes&dur=90.139&lmt=1654876422424229&mt=1656238605&fvip=2&fexp=24001373%2C24007246&beids=24239133&c=TVHTML5_SIMPLY_EMBEDDED_PLAYER&txp=5532434&n=3ixh2lhdJb0F_A&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhAN2ScIUWcoI1SGyCNJ2-Mf64OtuyeNXNL38BGjsvEbnmAiB9xSrsMviwPrcLN60haFcNm2cafN4BFpGIF1sgajhHjg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAKpuksL3tL2pldlcFzNQ_CCAmEewZrhW00Ogh_JXTqshAiEA6ZYsJ6h1KFGrVzIqarXu6WNBLQZcLNDtrHZxYCRYM-A%3D"
[download] Destination: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4
[download] 100% of 14.51MiB in 00:00
[EmbedSubtitle] Embedding subtitles in "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt" -map 0 -dn -ignore_unknown -c copy "-c:s" mov_text -map "-0:s" -map "1:0" "-metadata:s:s:0" "language=eng" "-metadata:s:s:0" "handler_name=English" "-metadata:s:s:0" "title=English" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.temp.mp4"
Deleting original file E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt (pass -k to keep)
[ModifyChapters] SponsorBlock information is unavailable
[Metadata] Adding metadata to "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4" -map 0 -dn -ignore_unknown -c copy -write_id3v1 1 -metadata "title=The Last of Us Part I - Announce Trailer | PS5 Games" -metadata "date=20220609" -metadata "description=https://www.playstation.com/games/the-last-of-us-part-i/
--description shortened--" -metadata "purl=https://www.youtube.com/watch?v=WxjeV10H1F0" -metadata "comment=https://www.youtube.com/watch?v=WxjeV10H1F0" -metadata "artist=PlayStation" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.temp.mp4"
[EmbedThumbnail] mutagen: Adding thumbnail to "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"

You can pass -S vcodec:h264 in the cmd to override the one in the config file

Okay, it seems passing this argument versus what I tried intially in the command above actually works and now I get 1080p h264 videos as expected. Thanks for your quick response!

pukkandan commented 2 years ago

The issue is with vcodec=h264. It should be vcodec^=avc1. See the vcodec column in -F.

Since -S uses groups, it is smart enough to understand that h264=avc1, but -f uses string matching and so your condition must be exactly correct

Mahir007 commented 2 years ago

hmm, it seems using vcodec^=avc1 still exhibits the same behaviour (limited to that 720p stream) as just using vcodec=h264.

log:

>yt-dlp -v --sub-langs en --embed-subs -f bv*[vcodec^=avc1]+ba[ext=m4a]/b[ext=mp4] https://www.youtube.com/watch?v=WxjeV10H1F0
[debug] Command-line config: ['-v', '--sub-langs', 'en', '--embed-subs', '-f', 'bv*[vcodec=avc1]+ba[ext=m4a]/b[ext=mp4]', 'https://www.youtube.com/watch?v=WxjeV10H1F0']
[debug] Portable config "C:\Users\user\AppData\Roaming\yt-dlp\yt-dlp.conf": ['-o', 'E:/Downloads/%(title)s.%(ext)s', '--geo-bypass', '--no-mtime', '--add-metadata', '--embed-thumbnail', '--compat-options', 'no-live-chat', '--convert-thumbnails', 'png', '--sponsorblock-remove', 'sponsor,selfpromo', '--format-sort', 'lang,quality,res,fps,hdr:12,codec:av01,size,br,asr,proto,ext,hasaud,source,id']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.06.22.1 [a86e01e] (win32_exe)
[debug] Compatibility options: no-live-chat
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg N-107244-g0744c84792-20220625 (setts), ffprobe N-107244-g0744c84792-20220625
[debug] Optional libraries: Cryptodome-3.14.1, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=WxjeV10H1F0
[youtube] WxjeV10H1F0: Downloading webpage
[youtube] WxjeV10H1F0: Downloading android player API JSON
[youtube] WxjeV10H1F0: Downloading tv embedded player API JSON
[youtube] WxjeV10H1F0: Downloading web embedded client config
[youtube] WxjeV10H1F0: Downloading player 9c24c545
[youtube] WxjeV10H1F0: Downloading web embedded player API JSON
[debug] Loading youtube-nsig.9c24c545 from cache
[debug] [youtube] Decrypted nsig cofUjrOBpniqqdahjSe => HwaKowWPruyJjw
[debug] [youtube] Decrypted nsig BkkztjLyvTydtl3dw8N => VyG7tdvX87TfyA
[debug] Sort order given by user: lang, quality, res, fps, hdr:12, codec:av01, size, br, asr, proto, ext, hasaud, source, id
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:av01(11), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[debug] Downloading subtitles: en
[SponsorBlock] Fetching SponsorBlock segments
[debug] SponsorBlock query: https://sponsor.ajay.app/api/skipSegments/96b9?service=YouTube&categories=%5B%22selfpromo%22%2C+%22sponsor%22%5D&actionTypes=%5B%22skip%22%2C+%22poi%22%5D
[SponsorBlock] No segments were found in the SponsorBlock database
[info] WxjeV10H1F0: Downloading 1 format(s): 22
[info] Writing video subtitles to: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt
[debug] Invoking http downloader on "https://www.youtube.com/api/timedtext?v=WxjeV10H1F0&caps=asr&xoaf=5&xosf=1&hl=en&ip=0.0.0.0&ipbits=0&expire=1656328734&sparams=ip%2Cipbits%2Cexpire%2Cv%2Ccaps%2Cxoaf&signature=8D6C10F3581205FAEB3F8A9F93ED378B6449E88D.B0DFD337D39673B7928338D4FC4B9F689760F2EE&key=yt8&lang=en&fmt=vtt"
[debug] File locking is not supported. Proceeding without locking
[download] Destination: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt
[download] 100% of 1.57KiB in 00:00
[info] Downloading video thumbnail 45 ...
[info] Writing video thumbnail 45 to: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp
[ThumbnailsConvertor] Converting thumbnail "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp" to png
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -f image2 -pattern_type none -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.png"
Deleting original file E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.webp (pass -k to keep)
[debug] Invoking http downloader on "https://rr1---sn-jvhh4pcgx-ajte.googlevideo.com/videoplayback?expire=1656325131&ei=qy-5Yu2HL4Tf1gbTxarADQ&ip=147.12.237.126&id=o-APEnb5taP3qbodNa2shvRsOvAhfZdCQOQ3VpEdNE4C3P&itag=22&source=youtube&requiressl=yes&mh=32&mm=31%2C29&mn=sn-jvhh4pcgx-ajte%2Csn-aigl6n7z&ms=au%2Crdu&mv=m&mvi=1&pl=18&initcwndbps=1426250&vprv=1&mime=video%2Fmp4&ns=kGwd8tXPbXRhOtDtsVaULfEG&cnr=14&ratebypass=yes&dur=90.139&lmt=1654876422424229&mt=1656303167&fvip=2&fexp=24001373%2C24007246&c=TVHTML5_SIMPLY_EMBEDDED_PLAYER&txp=5532434&n=HwaKowWPruyJjw&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgLt4A0ePxTj65bHVXNm-6YDr_ONVI3a--mNSk-nqKDh8CIQCfdh1Y2__SdLBOyESigmBTL5--b6RqsyCa20oPUfF_Kg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgSBnWjL1pDnIVoPhmJZ8kXzFF-ylM2hAjOPLq8Zg-L3gCIAWmJuFVXCm8k4wIDE1VlMK70zSHjV10iCAK7zLgoRX7"
[download] Destination: E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4
[download] 100% of 14.51MiB in 00:13
[EmbedSubtitle] Embedding subtitles in "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt" -map 0 -dn -ignore_unknown -c copy "-c:s" mov_text -map "-0:s" -map "1:0" "-metadata:s:s:0" "language=eng" "-metadata:s:s:0" "handler_name=English" "-metadata:s:s:0" "title=English" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.temp.mp4"
Deleting original file E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.en.vtt (pass -k to keep)
[ModifyChapters] SponsorBlock information is unavailable
[Metadata] Adding metadata to "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4" -map 0 -dn -ignore_unknown -c copy -write_id3v1 1 -metadata "title=The Last of Us Part I - Announce Trailer | PS5 Games" -metadata "date=20220609" -metadata "description=https://www.playstation.com/games/the-last-of-us-part-i/
~~description~~" -metadata "purl=https://www.youtube.com/watch?v=WxjeV10H1F0" -metadata "comment=https://www.youtube.com/watch?v=WxjeV10H1F0" -metadata "artist=PlayStation" -movflags "+faststart" "file:E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.temp.mp4"
[EmbedThumbnail] mutagen: Adding thumbnail to "E:\Downloads\The Last of Us Part I - Announce Trailer _ PS5 Games.mp4"
pukkandan commented 2 years ago

'-f', 'bv*[vcodec=avc1]+ba[ext=m4a]/b[ext=mp4]'

Quote the selector. You shell is consuming the ^

Mahir007 commented 2 years ago

Quote the selector. You shell is consuming the ^

Ahh okay, working perfectly now. Thanks again for your help!!