6

I am on ubuntu and want to convert a mp4 video to an mp3 audio file but can't figure out how. I tried installing ffmpeg but it failed to encode the mp3. I've read the gstreamer does it but I can't figure out how. I have gstreamer and python installed. I can program with python, but am not super comfortable compiling software from source or any higher level command line stuff. I only know the basics on the command line.

lovefaithswing
  • 1,510
  • 1
  • 21
  • 37
  • "it failed to encode the mp3". Way too vague. `ffmpeg` can do it. Please tell us what command you tried, and what error you got. – Matthew Flaschen Mar 31 '11 at 21:40
  • Why don't you first learn how to do it manually, with ffmpeg from the command-line, and then either fire a process from python to call ffmpeg, or use it as a library? – salezica Mar 31 '11 at 21:49
  • in order to get ffmpeg to work, I would need to build it from source to work with lame, but I don't have the technical skills required to do that. So I am looking for an alternative method that doesn't require building software from source. – lovefaithswing Apr 01 '11 at 15:22
  • I didn't include the ffmpeg error because I understand the error. – lovefaithswing Apr 01 '11 at 15:22

4 Answers4

3
mplayer <videofile> -dumpaudio -dumpfile out.bin

it will copy the raw audio stream, that should then be easily converted using sox, lame, vlc or whatnot. VLC has nice conversion options as well - and it sports a GUI. I don't know about extracting just the audio, but it should sure be capable of it

sehe
  • 374,641
  • 47
  • 450
  • 633
1

Use TAE https://github.com/tuna74/TunaAudioExtracter. It does everything you want.

0

hmm, for an easy python solution, you could always checkout the python video converter, on https://pypi.python.org/pypi/video-converter a sample code is as follows:

    from converter import Converter
    c = Converter()
    conv = c.convert('g.mp4', 'clip5.mp3', {'format':'mp3','audio':{'codec': 'mp3','bitrate':'22050','channels':1}})
    for timecode in conv:
        pass

where clip5.mp3 is the name of the output file,

Ben Aubin
  • 5,542
  • 2
  • 34
  • 54
programmer44
  • 499
  • 1
  • 5
  • 11
0

Easiest way to do this using GStreamer is to create GStreamer pipeline with decodebin element using gst-launch command-line utility:

gst-launch-1.0 filesrc location=in.mp4 ! decodebin ! audioconvert ! lamemp3enc ! filesink location=out.mp3

In case your mp4 file contains audio track in mp3 format you may want to avoid re-encoding:

gst-launch-1.0 filesrc location=in.mp4 ! qtdemux ! audio/mpeg ! filesink location=out.mp3

If you want to use FFMPEG, you can use following command:

ffmpeg -i in.mp4 out.mp3

You can avoid re-encoding (in case audio track is in mp3) with -acodec copy option:

ffmpeg -i in.mp4 -acodec copy out.mp3
Kyrylo Polezhaiev
  • 1,626
  • 11
  • 18