Trim Audio File

Sean McNamara smcnam at gmail.com
Thu Oct 6 11:00:58 PDT 2011


Hi,

On Thu, Oct 6, 2011 at 3:35 AM, Sudarshan Bisht
<bisht.sudarshan at gmail.com> wrote:
> I need to trim down size/duration  of an audio file, for example I have a 5
> MB audio file and I want to create an audio file having only 1 MB of size or
> 60 seconds of duration.

There's a (AFAIK closed source) tool out there called mp3DirectCut
that does this *without* reencoding (so you don't suffer any quality
degradation at all): http://mpesch3.de1.cc/mp3dc.html

Not sure if there's an element out there for gstreamer that does
similar. And I have no idea if this is even theoretically possible
with other audio codecs. But at least for mp3, you should be able to
write a gstreamer element to do it without re-encoding, in the worst
case.

> So to do this I need to first decode original audio file
> completely/partially and then encode the raw samples again until it reaches
> 1MB/60 sec.

Try to avoid this, unless your encoded format is lossless (WAV, FLAC).
Re-encoding using lossy encoders is like making a photocopy of a
previously photocopied document: each time you do it, the quality
degrades slightly.


> Is there any other optimized way ?  For example playing with audio headers.

If you do modify the headers to reflect a different duration, you will
want to also get rid of the  extraneous data, to keep your file
compliant with the file format (just speaking in general here). It's
not a good idea to lie about the duration while keeping the actual
data intact; plus it wastes storage. If you're going to do this, then
do it by cutting the data out, too. Many frame-based codecs should
theoretically have a way for a program to automatically chop some
samples out of it without re-encoding.... the challenge is finding or
writing software to do what you're looking for with the file formats
you'll be using.

HTH,

Sean

>
>
> --
> Regards,
>
> Sudarshan Bisht
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>


More information about the gstreamer-devel mailing list