6

I've got a video file, video.mp4. It is 18 minutes 23 seconds in duration. I am looking to extract the audio only from this video, and create an MP3 of the highest possible quality from the audio in the video.

Some googlefu lead me to this command: ffmpeg -i video.mp4 audio.mp3

The problem is that, this command doubles the length of the audio that's outputted (duration is 36 minutes 46 seconds). It loops the audio track once, so the output contains the entire 18 minutes 23 seconds of audio, then immediately starts the 18 minutes and 23 seconds of audio over again.

Some more googlefu lead me to this flag: -write_xing 0 from this SO question, but even with that flag it still loops the audio.

EDIT: Additional googlefu and me seeming to think it has something to do with 2 audio channels (and perhaps looping channel 2 immediately after channel 1, rather than merging the two) lead me to this flag: -ac 1 to force it to merge stereo -> mono. This did not work also, and it still outputs a 38 minute 46 seconds MP3 file.

How can I extract (to MP3) the audio from a video file, without doubling the duration?

1
  • 1
    Please show the complete console output from your command.
    – llogan
    Commented Mar 23, 2015 at 20:38

2 Answers 2

7

Try this:

ffmpeg -i video.mp4 -vn -sn -c:a mp3 -ab 192k audio.mp3

I have used this for the same purpose and it didn't change the duration of the audio. Also, (IMHO) trying to increase the quality is just overkill, but you could try with 320k.

5
  • That did it - do you know which of the flags you're using here is what solves my problem? Commented Mar 23, 2015 at 18:59
  • I think it could be related to forcing a constant bit-rate instead of letting ffmpeg pick some vbr by itself. I have seen pretty strange things with some vbr-encoded mp3 files (like a changing total-length during playback)
    – NuTTyX
    Commented Mar 23, 2015 at 19:34
  • 4
    After doing some of my own testing, I can confirm forcing the constant bitrate (-ab 192k) is the flag which is responsible for resolving the problem.
    – James Lai
    Commented Mar 4, 2016 at 17:41
  • 1
    I can confirm that the bitrate flag (-ab {bitrate}) fixed this for me when converting aiff to mp3.
    – tptcat
    Commented May 3, 2017 at 9:00
  • Does anyone have any idea what causes this in the first place, and why setting a high bitrate to solve the problem isn't the default behaviour?
    – xenia
    Commented Jul 7, 2017 at 15:36
2

Google turned up some bug reports in the ffmpeg Trac that show that -write_xing 0 on your ffmpeg command line may fix it as well. It seems the discrepancy in the length stems from incorrect values in the Xing data being written by default.

1
  • Your answer is not providing a solution to OP
    – yass
    Commented May 18, 2017 at 19:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .