sudo apt install ffmpeg
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
-xdownloads 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:
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
-vn disables video in the output.