Linux: Extract Audio From Video File (Video To Mp3)

by on February 14, 2011 · 3 comments· LAST UPDATED February 14, 2011

in

How do I extract audio from video file such as .avi/.mpg/.flv in Linux and UNIX and convert it to .mp3 file?

You can use mplayer which is a movie player for Linux and UNIX. It can play most MPEG/VOB, AVI, ASF/WMA/WMV, RM, QT/MOV/MP4, Ogg/OGM, MKV, VIVO, FLI, NuppelVideo, yuv4mpeg, FILM and RoQ files, supported by many native and binary codecs. You can watch VCD, SVCD, DVD, 3ivx, DivX 3/4/5, WMV and even H.264 movies, too. The same tool can be used to covert or extract audio from files. The syntax is as follows:

 
mplayer -dumpaudio -dumpfile output_filename.mp3 input.video_file.name
 

Where,

  1. -dumpaudio : Dumps raw compressed audio stream to ./stream.dump (useful with MPEG/AC-3, in most other cases the resulting file will not be playable). If you give more than one of -dumpaudio, -dumpvideo, -dumpstream on the command line only the last one will work.
  2. -dumpfile filename.mp3 : Specify which file (filename.mp3) MPlayer should dump to. Should be used together with -dumpaudio / -dumpvideo / -dumpstream.

Task: Extract Audio From .AVI File

Type the command as follows to extract audio from clip.avi to clip_track.mp3:
$ mplayer -dumpaudio -dumpfile clip_track.mp3 clip.avi
You can play extracted audio with mplayer command itself:
$ mplayer clip_track.mp3

Task: Extract Audio From VCD or DVD Track

The following command will extract audio from vcd track # 4:
$ mplayer vcd://04 -cdrom-device /dev/sr0 -dumpaudio -dumpfile /tmp/track04.mp3
The following command will extract audio from DVD track # 4:
$ mplayer dvd://04 -cdrom-device /dev/sr0 -dumpaudio -dumpfile /tmp/track04.mp3
You can extract track 5 to 10 using the bash for loop as follows:

 
for i in {05..10}
do
  mplayer vcd://$i -cdrom-device /dev/sr0 -dumpaudio -dumpfile /tmp/track$i.mp3
done
 

Task: Extract Audio From Stream

Use the following syntax:
$ mplayer -dumpstream http://example.com/xyz/3 -dumpfile /tmp/stream_03.mp3

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 patrick295767 June 18, 2013 at 4:50 am

Methods Outdated.

Please update your page!

Sincerely yours

Reply

2 iUser June 20, 2013 at 12:32 am

The current method as of the day 20th June 2013 works fine
I just did few dumps that way and hey every one of them took like one second each
GUI programs would probably do it longer, impressive

Reply

3 akitta June 24, 2013 at 10:19 pm

It didn’t work for me..
Trying to rip .mp3 audio from a Flash video..????
It creates the file there is just nothing in there (well 4.6mb) but 0sec duration.??

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: