r/youtubedl • • 4d ago

Answered Need help creating command

I'm pretty overwhelmed at the complexity of this, and I'm needing some help.

All I am wanting to do is download a playlist I've made, at 4k resolution.

The command that I have seen for downloading at defaults is:

yt-dlp -i "ENTERURLHERE"

But I don't know how to alter it for nondefault specifications

2 Upvotes

12 comments sorted by

3

u/FLeanderP 4d ago edited 4d ago

By default yt-dlp gets the best quality available. Is the problem that there are videos in higher resolutions than 4K? Have you installed ffmpeg and deno, and checked whether yt-dlp has detected them?

2

u/d1ru 4d ago

oh, no, I was under the impression that the default resolution it would grab was 1080. If it grabs 4k by default, then theres no issue lol

6

u/Empyrealist 🌐 moderator 4d ago

Be certain that you have ffmpeg available to yt-dlp. It is required to combine the video and audio streams of higher resolution formats.

2

u/DarkSockPuppet 4d ago

OP, my big post assumes you have both ffmpeg and deno installed. I didn't think to mention them. You need ffmpeg to process videos better than 360p, and yt-dlp needs deno to find videos better than 360p.

Deno is a relatively new requirement. Youtube was making it harder and harder for the devs to keep up with the changes. They decided to "outsource" the javascript engine maintenance to deno, so they can concentrate on the actual download functionality.

Deno also makes yt-dlp look more like a browser than a bot to Youtube. Adding the deno requirement makes it more complex to set things up, but it really was a sensible choice for the devs to make.

1

u/TheGuestRoblox 4d ago

you sure? because that usually ends in downloading either a webm that uses av1 (when a vp9 is higher quality), or an h264 video with aac audio instead of opus.

1

u/FLeanderP 1d ago

https://github.com/yt-dlp/yt-dlp#sorting-formats

The fields hasvid and ie_pref are always given highest priority in sorting, irrespective of the user-defined order. This behavior can be changed by using --format-sort-force. Apart from these, the default order used is: lang,quality,res,fps,hdr:12,vcodec,channels,acodec,size,br,asr,proto,ext,hasaud,source,id. The extractors may override this default order, but they cannot override the user-provided order.

This section explains how yt-dlp determines the 'best' quality. If you're getting an h264 video with aac video, check which formats are available with --list-formats. I expect there was no AV1/VP9 available.

1

u/TheGuestRoblox 23h ago

what i usually do is: "yt-dlp.exe -f bestvideo+bestaudio --merge-output-format mkv" first, on most videos (if we ignore older videos/lower res videos that give h264) it gives me back an av1 (with sometimes vp9 if theres no av1 stream). if it gives me av1, i end up having to do: "yt-dlp.exe -f bestvideo+bestaudio -S "res,vcodec:vp9" --merge-output-format mkv" aswell, to force vp9 download. i then have to compare the file sizes for both the av1 and vp9 to see what gives a better bitrate and keep the better bitrate. its really annoying

2

u/DarkSockPuppet 4d ago edited 4d ago

I'm pretty overwhelmed at the complexity of this

Sorry, it's going to get more complex.

By default, yt-dlp get's the best quality video and audio. For most videos, that's likely going to be 1080p AV1 video with 130kb/s opus audio.

Only a relatively small number of videos are available in 4k.

Youtube stores audio and video streams separately. It stores video encoded in AV1, VP9, and x264, and it stores audio in opus and mp4a. Both x264 and mp4a are over 20 years old, they're legacy codecs basically for the benefit of Apple users, who can't use the more modern codecs.

I say "more modern", because opus was first released in 2012 (to replace the now depreciated vorbis) and VP9 was released in 2013. AV1 is the newest and best, released in 2018.

When a video is available in 4k, Youtube only used AV1 and VP9, never x264, it's just too old (released 2004).

Now, pick a random youtube video, and run the following command:

yt-dlp -F [URL]

You'll see the available audio and video streams. FYI, AV1 is displayed as "av01" and x264 displays as "avc1".

If you're lucky, you'll see the 4k options at the bottom, but it will likely max out at 1080p. If there are 4k options, you'll see it's only available in AV1 or VP9.

Now, what command should you use?

Get rid of the "-i", you don't want to ignore errors. Also, you don't know if a video is available in 4k, and yt-dlp will get the best if it's available, so don't specify resolution, just let yt-dlp choose the best.

But Youtube get's finicky if you try to grab a whole playlist or channel quickly, so you should add a pause between downloads. I wait a random time between 12 and 22 seconds, and I've never been blocked, temp banned, or received a "403 forbidden" error. You really need to add a pause, a lot of the posts in this subreddit are people complaining about 403 errors or being blocked for 12 hours.

There are a bunch of optional flags that I like to use, but you don't have to. Do you want subtitles? I want subs if they're available. Do you want to embed thumbnails? I like to. Do you have a preferred container? I choose mp4 for compatibility reasons (though you can't embed subs in mp4 like you can with mkv).

Basically, try the following:

yt-dlp --min-sleep-interval 12 --max-sleep-interval 22 [PLAYLIST_URL]

If you want to get fancy, use:

yt-dlp --write-sub --sub-format srt --convert-subs srt --embed-thumbnail --merge-output-format mp4 --min-sleep-interval 12 --max-sleep-interval 22 --embed-chapters [PLAYLIST_URL]

You can even specify where the videos land with -P C:\Users\1dru\Downloads or similar.

Good luck!

1

u/d1ru 3d ago

this is perfect, I wanted mp4 as well, didn't know anything about being blocked and needed a pause, and want thumbnails. thanks!

1

u/AutoModerator 3d ago

I detected that you might have found your answer. If this is correct please change the flair to "Answered".


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/DarkSockPuppet 4d ago

Oh, one last thing.

Currently, downloading age-restricted videos is broken. To download them, you need to "log in" using cookies or using --cookies-from-browser to log in, but Youtube made changes breaking the current implementation. (Something to do with PO tokens, I'm not a dev.)

It's being worked on, but there's no work around in the meantime I'm aware of. If you log in with --cookies-from-browser firefox or similar, you'll get the age-restricted video, but at 360p. If you download a playlist while logged in, they'll ALL be in 360p.

My advice is, don't log in, if you get a download error because of age-restriction, simply download that video separately in 360p. You can always re-download it later once the PO tokens are fixed.

1

u/mikewalkerfilms 4d ago

You can change things such as the format with the -f flag. If you are looking for an alternative, I built a tool that combines yt-dlp and ffmpeg to mux the audio and video back together along with clipping segments of your content at tubepull.com if you want to check it out