Download audio from YouTube
Install ffmpeg:
sudo apt install ffmpeg
Install youtube-dl
, a tool to download YouTube videos. Using apt
installs a
version that's too old to work, so:
pip install --user pipsi
pipsi install youtube-dl
The best way
Tell youtube-dl to download the audio:
youtube-dl -x --audio-format=best URL
Where:
-
-x
downloads just the audio part. - Audio format defaults to 'best', but can be "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav".
- URL is an encoded version of the video URL (youtu.be/XXX), obtained by hitting the 'share' button on the youtube page.
As I understand it, it downloads whatever audio format YouTube provides, then converts it locally using ffmpeg, so you're not really getting the benefit of those lossless formats - mp3 is fine for my needs.
My previous inferior way
This method is worse because it downloads the whole video file before extracting audio locally, and the download gets throttled by YouTube in some way, which of late is very slow indeed.
Download the video from YouTube:
youtube-dl URL
This results in a webm file. I have no idea what that is, and am relieved to discover that converting it into an mp3 requires just:
ffmpeg -i MyVideoFile -vn MyAudioFile.mp3
Where -vn
disables video in the output.