View Full Version : Sox 14.3.1: How to trim specified amount of time off the end of a wav file?
Jonathan[_5_]
June 16th 11, 04:45 PM
Hi,
Sorry for this basic question, but is there a simple way to use the
trim function in Sox to remove a specified amount of time off the
*end* of a WAV file?
Let's say 2 seconds, for example.
Is it necessary to know exactly how far into the file you want to
start trimming, or is there a way to just plug in 2 seconds as a
parameter?
I have read the documentation, but I found it a bit confusing.
Thanks!
Jonathan
Scott Dorsey
June 16th 11, 04:57 PM
In article >,
Jonathan > wrote:
>Hi,
>
>Sorry for this basic question, but is there a simple way to use the
>trim function in Sox to remove a specified amount of time off the
>*end* of a WAV file?
>Let's say 2 seconds, for example.
>
>Is it necessary to know exactly how far into the file you want to
>start trimming, or is there a way to just plug in 2 seconds as a
>parameter?
>I have read the documentation, but I found it a bit confusing.
sox infile outfile trim 0 0:0:2
--scott
--
"C'est un Nagra. C'est suisse, et tres, tres precis."
Jonathan[_5_]
June 16th 11, 04:58 PM
On Jun 16, 11:45*am, Jonathan > wrote:
> Hi,
>
> Sorry for this basic question, but is there a simple way to use the
> trim function in Sox to remove a specified amount of time off the
> *end* of a WAV file?
> Let's say 2 seconds, for example.
>
> Is it necessary to know exactly how far into the file you want to
> start trimming, or is there a way to just plug in 2 seconds as a
> parameter?
> I have read the documentation, but I found it a bit confusing.
>
> Thanks!
> Jonathan
To clarify...
I realize you can accomplish this if you use zero as the first
parameter, and then specify a start time to start trimming...
Just wondering if there's a way to supply only the amount of trim
time, which would be a little easier for me.
Jonathan[_5_]
June 17th 11, 08:44 PM
On Jun 16, 11:57*am, (Scott Dorsey) wrote:
> In article >,
>
> Jonathan > wrote:
> >Hi,
>
> >Sorry for this basic question, but is there a simple way to use the
> >trim function in Sox to remove a specified amount of time off the
> >*end* of a WAV file?
> >Let's say 2 seconds, for example.
>
> >Is it necessary to know exactly how far into the file you want to
> >start trimming, or is there a way to just plug in 2 seconds as a
> >parameter?
> >I have read the documentation, but I found it a bit confusing.
>
> sox infile outfile trim 0 0:0:2
> --scott
>
> --
> "C'est un Nagra. C'est suisse, et tres, tres precis."
Thanks!
Nil
June 21st 11, 11:36 PM
On 16 Jun 2011, (Scott Dorsey) wrote in
rec.audio.pro:
> In article
> >
> , Jonathan > wrote:
>>Sorry for this basic question, but is there a simple way to use
>>the trim function in Sox to remove a specified amount of time off
>>the *end* of a WAV file?
>>Let's say 2 seconds, for example.
>>
>>Is it necessary to know exactly how far into the file you want to
>>start trimming, or is there a way to just plug in 2 seconds as a
>>parameter?
>>I have read the documentation, but I found it a bit confusing.
>
> sox infile outfile trim 0 0:0:2
This doesn't appear to do what the OP wanted. Your command will trim
from the start of the file to 2 seconds in. I think what the OP wants
is to trim, say, 2 seconds off the tail.
As far as I can tell, you need to tell sox where to start the trim, so
in this case you'd have to specify the time length of the tile minus 2
seconds. Like, for a 3 minute song:
sox infile outfile 0 0:02:58
Anahata
June 22nd 11, 09:16 AM
On Tue, 21 Jun 2011 18:36:25 -0400, Nil wrote:
> On 16 Jun 2011, (Scott Dorsey) wrote in rec.audio.pro:
>> sox infile outfile trim 0 0:0:2
>
> This doesn't appear to do what the OP wanted. Your command will trim
> from the start of the file to 2 seconds in. I think what the OP wants is
> to trim, say, 2 seconds off the tail.
man soxeffect
"trim start [length]
Trim can trim off unwanted audio from the beginning and end of
the audio. Audio is not sent to the output stream until the
start location is reached.
The optional length parameter tells the number of samples to
output after the start sample and is used to trim off the back
side of the audio. ***Using a value of 0 for the start parameter
will allow trimming off the back side only.***"
I have to RTFM *every* time I use sox. It's very powerful, but impossible
to remember all the commands and variations thereof, and there's nearly
always some trial and error before I get it to do what I want.
--
Anahata
--/-- http://www.treewind.co.uk
+44 (0)1638 720444
alex
June 22nd 11, 11:40 AM
Il 16/06/2011 17.58, Jonathan ha scritto:
> To clarify...
> I realize you can accomplish this if you use zero as the first
> parameter, and then specify a start time to start trimming...
> Just wondering if there's a way to supply only the amount of trim
> time, which would be a little easier for me.
maybe you can use the "reverse" command twice...
alex
June 22nd 11, 01:46 PM
Il 22/06/2011 12.40, alex ha scritto:
> Il 16/06/2011 17.58, Jonathan ha scritto:
>> To clarify...
>> I realize you can accomplish this if you use zero as the first
>> parameter, and then specify a start time to start trimming...
>> Just wondering if there's a way to supply only the amount of trim
>> time, which would be a little easier for me.
>
> maybe you can use the "reverse" command twice...
like this:
sox infile.wav outfile.wav reverse trim 30 reverse
this will trim out the last 30 seconds of audio. A bit slow since the
program need to reverse the file twice but works lossly.
Anahata
June 22nd 11, 01:48 PM
On Thu, 16 Jun 2011 08:58:59 -0700, Jonathan wrote:
>
> To clarify...
> I realize you can accomplish this if you use zero as the first
> parameter, and then specify a start time to start trimming... Just
> wondering if there's a way to supply only the amount of trim time, which
> would be a little easier for me.
My understanding is that Scott's answer does this.
Looking back though, I have to agree the manual isn't too clear...
--
Anahata
--/-- http://www.treewind.co.uk
+44 (0)1638 720444
alex
June 22nd 11, 02:26 PM
Il 22/06/2011 14.46, alex ha scritto:
> like this:
>
> sox infile.wav outfile.wav reverse trim 30 reverse
>
> this will trim out the last 30 seconds of audio. A bit slow since the
> program need to reverse the file twice but works lossly.
hehe, sorry... LOSSLESSLY...
Nil
June 22nd 11, 05:31 PM
On 22 Jun 2011, anahata > wrote in
rec.audio.pro:
> man soxeffect
>
> "trim start [length]
> Trim can trim off unwanted audio from the beginning and end of
> the audio. Audio is not sent to the output stream until the
> start location is reached.
>
> The optional length parameter tells the number of samples to
> output after the start sample and is used to trim off the back
> side of the audio. ***Using a value of 0 for the start
> parameter will allow trimming off the back side only.***"
>
> I have to RTFM *every* time I use sox. It's very powerful, but
> impossible to remember all the commands and variations thereof,
> and there's nearly always some trial and error before I get it to
> do what I want.
Yes, that's what the manual says, but it's language is a little
misleading. What it does is remove everything BUT the tail. At least
that's what's happening for me, with version 14.3.0 for Windows. The
command
sox test.wav test1.wav trim 0 5
....leaves me with only the last 5 seconds of the file, rather than
removing the last 5 seconds.
Nil
June 22nd 11, 05:39 PM
On 22 Jun 2011, alex > wrote in rec.audio.pro:
> like this:
>
> sox infile.wav outfile.wav reverse trim 30 reverse
>
> this will trim out the last 30 seconds of audio. A bit slow since
> the program need to reverse the file twice but works lossly.
You're right - I find that very recommendation in the manual:
"Unfortunately, you must know the length of the silence at the end of
your audio file to trim off silence reliably. A work around is to
use the silence effect in combination with the reverse effect. By
first reversing the audio, you can use the above-periods to reliably
trim all audio from what looks like the front of the file. Then
reverse the file again to get back to normal."
I just tried it and it seems to work perfectly.
Jonathan[_5_]
June 22nd 11, 07:55 PM
On Jun 22, 12:31*pm, Nil > wrote:
> On 22 Jun 2011, anahata > wrote in
> rec.audio.pro:
>
>
>
>
>
>
>
>
>
> > man soxeffect
>
> > "trim start [length]
> > *Trim *can *trim off unwanted audio from the beginning and end of
> > *the audio. *Audio is not sent to the *output *stream *until *the
> > *start location is reached.
>
> > *The *optional *length *parameter *tells the number of samples to
> > *output after the start sample and is used to trim off *the *back
> > *side *of *the audio. ****Using a value of 0 for the start
> > *parameter will allow trimming off the back side only.***"
>
> > I have to RTFM *every* time I use sox. It's very powerful, but
> > impossible to remember all the commands and variations thereof,
> > and there's nearly always some trial and error before I get it to
> > do what I want.
>
> Yes, that's what the manual says, but it's language is a little
> misleading. What it does is remove everything BUT the tail. At least
> that's what's happening for me, with version 14.3.0 for Windows. The
> command
>
> sox test.wav test1.wav trim 0 5
>
> ...leaves me with only the last 5 seconds of the file, rather than
> removing the last 5 seconds.
Yeah...I discovered that :)
alex
June 22nd 11, 09:33 PM
Il 22/06/2011 18.39, Nil ha scritto:
> On 22 Jun 2011, > wrote in rec.audio.pro:
>
>> like this:
>>
>> sox infile.wav outfile.wav reverse trim 30 reverse
>>
>> this will trim out the last 30 seconds of audio. A bit slow since
>> the program need to reverse the file twice but works lossly.
>
> You're right - I find that very recommendation in the manual:
>
> "Unfortunately, you must know the length of the silence at the end of
> your audio file to trim off silence reliably. A work around is to
> use the silence effect in combination with the reverse effect. By
> first reversing the audio, you can use the above-periods to reliably
> trim all audio from what looks like the front of the file. Then
> reverse the file again to get back to normal."
>
> I just tried it and it seems to work perfectly.
really? i don't readed the manual, i just searched for a "reverse"
command...
i don't expected this situation to be explained in the man.
In scripting terms the most reliable workaround will be allowing some
"algebra" in the parameters like this: "trim (end-30)"...
regards
alex
Nil
June 22nd 11, 11:57 PM
On 22 Jun 2011, alex > wrote in rec.audio.pro:
>> "Unfortunately, you must know the length of the silence at the
>> end of your audio file to trim off silence reliably. A work
>> around is to use the silence effect in combination with the
>> reverse effect. By first reversing the audio, you can use the
>> above-periods to reliably trim all audio from what looks like the
>> front of the file. Then reverse the file again to get back to
>> normal."
>>
>> I just tried it and it seems to work perfectly.
>
> really? i don't readed the manual, i just searched for a "reverse"
> command...
> i don't expected this situation to be explained in the man.
> In scripting terms the most reliable workaround will be allowing
> some "algebra" in the parameters like this: "trim (end-30)"...
Yes, it's in there, although the description is for a slightly
different scenario. It describes using the "silence" command, which
supposedly will delete all silence at the end of the track (which may
be what the OP wants, anyway.) "Reverse" works with the "trim" command,
too - I tried it. The command line:
sox test.wav test1.wav reverse trim 10 reverse
....removes exactly the last 10 seconds of the file. I was worried that
the "reverse" command might do something negative to the file, but I
tested it by comparing a double-reversed version with the original, and
they are byte-for-byte identical.
alex
June 23rd 11, 12:03 AM
Il 23/06/2011 0.57, Nil ha scritto:
> ...removes exactly the last 10 seconds of the file. I was worried that
> the "reverse" command might do something negative to the file, but I
> tested it by comparing a double-reversed version with the original, and
> they are byte-for-byte identical.
yes because sox, after the initial decoding (if the file is encoded),
will save temp pcm files and does not re-encode it on every passage.
This make the "double reverse" method completely lossless against the
single processing step of the trim command. Sadly, expecially on large
files, this will lead to a slower processing task because the temp files
will be written 3 times instead of 1.
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.