youtube-dl

youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform specific - gitbub

It should work on your Unix box, on Windows or on Mac OS X. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.

youtube-dl [OPTIONS] URL [URL...]

OS X users can install youtube-dl with Homebrew:

brew install youtube-dl

# Downloading mp4

By default the current version youtube-dl will download the highest quality audio and the highest quality video streams available and then join these streams into a compatible container - askubuntu.com

Current choices of container are mkv, mp4, ogg, webm, flv, avi is also supported through the --recode-video option.

If these 'best' streams are codecs that do not sit well in an mp4 container, for example, youtube-dl will pack them into an mkv container and issue the warning that you have seen.

Mind you vlc, SMPlayer and friends will play back the resulting mkv file with no issues on a well configured Ubuntu system.

If however you are really keen to get the best quality video and the best quality video audio but only in an mp4 container (thus bypassing the mkv warning and subsequent Matrosk container output from youtube-dl) you can use something like the following:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' URL

Obviously substituting the 'URL' value for the address of the youtube video you wish to download. Such a relatively complex command line can be placed permanently in the configuration file:

~/.config/youtube-dl/config

as follows:

-f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]'

This way it is now the default for youtube-dl and does not need to be given on the command line each time.

# Format selection

By default youtube-dl tries to download the best available quality. I that is not what you want the general syntax for format selection is --format FORMAT or shorter -f FORMAT where FORMAT is a an expression that describes format or formats you would like to download.

You can use a file extension (currently 3gp, aac, flv, m4a, mp3, mp4, ogg, wav, webm are supported) to download the best quality format of a particular file extension served as a single file, e.g. -f webm will download the best quality format with the webm extension served as a single file.

You can also use special names to select particular edge case formats:

- best - worst - bestvideo - worstvideo - bestaudio - worstaudio

DASH video if it exists will often be the best quality available.

# Format selection examples

Note that on Windows you may need to use double quotes instead of single - [dasf github]

# Download best mp4 format available or any other best if no mp4 available $ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' # Download best format available but not better that 480p $ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]' # Download best video only format but no bigger than 50 MB $ youtube-dl -f 'best[filesize<50M]' # Download best format available via direct link over HTTP/HTTPS protocol $ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]' # Download the best video format and the best audio format without merging them $ youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'

Note that in the last example, an output template is recommended as bestvideo and bestaudio may have the same file name.

Animated Gifs are not just a popular medium but hey also work nicely with Federated Wiki.