113

I need to extract an MP3 audio track from an MP4 video with ffmpeg. I can do this for .flv -> mp3, but I don't know the command line parameters for mp4->mp3. For example, flv -> mp3:

ffmpeg -i video.flv -acodec copy audio.mp3

What parameters should I use for mp4 -> mp3?

migrated from stackoverflow.com Sep 6 '11 at 6:06

This question came from our site for professional and enthusiast programmers.

  • 1
    If you don't really need an MP3, I would not convert the audio: MP4->MP3 is a lossy transformation, you will lose extra source information. – Thom Wiggers Dec 8 '13 at 0:33
  • no more ffmpeg for ubuntu 14.04 – Louis Oct 7 '14 at 18:03
137

The basic command is:

ffmpeg -i filename.mp4 filename.mp3

or

ffmpeg -i video.mp4 -b:a 192K -vn music.mp3

Check this URL: MP4 Video to MP3 File Using ffmpeg (Ubuntu 9.10 Karmic Koala)

Note: Ubuntu does not supply FFmpeg, but the fork named Libav. The syntax is the same – just use avconv instead of ffmpeg for the above examples.

51

The better way to encode MP3 is to use -q:a for variable bit rate.

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

The q option can only be used with libmp3lame and corresponds to the LAME -V option. See:

  • @slhck ...that's a good point, but I've just tested on a video file, and leaving out -vn just copies the audio stream. I suppose ffmpeg must have some way of detecting the difference (I just checked a file with ffprobe, and the video was stream 1 rather than the usual 0, and had some metadata: comment : Cover (front)) – evilsoup Feb 17 '13 at 21:31
  • This one finally played also the Android Music player. Thanks – michalzuber Nov 10 '15 at 7:24
  • 1
    And to convert whole directory (including filenames with spaces) with the above command: for i in *.mp4; do ffmpeg -i "$i" -q:a 0 -map a "$(basename "${i/.mp4}").mp3"; done; – kingSlayer Nov 29 '16 at 19:27