Re: I dream of converting this file to a real mp3
"Kelly Jones" <[email protected]> Wed, 29 Oct 2008 17:55:23 -0700
| Newsgroups | gmane.org.user-groups.nmlug |
|---|---|
| Message-ID | <[email protected]> |
On 10/28/08, Wesley J. Landaker <[email protected]> wrote: > On Tuesday 28 October 2008 18:33:12 Kelly Jones wrote: >> Is the sync word always 4 'ff' (decimal 255) in a row? > > I'm sorry, I led you astray; the sync word is actually three *nibbles* of f, > not 4 bytes of ff. (I was apparently thinking of the sync word for a > different format--I know about WAY too many file formats...) The fourth > nibble in the 16-bit sync word is info about the version, layer, and error > correction. So you are actually looking for ff fa (MPEG-1 Layer 3 ECC) or > ff fb (MPEG-1 Layer 3 no ECC). > >> % \od -x jeannie1.wav | fgrep ffff > > Careful: od is showing these as shorts, but is byte swapping them for > display. So faff and fbff are what we actually want in this display format. > Note that because word alignment is not required (AFAIR) this could show up > as ffxx xxfa or ffxx xxfb as well. Try "od -t x1" for an actual view of the > bytes in order. > >> 0000440 9d09 364d ffff e8ff 6a32 3067 ed65 bf4d >> 0000460 ffff faff ca0c 0634 d830 3064 3f03 f8ff > ^^^^ > So this looks like a MP3 frame header sync word. Despite the display order > from od, the actual byte there stream is ff fa. There will be a sync word > for every frame in the file, but of course you only really care about > aligning with the first one. Wesley, you're a genius! The following Perl one-liner does the trick: # perl -0777 -pnle 's/^.*?\xFF(\xFA|\xFB)/\xFF$1/s' jeannie1.wav > jeannie1.mp3 I tried on several similar files and it worked great there too! Generalizing it is a bit weird (double escapes required): \ls *.wav | perl -nle 'print "perl -0777 -pnle \47s/^.*?\\xFF(\\xFA|\\xFB)/\\xF\ F$1/s\47 $_>MP3/$_.mp3"' | sh I now have an MP3 library of TV theme songs. Muhahahaha! -- We're just a Bunch Of Regular Guys, a collective group that's trying to understand and assimilate technology. We feel that resistance to new ideas and technology is unwise and ultimately futile. _______________________________________________ NMLUG mailing list [email protected] http://lists.b9.com/cgi-bin/mailman/listinfo/nmlug