truncate/extract section of audio

The place for "I can't figure out how to..." questions.
Post Reply
kgentes
User
Posts: 8
Joined: Fri Aug 12, 2005 10:14 pm

truncate/extract section of audio

Post by kgentes » Wed Aug 16, 2006 8:07 pm

weirdness has me finding no place to ask this question. Does anyone know of where I can find a module that would allow me to simply say "truncate this mp3 or WAV file" such as "give me just the first 60 seconds of audio" or last 30 seconds or the middle 45 seconds of the audio of this file.?

anything like that..?

seems like getid3 is pefect for lots of data gathering, but does it have a twin that actually does work on the audio portion of the audio file?

of course, I am not asking for a PC application.. we are all programmers here right? no I am looking for a php module or such...

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Fri Aug 18, 2006 12:50 pm

MP3s can be cut into and out of at any point -- since it's designed as streaming data decoders are required to skip any corrupted data and resume playing at the next valid frame. So for an MP3 you could simply guess where the best point to cut is (CBR files are obviously very easy to predict approximately what byte offset matches what time index; VBR files may require the use of the 100-entry TOC in the VBR header to give you an educated guess where any given time index is in byte-offset in the file). To get fancy you could then scan for the nearest frame header, but it's not absolutely neccesary, it should play fine as-is.

You could truncate a WAV at pretty much any point; although it will technically be broken if the header hasn't been modifed to reflect the new data size, it should still play fine. Skipping something at the beginning is different, because you'd need to preserve (or better, rewrite) the header and make sure you're cutting in at the right byte otherwise your channels will be at best rotated, or just outright corrupted. And that's assuming it's plain PCM in the WAV, if it's something more complex (DTS for example) then it's far more complicated.

getID3() doesn't have any such tools built in, although it does come with demo.joinmp3.php

Post Reply