Re: I dream of converting this file to a real mp3

"Wesley J. Landaker" <[email protected]> Tue, 28 Oct 2008 16:53:17 -0600
Newsgroups gmane.org.user-groups.nmlug
Organization icecavern.net
Message-ID <[email protected]>
On Saturday 25 October 2008 22:04:48 Kelly Jones wrote:
> I have an odd file:
> > file jeannie1.wav
>
> jeannie1.wav: RIFF (little-endian) data, WAVE audio, MPEG Layer 3,
> mono 11025 Hz
[...]
> What's the correct way to convert jeannie1.wav to MP3 with a single
> lame command, short of folding my arms and blinking?

The problem that you are having -- and most answers seem to be missing the 
point of -- is that your file already is essentially an MP3, but 
it's "disguised" as a WAV file and isn't in the usual MP3 format file.

What we call ".wav" files are actually general RIFF containers that happen 
to only have WAVE audio chunks. Usually when you get your hands on a ".wav" 
file, it has PCM audio data, but that's not required. WAVE audio actually 
supports all sorts of codecs like GSM, or in your case, MPEG-1 Audio Layer 
3 (i.e. MP3). 

What we call ".mp3" files are either raw MP3 frames or MP3 frames 
encapsulated in the ID3 container format.

So if you are using lame anywhere in the chain, that's not very optimal: it 
means you have decoded and are now re-encoding the data and will suffering 
a corresponding quality loss. What you really want is change container 
formats while keeping the data static.

It's actually pretty easy to convert in this situation. Here are a couple 
ways:

  1) Rename ".wav" to ".mp3" -- since MP3 self-synchronizes upon playback, 
the RIFF header will just look like garbage and will be skipped until the 
actual MP3 data is found and played. The garbage is there, so this 
is "wrong", but in practice this will probably work with any player.

  Example:
    cp jeannie1.wav jeannie1.mp3

  2) Rename, then strip the RIFF header off with a hex editor. This is 
actually pretty trivial if you know what you are doing, and will avoid 
garbage at the front of the MP3 file. This is good if it's giving you 
trouble, or you just want to do it "right".

  Example:
    cp jeannie1.wav jeannie1.mp3
    khexedit jeannie1.mp3
    (strip RIFF header by e.g. looking for first MP3 sync word ff ff ff ff)
    
  3) If your sox is compiled with MP3 support, it can convert container 
formats without touching the data. Unfortunately, sox does not support MP3 
by default in most distributions.

  Example:
    sox jeannie1.wav jeannie1.mp3

  4) Write (or find) a simple program that will simply strip the RIFF header 
like #2. This would probably be about 5-10 lines of python, for example.

-- 
Wesley J. Landaker <[email protected]> <xmpp:[email protected]>
OpenPGP FP: 4135 2A3B 4726 ACC5 9094  0097 F0A9 8A4C 4CD6 E3D2

_______________________________________________
NMLUG mailing list
[email protected]
http://lists.b9.com/cgi-bin/mailman/listinfo/nmlug
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkkHl94ACgkQ8KmKTEzW49JC5gCfTbY7XiaVbDS6jxMz4JWTj8hS
B58An0tNNZUzz42IrNdAhIgVKEWoyCwP
=bKk7
-----END PGP SIGNATURE-----