Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted
+100

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.

share|improve this answer
    
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 '12 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. –  lynxlynxlynx Aug 5 '12 at 16:47
    
Oh and can you put a smaller file online for me to check? –  lynxlynxlynx Aug 5 '12 at 21:28
    
Ok, look into test.devgems.net. I've uploaded some shit from YT I downloaded with my YT-downloader I uploaded there too (You have to adapt the DEST-path and download youtube-dl to use it). Then I used avconv -i "MarioTest.avi" -vol 100 -ab 160k -ar 44100 "MarioTest.mp3" to extract the audio, but the audio has a length of 6:39. And this is wrong. –  Bevor Aug 6 '12 at 18:19
    
Works for me using my ffmpeg line (don+t have avconv), creating an mp3 of the same length. ffmpeg version 0.10.3. –  lynxlynxlynx Aug 6 '12 at 18:53
show 3 more comments

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.

share|improve this answer
    
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 '12 at 18:28
add comment

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.

share|improve this answer
    
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 '12 at 9:48
add comment

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

share|improve this answer
2  
Do you want to include some information about why this PPA will fix it? –  jasonwryan Nov 1 '12 at 2:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.