I spent the past day or so figuring out how to get high quality audio from YouTube videos. This post demonstrates my results. All software in this post is freely available, and open source where possible. This method should not be used to rip music from YouTube videos, as that may or may not constitute copyright infringement.
First, I'll explain quality levels on YouTube. There are three levels of quality on YouTube; there's standard (low) quality, there's medium quality, and there's high quality. Some videos have a high quality button that lets you view them in HQ, but not every video has this, even though they may actually have a higher quality. Note that the quality of a video will never be higher than the original upload. You can't get something from nothing.
There's also high definition, but I honestly don't know or care enough about that to bother to look into it.
If you want to see if a video has a high quality mode, but there's no HQ button on the video itself, there's an easy way to find out. Watch a few seconds in standard definition, then add &fmt=18 to the end of the URL and watch a few seconds of the new video. If it looks and sounds better than the original, it's got a high or medium quality version. If you want to view it in medium quality, add &fmt=6 to the end instead.
YouTube videos are stored in different ways depending on their quality. Standard and medium quality videos are stored on YouTube as .flv files. FLV is a container format; in other words, it's a file that holds other files. In this case, there are two files: an audio file (mp3) and a video file (avi).
High quality videos on YouTube are stored in a different container format, known as MPEG-4 Part 14, or .mp4 files. Much like FLV files, they contain a number of other files inside. With YouTube MP4s, there will be an audio file (aac) and a video (H.264) file.
Downloading
To download standard quality, I recommend using Better YouTube addon for Firefox and enabling the "download link" option. If you're using Firefox 3.1 beta, contact me and I'll tell you how to force the addon to install; if you're using any version prior to that, it should install fine.
There's no easy way to download medium quality, nor is there a compelling reason to. Contact me if you need an explanation, but it's unnecessary as you can just convert the output from the MP4 to an MP3, which I'll explain later.
To download high quality or high definition, use this addon. Once again, if you're using Firefox 3.1 beta, contact me and I'll help you force it to install.
Extracting the Audio
Once you're done downloading, you'll either have an FLV file if you downloaded standard or medium quality, or an MP4 file if you downloaded high quality. It will be named "video," so you should probably rename it for reference.
If you have an FLV file, it's extremely easy to extract the audio file out. Start FLV Extract and make sure only the "audio" box is checked, then just drag the FLV file into the program, and it should produce an MP3 file with the same name.
On the other hand, if you have an MP4 file, you'll have to go through a lot more trouble. There are two ways to do it. If you just want to play the audio file on your computer, I recommend taking the first approach; however, if you need the file to be in MP3 format, you'll want to take the second approach. Both ways require use of programs that use the command prompt, but I'll tell you exactly what you need to do.
First way
In this method, you'll end up with an audio file in the AAC format. This format is essentially the successor to MP3. Most media players do not support it by default yet (WMP 11 doesn't, but it has been confirmed that WMP 12 will); however, support can be enabled with a plugin (download and install here). However, if you're willing to use it, VLC Media Player supports AAC by default.
To obtain the AAC file, you will only need one program: MP4Box. Create a folder called MP4Box in C:\ and extract the contents of the link to that folder. Place your MP4 file into the folder as well. Then, start up the command prompt (Windows key + "R", then type cmd). Type "C:" and press enter. Type "cd C:\MP4Box" and press enter. This will make sure that you are on the C drive and will place you in the folder where MP4Box is located. After you've done this, type "mp4box -raw 1 $VIDEONAME.mp4", where $VIDEONAME is the name of your video file. This dumps the audio stream (1) from the MP4 file into an AAC file with a similar file name to the original. You can exit the command prompt by typing "exit" and pressing enter. You now have a playable AAC file, provided your media player supports the format (discussed earlier). You can delete the original MP4 file if you want.
Second Way
In this method, you'll end up with an MP3 file, which will be slightly lower quality than the original file, though still higher quality than the medium quality on YouTube (MP3 compression loses more than AAC compression, so there's no way around this). Pretty much every media player in existence supports MP3, so playing it should not be a problem.
You will need two programs for this method: Audacity (Audacity Portable link here) and MPlayer (save to a new folder in C:\ called MPlayer). Also place your MP4 file in C:\MPlayer, which you should have just created. You will also need lame_enc.dll, which is included in this archive. Extract lame_enc.dll to somewhere you can get at it easily, and remember where you put it.
First, open up the command prompt (Windows key + "R", then type cmd). Navigate to the MPlayer folder (first, type "C:" to make sure you are in the C drive, then type "cd C:\MPlayer" to change directories to the MPlayer folder). Type "mplayer -ao pcm -vo null -vc dummy $VIDEONAME.mp4" to obtain a non-compressed WAV audio file from the MP4 file, where $VIDEONAME is the name of your MP4 file. The WAV will be named "audiodump.wav," I believe. WAV files are bulky, however, and aren't as useful as MP3s.
This is where Audacity comes in. Open the WAV file using Audacity. Once it's done loading, go to File and select "Export as MP3." It will then ask you to locate lame_enc.dll, so find where you put it and click OK. It will then ask you to tag your MP3 file. Use the flexible version unless you're going to be playing the MP3 on ancient hardware, and make sure to select the genre of your audio from the list (Rock, Anime, Classical, Blues, Speech, Humor; there are about 100 different genres you can tag it with). Close Audacity, and type "exit" in the command prompt to exit it. You now have a completely unrestricted, playable MP3 file for however you wish to use it. You may want to delete the WAV file, as it'll likely be as large or larger than the original MP4. You can delete the MP4 as well.
If you have any questions, feel free to ask; I'll help to the best of my ability.
First, I'll explain quality levels on YouTube. There are three levels of quality on YouTube; there's standard (low) quality, there's medium quality, and there's high quality. Some videos have a high quality button that lets you view them in HQ, but not every video has this, even though they may actually have a higher quality. Note that the quality of a video will never be higher than the original upload. You can't get something from nothing.
There's also high definition, but I honestly don't know or care enough about that to bother to look into it.
If you want to see if a video has a high quality mode, but there's no HQ button on the video itself, there's an easy way to find out. Watch a few seconds in standard definition, then add &fmt=18 to the end of the URL and watch a few seconds of the new video. If it looks and sounds better than the original, it's got a high or medium quality version. If you want to view it in medium quality, add &fmt=6 to the end instead.
YouTube videos are stored in different ways depending on their quality. Standard and medium quality videos are stored on YouTube as .flv files. FLV is a container format; in other words, it's a file that holds other files. In this case, there are two files: an audio file (mp3) and a video file (avi).
High quality videos on YouTube are stored in a different container format, known as MPEG-4 Part 14, or .mp4 files. Much like FLV files, they contain a number of other files inside. With YouTube MP4s, there will be an audio file (aac) and a video (H.264) file.
Downloading
To download standard quality, I recommend using Better YouTube addon for Firefox and enabling the "download link" option. If you're using Firefox 3.1 beta, contact me and I'll tell you how to force the addon to install; if you're using any version prior to that, it should install fine.
There's no easy way to download medium quality, nor is there a compelling reason to. Contact me if you need an explanation, but it's unnecessary as you can just convert the output from the MP4 to an MP3, which I'll explain later.
To download high quality or high definition, use this addon. Once again, if you're using Firefox 3.1 beta, contact me and I'll help you force it to install.
Extracting the Audio
Once you're done downloading, you'll either have an FLV file if you downloaded standard or medium quality, or an MP4 file if you downloaded high quality. It will be named "video," so you should probably rename it for reference.
If you have an FLV file, it's extremely easy to extract the audio file out. Start FLV Extract and make sure only the "audio" box is checked, then just drag the FLV file into the program, and it should produce an MP3 file with the same name.
On the other hand, if you have an MP4 file, you'll have to go through a lot more trouble. There are two ways to do it. If you just want to play the audio file on your computer, I recommend taking the first approach; however, if you need the file to be in MP3 format, you'll want to take the second approach. Both ways require use of programs that use the command prompt, but I'll tell you exactly what you need to do.
First way
In this method, you'll end up with an audio file in the AAC format. This format is essentially the successor to MP3. Most media players do not support it by default yet (WMP 11 doesn't, but it has been confirmed that WMP 12 will); however, support can be enabled with a plugin (download and install here). However, if you're willing to use it, VLC Media Player supports AAC by default.
To obtain the AAC file, you will only need one program: MP4Box. Create a folder called MP4Box in C:\ and extract the contents of the link to that folder. Place your MP4 file into the folder as well. Then, start up the command prompt (Windows key + "R", then type cmd). Type "C:" and press enter. Type "cd C:\MP4Box" and press enter. This will make sure that you are on the C drive and will place you in the folder where MP4Box is located. After you've done this, type "mp4box -raw 1 $VIDEONAME.mp4", where $VIDEONAME is the name of your video file. This dumps the audio stream (1) from the MP4 file into an AAC file with a similar file name to the original. You can exit the command prompt by typing "exit" and pressing enter. You now have a playable AAC file, provided your media player supports the format (discussed earlier). You can delete the original MP4 file if you want.
Second Way
In this method, you'll end up with an MP3 file, which will be slightly lower quality than the original file, though still higher quality than the medium quality on YouTube (MP3 compression loses more than AAC compression, so there's no way around this). Pretty much every media player in existence supports MP3, so playing it should not be a problem.
You will need two programs for this method: Audacity (Audacity Portable link here) and MPlayer (save to a new folder in C:\ called MPlayer). Also place your MP4 file in C:\MPlayer, which you should have just created. You will also need lame_enc.dll, which is included in this archive. Extract lame_enc.dll to somewhere you can get at it easily, and remember where you put it.
First, open up the command prompt (Windows key + "R", then type cmd). Navigate to the MPlayer folder (first, type "C:" to make sure you are in the C drive, then type "cd C:\MPlayer" to change directories to the MPlayer folder). Type "mplayer -ao pcm -vo null -vc dummy $VIDEONAME.mp4" to obtain a non-compressed WAV audio file from the MP4 file, where $VIDEONAME is the name of your MP4 file. The WAV will be named "audiodump.wav," I believe. WAV files are bulky, however, and aren't as useful as MP3s.
This is where Audacity comes in. Open the WAV file using Audacity. Once it's done loading, go to File and select "Export as MP3." It will then ask you to locate lame_enc.dll, so find where you put it and click OK. It will then ask you to tag your MP3 file. Use the flexible version unless you're going to be playing the MP3 on ancient hardware, and make sure to select the genre of your audio from the list (Rock, Anime, Classical, Blues, Speech, Humor; there are about 100 different genres you can tag it with). Close Audacity, and type "exit" in the command prompt to exit it. You now have a completely unrestricted, playable MP3 file for however you wish to use it. You may want to delete the WAV file, as it'll likely be as large or larger than the original MP4. You can delete the MP4 as well.
If you have any questions, feel free to ask; I'll help to the best of my ability.