How to download youtube video
Here is small tutorial on how to download video from youtube.
If google “how to download youtube videos” you will find a lot of options on how to do it. It will be websites (with a lot of ads) or programs (who know if they aren’t malware). So I decided to find more secure way to do it.
I found open source project https://github.com/rg3/youtube-dl on github. Many peoples are supporting it right now. It supports many other websites besides youtube.
If you know how to work with command line and/or Python you will find all required information https://github.com/rg3/youtube-dl.
Bellow I’ll show how to use youtube-dl on Windows.
- Create folder on your PC where you put all files. For example create folder with name
youtube
on driveC:\
. - Download youtube-dl.exe file to
C:\youtube
.
- Click on Start menu or press “Windows” button and type cmd.
- Click on Command Prompt to start it.
- Type
cd c:\youtube
- Type in Command Prompt next command
youtube-dl.exe --help
If it prints a lot of text then you did everything right.
Now we can start downloading video. As example I’m going to use Marvel Studios' Avengers - Official Trailer
- First what we need is youtube URL. https://www.youtube.com/watch?v=hA6hldpSTF8
- From this URL we need only last part hA6hldpSTF8
- Type (or copy/paste) in Command Prompt following command
youtube-dl -o "%(title)s.%(ext)s" hA6hldpSTF8
- As result you should see something similar:
- Video should be in C:\youtube.
In most cases this should be enough.
Now if you start video you notice that it has resolution 1280x720 (as for today). By default youtube-dl downloads best quality video with audio available. In this case this is 1280x720. It means that better video quality comes without audio.
- type this command
youtube-dl -F hA6hldpSTF8
Take a look at lines that begin from 251 and 137.
251 webm is best quality audio and 137 mp4 is best quality video.
- in order to download these files type command
youtube-dl -f "bestvideo+bestaudio/best" -o "%(title)s.%(ext)s" hA6hldpSTF8
It will download 2 files
There are 2 warnings in Command Prompt
Lets start with 2nd warning:
Requested formats are incompatible for merge and will be merged into mkv.
In our case compatible video and audio formats are mp4 m4a and webm webm
- use this command to download mp4 m4a
youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best" -o "%(title)s.%(ext)s" hA6hldpSTF8
- use this command to download webm webm
youtube-dl -f "bestvideo[ext=webm]+bestaudio[ext=webm]/best" -o "%(title)s.%(ext)s" hA6hldpSTF8
Now 1st warning:
You have requested multiple formats but ffmpeg or avconv are not installed. The formats won’t be merged.
In order to solve it you need to download either ffmpeg or avconv. I’m using ffmpeg https://www.ffmpeg.org/download.html.
- Follow the link and download latest 64 bit static package. See screenshot:
- today it’s https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-4.1-win64-static.zip
- Open downloaded .zip file, find
ffmpeg.exe
and copy it tocd c:\youtube
Now you can repeat last download commands:
- use this command to download mp4 m4a
youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best" -o "%(title)s.%(ext)s" hA6hldpSTF8
- use this command to download webm webm
youtube-dl -f "bestvideo[ext=webm]+bestaudio[ext=webm]/best" -o "%(title)s.%(ext)s" hA6hldpSTF8
Now these commands download and merge audio and video in one media file.