3

I want to reencode a audiobook for my mobile with speexenc. The first step is to reencode the file with mplayer.

for i in *.mp3; do
    mplayer -ao pcm:waveheader "$i" -af pan=1:0.5:0.5,resample=22050 -ao pcm:file="$i.wav";
done

Is what I found on the internet. But the outfile is not a pcm wav:

file *.wav
RIFF (little-endian) data, WAVE audio, mono 22050 Hz

Where a reference wav from xiph.org is pcm.

file wb_male.wav 
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 16000 Hz

speexenc does encode the last PCM WAV, but does not with the mplayer file. Why not? The does the Audiooutput called "pcm" does not ouput a pcm file? How to Fix it? And is there a easy way to pipe the wav directly to speexenc without a named fifo?

Ludwig
  • 31

3 Answers3

4

The MPlayer man page uses this syntax:

mplayer -ao pcm:file=test.wav test.avi

If you want to do things like limiting sampling rate, you can throw on an -srate option (like -srate 44100 for redbook CD audio).

But, if you have it installed, I'd suggest using ffmpeg because it's actually meant for doing these things.

amphetamachine
  • 5,517
  • 2
  • 35
  • 43
2

The wav file generated by mplayer -ao pcm from an mp3 is in PCM format. It just happens to be floating-point PCM because that's what comes naturally out of the mp3 decoder. file should have told you this, but it doesn't know about the floating-point PCM format.

The mp3 decoder produces float and -ao pcm just writes whatever format it receives, so you need something between them to change the format: the af format filter. For signed 16-bit little-endian (which is what you probably want), -af format=s16le will do it.

Alan Curry
  • 2,274
0

When you run mplayer with pcm output it tells you the fastest way to do it:

Info: Faster dumping is achieved with -benchmark -vc null -vo null -ao pcm:fast

so

mplayer in.mp3 -benchmark -vc null -vo null -ao pcm:fast:file=out.wav -af format=s16le

Result:

$ file out.wav
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 48000 Hz

Is that good enough? You can use sox or audacity to convert stereo to mono.