229

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?

4
  • 2
    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. Dec 8, 2013 at 0:33
  • no more ffmpeg for ubuntu 14.04
    – Louis
    Oct 7, 2014 at 18:03
  • 1
    @ThomWiggers is it necessarily lossy? I don't know how mp4s are encoded, but as long as you can separate video and audio, it shouldn't have to be Jun 17, 2019 at 14:47
  • The original version of this question was not clear how the audio was encoded – that got changed in edits. Remuxing does not have to be lossy. Jun 18, 2019 at 15:03

4 Answers 4

299

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) link broken [Updated on 7th Dec 2021]

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.

7
85

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

ffmpeg -i in.mp4 -q:a 0 -map a out.mp3

The q option can only be used with libmp3lame and corresponds to the LAME -V option. See Encoding VBR (Variable Bit Rate) mp3 audio:

https://trac.ffmpeg.org/wiki/Encode/MP3

5
  • @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, 2013 at 21:31
  • This one finally played also the Android Music player. Thanks Nov 10, 2015 at 7:24
  • 3
    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, 2016 at 19:27
  • 1
    How is the resulting .mp3 different from the vanilla command ffmpeg -i vid.mp4 audio.mp3 in @Naga Harish M 's answer? Less lossy? Jun 17, 2019 at 14:48
  • @kingSlayer how do I do that on Mac?
    – Sam
    Aug 21, 2022 at 21:24
18

I got it working from youtube mp4 videos with follwing command:

ffmpeg -i video.mp4 -vn audio.mp3
2
  • 14
    -vn option explicitly drops video so the conversion is much much faster. Sep 24, 2020 at 23:08
  • I use this command to convert the whole folders on Windows. FOR %I in ("*.*") DO ffmpeg -i "%I" -movflags use_metadata_tags -vn "C:\Users\MYUSERNAME\Music\converted\%~nI.mp3" This will be convert mp4 to mp3 while keep metadata even some of them are missing such as comments field but you can recover them in MP3tag software.
    – vee
    Jul 14 at 5:40
0

You can use a graphical tool, such as FFAudioConverter, which can be installed to Linux using Flatpak or Windows.

I tried the above and many other commands, but kept having a problem with VLC reporting incorrect and also constant changing of the length of an audio track. I did not experience this problem with FFAudioConverter.

Using the tool is very simple. Just open the application, then drag and drop a file, selected files, or a directory into the application. Verify the settings are configured for your desired output, then click Convert.

enter image description here

2
  • Can it take bulk? multiple videos?
    – j0h
    Jul 17, 2022 at 14:18
  • 1
    @j0h Yes. From the linked GitHub description: "Convert many files or whole directories very fast".
    – Paul
    Jul 17, 2022 at 14:36

You must log in to answer this question.