Downloading YouTube videos as audio with yt-dlp

How to Download audio from a YouTube video using yt-dlp.

For more information on yt-dlp general usage read this post.

yt dlp install and usage guide

As you will more than likely be wanting the best quality audio the format (-f) selector will be for best audio (ba).

yt-dlp -f 'ba' https://www.youtube.com/watch?v=dQw4w9WgXcQ -o '%(id)s.%(ext)s'

To save as the video title change %(id)s.%(ext)s to '%(title)s.%(ext)s' to save. For a custom filename songname.%(ext)s.

With YouTubes VP9 codec this file will most likely be .webm or .opus extension.

Saving video as an MP3 file

To save the highest quality audio as an mp3 file you need to define --audio-format mp3 with -x which is extract audio

yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v=dQw4w9WgXcQ  -o '%(id)s.%(ext)s'