At least mp3, that is MPEG-1, Audio Layer 3, is divided up into "frames", small chunks of audio of specific length as stated by the bitrate of that frame. You can create an index of these frames and then seek in the audio file to the desired location. Alternatively, you can just guess the location of the chunk and start reading a bit before it and a bit after its estimated size - the MPEG stream contains marker bytes (ff fe I think) that will allow you to resynchronize to the stream. I'm not aware of any time code in the MPEG stream, so I recommend going with the separate index to reduce the webserver traffic. Maybe consider even adding an external API to request a certain time - seeking on the server is likely faster than requesting parts of the file via HTTP Range headers and hoping you found the correct offset.

But for doing sub-second exact cutting (or playback), you will need to implement a way of seeking in the decompressed stream as well, because each frame represents a "large" amound of sound. Maybe your playback libraries can start playback in the middle of a frame (after they read and discard the first part of the frame).


In reply to Re: Cut exact time range from compressed audio by Corion
in thread Cut exact time range from compressed audio by Sixtease

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.