Before upgrade to the latest Ubuntu I used the following command to extract mp3 from an avi file:

$ for x in *.avi; do ffmpeg -vol 100 -ab 160k -ar 44100 -i "$x" "`basename "$x" .avi`.mp3"; done

This worked. But since Ubuntu 12.04 I get Option sample_rate not found. when I try to execute this command. If I omit -ar 44100 (or -sample_rate 44100) it does extract the mp3, but in most cases the length of the extracted mp3 doesn't fit anymore. That means that they've got a length of 43min or something although the avi has a length of only 5min.

It's the same problem with both ffmpeg and avconv. Any ideas how to solve these problems?

4 Answers 4


Try with this instead:

ffmpeg -i "$x" -vol 100 -ab 160k -ar 44100 "`basename "$x" .avi`.mp3"

Before the options were in front of the input file, but it looks like you want to set them for the output file.

  • Very good, the error message is gone. But I still have the problem, that the length doesn't fit. I guess this is a bug, right?
    – Bevor
    Aug 4, 2012 at 18:06
  • It definitely looks like it. I also tried it with a mov (couldn't find a short avi quickly) and the mp3 was produced perfectly, with a correct duration. Aug 5, 2012 at 16:47
  • Oh and can you put a smaller file online for me to check? Aug 5, 2012 at 21:28
  • Works for me using my ffmpeg line (don+t have avconv), creating an mp3 of the same length. ffmpeg version 0.10.3. Aug 6, 2012 at 18:53
  • Ok thanks, I wonder if the encoding in ytdownloader is maybe wrong. Can you tell me, which version is your libmp3lame?
    – Bevor
    Aug 7, 2012 at 6:42

Have you tried it with other avi files? The audio track of the file might be longer than the video track (just a guess).

Have you tried the -t option?

   -t duration
       Restrict the transcoded/captured video sequence to the duration
       specified in seconds.  "hh:mm:ss[.xxx]" syntax is also supported.

You may want to try setting an audio bit stream filter in ffmpeg. I've never tried it but the "remove_extra" filter sounds promising ;)

   -absf bitstream_filter
       Bitstream filters available are "dump_extra", "remove_extra",
       "noise", "mp3comp", "mp3decomp".

Have you considered using a command like ExifTool to view information about the file and setting your options accordingly (perhaps even parsing the output & automating it in your script)?

Perhaps you could extract the audio file in a lossless format and then transcode the audio file but there has to be a better way than that.

If you get it sorted please do post what you've done because I'm not satisfied with the obvious methods of processing the 1000's of video files I need to demux. I've made a script similar to yours, however I want to get the best possible quality audio files I can without wasting any space. My transcoding options will be dynamic for sure so I need something a little more sophisticated than a one liner.

  • Yes, I tried it with other files, and the -t flag does nothing. Same result with or without -t flag. You can try it by yourself, look my comment in lynxlynxlynx's posting.
    – Bevor
    Aug 6, 2012 at 18:28

ffmpeg -version will inform you what build options were enabled during when ffmpeg was compiled for Ubuntu 12.04. You may be missing a library or maybe an option was not enabled during build time in which you would have to recompile with any disabled options enabled. Default sample rate for ffmpeg is 44100 with a bit rate of 64k.

  • Ok, but this doesn't explain why the most results end up in mp3 files with a wrong running time displayed, does it?
    – Bevor
    Aug 4, 2012 at 9:48

Install the ppa of ffmpeg from ppa:jon-severinsson/ffmpeg and this will fix it.

  • 2
    Do you want to include some information about why this PPA will fix it?
    – jasonwryan
    Nov 1, 2012 at 2:12

You must log in to answer this question.

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