This is a general guide for downloading video from youtube, but I’ll include some specifics for 4K video.
First thing you’ll need is youtube-dl. This is a command line utility. It’s actually python based, but there’s an all-inclusive windows exe file that you will be using. Note that this exe file is actually a self-executing archive that contains all the python runtimes and scripts, and because of this it tends to freak out windows defender. It will very likely continually prompt you to send the file for analysis. Do it or not. Up to you. This executable is all you need for mp4 downloads up to 1080p. For different format muxing and for 4k downloads, you’ll need a copy of ffmpeg as well. I just grabbed a static 64bit build. You can extract the ffmpeg.exe binary and put it in to the same folder as youtube-dl.exe.
For your basic usage, just run
youtube-dl [youtube url] and it will automatically grab the best single (audio+video) file for you in mp4 format. This will be anything up to 1080p.
Laziness is the mother of invention, apparently, so I created a quick batch file to grab a list of URLs. I discovered afterwards that youtube-dl has a batch download function, but I had problems with it, so I reverted back to using my batch file:
Because I am cunning, I named the file ‘get.bat’ (put it in the same folder as the youtube-dl binary) and stuck the below line in to it.
@For /F "tokens=1" %%A in (get.txt) do youtube-dl -o "%%(title)s.%%(ext)s" %%A
Then, create a file called ‘get.txt’ (same folder as get.bat) and put your youtube URLs, one per line:
Then simply run get.bat and you’ll soon have a bunch of mp4s.
Rename the batch file and text file as you wish, just remember to edit the batch file so it knows the new name of the text filename you chose.
Any video on youtube that has a res higher than 1080p is a video stream only. The audio stream is separate and requires muxing in to a single file. Fortunately youtube-dl can do this for you, but it requires the presence of ffmpeg.exe, so if you haven’t grabbed it yet, go get it.
Make sure the youtube video you want to download in 4K actually has a 4K stream. On the youtube video page, if you go to settings-quality on the vid, 2160p should be listed. I’ve come across at least one supposed 4K video that wasn’t.
If you need a specific video and audio codec, you can see what is available on the video by running:
youtube-dl -F [video url]
You can use the format bestvideo+bestaudio and let youtube-dl figure it out for you, but I’ve had problems with that as it usually selects the Opus audio stream, which my TV doesn’t like, so I manually select vorbis. I could use bestvideo+171 which would work for me in most cases, but my TV is finicky, and I know it likes the webm format (VP9), so my preferred formats are 313+171, which all of the 4K vids I have downloaded so far have had, and they work brilliantly.
So create a ‘get4k.bat’ file, and add the line:
@For /F "tokens=1" %%A in (get.txt) do youtube-dl -o "%%(title)s.%%(ext)s" --format 313+171 --merge-output-format mkv %%A
This uses the same ‘get.txt’ as the previous batch, but change it up as you like. Also change the format parameter to your preferred streams.
Note that I have specified the output format to be mkv. If you change this to mp4, youtube-dl doesn’t like it. It might have something to do with the specific formats and the container type, but it will throw a header write error. If you change the output format back to mkv, it will merge the already downloaded formats into the mkv file (so you don’t have to worry about downloading that huge video stream again).
Youtube-dl can be used for other video sites, not just youtube. Check the docs for info.