Most useful YouTube-DL commands (for audio extraction and conversion, M4A/MP4)

If you are a lover of offline video and audio extraction, you probably know youtube-dl.

Since WEBM gains popularity on YT you have to go new ways, if you are an old-timer like me, who likes to stick with MP4/M4A. But I am not the only one, as the discussions show.

Here are some of my old and new favorites

Audio only / Extracting audio

Extract audio from a YouTube video and convert it to mp3 or m4a (requires ffmpeg installed and in PATH):

youtube-dl URL --extract-audio --audio-format mp3 | m4a

You might want to specific download location:

youtube-dl --output /path/to/your/dir 

But this does not work so well on windows (you often get a wired file name) and in combination with advanced commands. An OUTPUT TEMPLATE can help out.

Extract/convert & download to another location wit that preserves the title of the video:

youtube-dl URL --output "d:\dl\%(title)s.%(ext)s" --extract-audio --audio-format aac

Alternatively, if you don’t want to extract, you could also just download the audio, preferred m4a:

youtube-dl URL -f bestaudio[ext=m4a]/mp4 --output "D:\DL\%(title)s.%(ext)s" 

But: Some audio players do not support DASH audio. For m4a, I had to demux it to make it a ‘regular’ m4a using ffmpeg.

ffmpeg -I input.m4a -vn -c:a copy output.m4a 

(The downside of this method is that you have to do an extra step that makes good use of your drive and CPU.)

Or: Download just mp4 audio and extract/convert it afterwards:

youtube-dl URL -f bestaudio[ext=m4a]/mp4 --extract-audio --audio-format m4a --output "D:\DL\%(title)s.%(ext)s"

(The downside of this method is that you have to download more data).

Best Best video and audio in MP4 & M4A/AAC

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

This filter will give you the best MP4/AAC audio and MP4 video.
According to my own experience the difference to the best WEBM video is rather small (~5-8%). But your millage may vary.

The best audio is most of the time already AAC/M4A. So, don’t worry about that.

That’s it.