LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Convert avi to mp3 (https://www.linuxquestions.org/questions/linux-software-2/convert-avi-to-mp3-289731/)

dexim 02-13-2005 02:30 PM

Convert avi to mp3
 
Anyone know a way to convert avi to mp3? Thank you in advance for any suggestions.

mebrelith 02-13-2005 03:13 PM

Just to clarify, you want to convert AVI (a video format) to MP3 (an audio format)? Maybe you mean extract the audio from an AVI and save it as MP3? I don't have any clues as to how to di this, but your post looks confusing to me. Just wanting to verify.

dexim 02-13-2005 06:59 PM

yes, I wish to extract audio from avi and save as mp3. http://www.google.com/search?hl=en&q...=Google+Search shows some Microsoft applications that do this. I have aprx 50 avi files totaling 5 GB in different directories. I want to run script or program from terminal to extract audio from files into mp3's, then move all of the mp3's into one directory. I can figure out how to write script to move files into new directory, im not sure how to get avi audio into mp3. any help will be greatly appreciated.

ilikejam 02-13-2005 07:57 PM

I wrote a script which does just that. It needs mplayer and LAME:

Code:

#!/bin/bash

if [ -e "$1" ]
    then
    if ! mplayer -vo dummy -ao pcm -aofile any2wav.wav "$1"
        then
        echo "Couldn't decode $1."
        echo "Exiting."
        exit 1
    fi
    OUTFILE="$1.mp3"
    if ! lame --alt-preset standard any2wav.wav "$OUTFILE"
        then
        echo "Couldn't encode $OUTFILE."
        echo "Exiting."
        rm -f any2wav.wav
        exit 1
    fi
    rm -f any2wav.wav
else
    echo "$1 does not exist."
    echo "Exiting."
    exit 1
fi

Dave

zippo85 02-13-2005 11:38 PM

7

dexim 02-15-2005 11:20 PM

Thank you much Dave! very very helpful. :D :D :D

JoseNeville 10-04-2006 11:02 PM

I have a file secret-world.mp4. How I can edit the script to work with it.

ilikejam 10-05-2006 02:37 AM

Hi.

No editing required. The file to be converted is just given as the argument to the script, e.g.
Code:

/path/to/the/saved/script secret-world.mp4
Dave

JoseNeville 10-05-2006 07:25 AM

I received this message.

-aofile is deprecated. Use -ao pcm:file=<filename> instead.
Could not find "any2wav.wav".
Couldn't encode secret-world.avi.mp3.
Exiting.


Thanks

HappyTux 10-05-2006 11:55 AM

Quote:

Originally Posted by JoseNeville
I received this message.

-aofile is deprecated. Use -ao pcm:file=<filename> instead.
Could not find "any2wav.wav".
Couldn't encode secret-world.avi.mp3.
Exiting.


Thanks

Try changing this line.

Code:

if ! mplayer -vo dummy -ao pcm -aofile any2wav.wav "$1"
To

Code:

if ! mplayer -vo dummy -ao pcm:file=any2wav.wav "$1"
Then see if it works.

JoseNeville 10-05-2006 06:49 PM

This is the code

Quote:

#!/bin/bash

if [ -e "$1" ]
then
if ! mplayer -vo dummy -ao pcm:file=any2wav.wav "$1"
then
echo "Couldn't decode $1."
echo "Exiting."
exit 1
fi
OUTFILE="$1.mp3"
if ! lame --alt-preset standard any2wav.wav "$OUTFILE"
then
echo "Couldn't encode $OUTFILE."
echo "Exiting."
rm -f any2wav.wav
exit 1
fi
rm -f any2wav.wav
else
echo "$1 does not exist."
echo "Exiting."
exit 1
fi
this is the error now

Error opening/initializing the selected video_out (-vo) device.


Exiting... (End of file)
Could not find "any2wav.wav".
Couldn't encode secret-world.avi.mp3.
Exiting.

JoseNeville 10-05-2006 06:51 PM

This is the code

Quote:

#!/bin/bash

if [ -e "$1" ]
then
if ! mplayer -vo dummy -ao pcm:file=any2wav.wav "$1"
then
echo "Couldn't decode $1."
echo "Exiting."
exit 1
fi
OUTFILE="$1.mp3"
if ! lame --alt-preset standard any2wav.wav "$OUTFILE"
then
echo "Couldn't encode $OUTFILE."
echo "Exiting."
rm -f any2wav.wav
exit 1
fi
rm -f any2wav.wav
else
echo "$1 does not exist."
echo "Exiting."
exit 1
fi
this is the error now

Error opening/initializing the selected video_out (-vo) device.


Exiting... (End of file)
Could not find "any2wav.wav".
Couldn't encode secret-world.avi.mp3.
Exiting.

HappyTux 10-05-2006 08:39 PM

Quote:

Originally Posted by JoseNeville
This is the code



this is the error now

Error opening/initializing the selected video_out (-vo) device.


Exiting... (End of file)
Could not find "any2wav.wav".
Couldn't encode secret-world.avi.mp3.
Exiting.

Should have tried the command myself use this.

Code:

if ! mplayer -vo null -ao pcm:file=any2wav.wav "$1"
Or if wanting to do it faster.

Code:

if ! mplayer -vc null -vo null -ao pcm:fast:file=any2wav.wav "$1"
Now I just tried the actual command mplayer -vc null -vo null -ao pcm:fast:file=any2wav.wav file.avi not the script and it works fine this way.

Edit: Just tried the script it works with the line with the -vc null -vo null ... in it.

Code:

>$ ./avitomp3 dave\ chapelle\ -killing\ them\ softly.avi
MPlayer dev-SVN-rUNKNOWN-4.1.2 (C) 2000-2006 MPlayer Team
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ (Family: 15, Model: 35, Stepping: 2)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 3DNow 3DNowEx SSE SSE2
Opening joystick device /dev/input/js0
Can't open joystick device /dev/input/js0: Permission denied
Can't init input joystick
Setting up LIRC support...
mplayer: could not connect to socket
mplayer: Connection refused
Failed to open LIRC support.
You will not be able to use your remote control.

Playing dave chapelle -killing them softly.avi.
AVI file format detected.
VIDEO:  [MP43]  320x240  24bpp  14.993 fps  672.9 kbps (82.1 kbyte/s)
==========================================================================
Forced video codec: null
Opening video decoder: [null] Null video decoder
VDec: vo config request - 320 x 240 (preferred colorspace: BGR 24-bit)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
VO: [null] 320x240 => 320x240 Planar YV12
Selected video codec: [null] vfm: null (NULL codec (no decoding!))
==========================================================================
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 22050 Hz, 1 ch, u8, 176.4 kbit/100.00% (ratio: 22050->22050)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
[AO PCM] File: any2wav.wav (WAVE)
PCM: Samplerate: 22050Hz Channels: Mono Format u8
[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast
[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).
AO: [pcm] 22050Hz 1ch u8 (1 bytes per sample)
Starting playback...
A:  8.9 V:  3.3 A-V:  5.648 ct:  0.000  50/ 50  0%  0%  0.6% 50 0

          ************************************************
          **** Your system is too SLOW to play this!  ****
          ************************************************

Possible reasons, problems, workarounds:
- Most common: broken/buggy _audio_ driver
  - Try -ao sdl or use the OSS emulation of ALSA.
  - Experiment with different values for -autosync, 30 is a good start.
- Slow video output
  - Try a different -vo driver (-vo help for a list) or try -framedrop!
- Slow CPU
  - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,
    e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.
- Broken file
  - Try various combinations of -nobps -ni -forceidx -mc 0.
- Slow media (NFS/SMB mounts, DVD, VCD etc)
  - Try -cache 8192.
- Are you using -cache to play a non-interleaved AVI file?
  - Try -nocache.
Read DOCS/HTML/en/video.html for tuning/speedup tips.
If none of this helps you, read DOCS/HTML/en/bugreports.html.

A:3413.2 V:3413.2 A-V:  0.067 ct:  0.140 51175/51175  0%  0%  0.3% 47139 0

Exiting... (End of file)
LAME 3.97 64bits (http://www.mp3dev.org/)
Using polyphase lowpass filter, transition band: 10758 Hz - 11025 Hz
Encoding any2wav.wav to dave chapelle -killing them softly.avi.mp3
Encoding as 22.05 kHz VBR(q=2) single-ch MPEG-2 Layer III (ca. 7.3x) qval=3
    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA
130666/130666(100%)|    1:48/    1:48|    1:50/    1:50|  31.367x|    0:00
  8 [    2] *
 16 [    0]
 24 [    0]
 32 [    1] *
 40 [  338] *
 48 [ 19225] *****************
 56 [ 79033] *********************************************************************
 64 [ 27069] ************************
 80 [  4015] ****
 96 [  839] *
112 [  120] *
128 [    14] *
144 [    10] *
160 [    0]
----------------------------------------------------------------------------------
  kbps      mono %    long switch short %
  57.5      100.0        96.4  2.1  1.5
Writing LAME Tag...done
ReplayGain: -5.1dB

>$  ll *.mp3
-rw-r--r-- 1 stephen stephen 24M 2006-10-05 22:50 dave chapelle -killing them softly.avi.mp3


ilikejam 10-06-2006 03:30 AM

Hi all.

This is what I'm using at the moment (with the new-ish mplayer syntax)
Code:

#!/bin/bash

if [ -e "$1" ]
    then
    if ! mplayer -vo null -vc null -af lavcresample=44100,channels=2,format=s16le -ao pcm:file="$1".wav "$1"
        then
        echo "Couldn't decode $1."
        echo "Exiting."
        exit 1
    fi
    OUTFILE="$1.mp3"
    if ! lame --alt-preset standard "$1".wav "$OUTFILE"
        then
        echo "Couldn't encode $OUTFILE."
        echo "Exiting."
        rm -f "$1".wav
        exit 1
    fi
    rm -f "$1".wav
else
    echo "$1 does not exist."
    echo "Exiting."
    exit 1
fi

It makes sure everything's resampled to 2 channel 44.1kHz 16 bit little endian (CD format), using the high quality resampler before mp3ing.

Dave


All times are GMT -5. The time now is 02:59 PM.