Ripping audio from video files with mplayer

Friday, January 01, 2010 Posted by Psyk
Here's a quick fire way to get that sound clip, soundtrack or whatever it is into an audio format from a video file. For example, on youtube, there might be a good video clip with a great soundtrack, and the video is nothing more than just a fixed image and/or you want to stick on your iPod/iPhone etc. Or you might want to get an audio sample for use in a ring tone etc.

Below is a script that I use to rip audio files out of pretty much any video.
 #!/bin/bash  
 echo "Ripping audio......."   
 mplayer -nocorrect-pts -vo null -vc null -ao pcm:fast:file=audiodump.wav "$1"   
 normalize -v audiodump.wav   
 faac -b 256 -c 48000 --mpeg-vers 4 -o audiodump.aac audiodump.wav  
The first line uses mplayer to dump the audio to a standard wav file called "audiodump.wav". The "-nocorrect-pts" corrects errors in some certain video files.

I then normalize the audio file via the "normalize" command (make sure you have the normalize package installed).

It's then encoded into AAC format using faac. You could easily do an mp3 here by using lame. For example, change the line starting with faac to something like:

lame --preset extreme audiodump.wav audiodump.mp3
Labels:

Post a Comment