Download Youtube videos in highest quality available

Download Youtube videos in highest quality available.

Note: Homebrew is a package manager for Mac only, you’ll need to find an alternative method for installing these libraries if you’re on Windows or Linux.

Install some libraries:

# the downloader
brew install youtube-dl
# for merging video and audio
brew install ffmpegCode language: PHP (php)

Download best quality audio and video and merge into one mp4:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' 'url' --merge-output-format mp4Code language: JavaScript (javascript)

With auth:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' -u 'email' -p 'password' 'url' --merge-output-format mp4Code language: JavaScript (javascript)

Download best quality audio only:

youtube-dl -f 'bestaudio[ext=m4a]/bestaudio' --embed-thumbnail --add-metadata 'url'Code language: JavaScript (javascript)

Login required?

Download age restricted or private videos that require you to be logged in to YouTube.

  1. Download the Chrome extension “Get cookies.txt LOCALLY”
  2. Visit the YouTube you want to download (while logged in and able to view the video)
  3. Use the extension to export cookies
  4. Add the flag `–cookies ‘yt-cookies.txt’` to your command (assuming you renamed the text file)
  • If you’re still receiving these error/s your cookies may have expired, export them again
Errors indicating that you need to do this
ERROR: unable to download video data: HTTP Error 403: ForbiddenCode language: JavaScript (javascript)
WARNING: Unable to look up account info: HTTP Error 400: Bad Request
WARNING: unable to download video info webpage: HTTP Error 410: Gone
ERROR: Sign in to confirm your age
This video may be inappropriate for some users.Code language: JavaScript (javascript)

More helpful and related utility

Use FFmpeg to convert mp4 to m4a without transcode

ffmpeg -i input.mp4 -map 0:a -c copy output.m4aCode language: CSS (css)


for file in *.mp4; do ffmpeg -i "$file" -vn -c:a copy "output/$(basename "$file" .mp4).m4a"; doneCode language: PHP (php)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.