2016-12-20 Extract YouTube Audio

This is easy to do if you have youtube-dl. [1]

youtube-dl.exe --extract-audio --audio-format mp3 https://youtu.be/...

On Windows, you need to install both youtube-dl and ffmpeg for Windows:

./youtube-dl.exe --extract-audio --audio-format=mp3 --ffmpeg-location=/Portable\ Programs/ffmpeg-20161218-02aa070-win64-static/bin/ffmpeg.exe https://www.youtube.com/watch?v=u4DZPemB4uI

If you downloaded the mp4 file and forgot the transformation to mp3, you can do that, too:

ffmpeg -i somefile.mp4 -q:a 0 -map a somefile.mp3

This will give you one big file. But if you know the number of tracks, you can get a copy of mp3splt. I got the zipfile, unzipped it, and ran it on my file as follows, given that I knew this file contained 25 tracks:

mp3splt_2.6.2_i386/mp3splt.exe -s -p nt=25,rm foo.mp3

And here’s how you can add the metadata, if you have the track list:

i=1
while read title; do
    file="fileprefix_$(printf "%02d" $i).mp3"
    mp3info -a "artist" -c "URL or whatever" -g 24 -l "album" -n $i -t "$title" -y 2013 "$file"
    i=$(($i + 1))
done <<EOF
title for track 1
title for track 2
title for track 3
title for track 4
...
title for track 25
EOF

Tags:

Comments

@fitheach said that this will be re-encoding the audio from one lossy to another, and this is true. Here’s an alternative:

youtube-dl -F https://www.youtube.com/watch?v=QS6b8JKzUeo

This shows the existing formats and their codes (first column). You could download WebM with Opus or Vorbis, for example. Use -f and the code you want to download just that format.

Then use ffmpeg to copy out the audio (example Vorbis):

ffmpeg -i "$file" -vn -acodec copy  "OGG/$nosuffix.ogg"

You need to know the codecs your player supports, of course. Perhaps mp3 is all it can do. I installed Rockbox on my iPod, however, and it supports a lot, apparently!

– Alex Schroeder 2019-04-19 08:39 UTC


Please make sure you contribute only your own work, or work licensed under the GNU Free Documentation License. Note: in order to facilitate peer review and fight vandalism, we will store your IP number for a number of days. See Privacy Policy for more information. See Info for text formatting rules. You can edit the comment page if you need to fix typos. You can subscribe to new comments by email without leaving a comment.

To save this page you must answer this question:

Please say HELLO.