Re: [linux-audio-dev] splicing mp3s

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] splicing mp3s
From: Erik Walthinsen (omega_AT_cse.ogi.edu)
Date: Tue Jun 06 2000 - 01:18:50 EEST


On Mon, 5 Jun 2000, Paul Winkler wrote:

> I don't know how long a "frame" is. Some experimentation should tell
> you. Somewhere near 50 frames / second, at least with the file I
> tried. Might depend on bitrate of the mp3 file? If you can figure
> that out, you're all set.

An mp3 frame is 1152 samples long, mono or stereo, regardless of
source/output sampling rate. The compressed size varies depending on
bitrate. If you want to try to splice constant bitrate mp3s together
without decoding, you need to know the bytes/frame. mpg123 will tell you
this if you give it a -v. From there you can use dd to extract what you
want:

dd if=src.mp3 of=dest.mp3 bs=<bpf> skip=<offset> count=<len>

However, this only works if all frames are the same size. A lot of
encoders will vary the frame size every once in a while to attain a
fractional bytes/frame value, as necessary to precisely match a requested
bitrate. Therefore, you'll see patterns of sizes like
418,418,418,418,418,418,418,419,418,418,418,418,418,418,419,etc.

If you want to write a simple program, you search out the mp3 header,
which begins with 12 1's, or 0xfff in hex. Just count out the frames,
seeking for the next matching pattern. A more complex program would
analyze the header to calculate the bpf value, saving time and increasing
accuracy. Code for that can be extracted from mpg123, with some work.

Hope that helps,
               Omega

         Erik Walthinsen <omega_AT_cse.ogi.edu> - Staff Programmer @ OGI
        Quasar project - http://www.cse.ogi.edu/DISC/projects/quasar/
   Video4Linux Two drivers and stuff - http://www.cse.ogi.edu/~omega/v4l2/
        __
       / \ SEUL: Simple End-User Linux - http://www.seul.org/
      | | M E G A Helping Linux become THE choice
      _\ /_ for the home or office user


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Tue Jun 06 2000 - 01:53:02 EEST