Trim

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (one more touch-up)
(more clear maybe)
Line 1: Line 1:
 
== Trim ==
 
== Trim ==
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
{{Template:Func4Def
+
''Trims'' a clip &ndash; removes frames from one or both ends.
|Trim(clip, int ''first_frame'', int ''last_frame'' [, bool ''"pad"''])
+
 
|Trim(clip, int ''first_frame'', int -''num_frames'' [, bool ''"pad"''])
+
The audio is similarly trimmed so that it stays synchronized (see [[#Pad_argument|Pad argument]] below).
|Trim(clip, int ''first_frame'', [int ''"end"'' , bool ''"pad"''])
+
|Trim(clip, int ''first_frame'', [int ''"length"'' , bool ''"pad"''])
+
For convenience, '''Trim''' can be called in four slightly different ways:
 +
 
 +
 
 +
{{FuncDef
 +
|Trim(clip, int ''first_frame'', int ''last_frame'' [, bool ''pad''] )
 
}}
 
}}
 +
:Returns a clip starting at {{FuncArg|first_frame}} and running up to and including {{FuncArg|last_frame}}.
 +
:* For example, <tt>Trim(3, 5)</tt> returns source clip frames '''3''', '''4''' and '''5'''.
 +
:*Remember, AviSynth starts counting at frame 0.
 +
:*If you set {{FuncArg|last_frame}} to 0, you will get a clip starting at {{FuncArg|first_frame}} and running to the end of the clip.
  
'''Trim''' trims a clip so that it includes only the frames {{FuncArg|first_frame}} up to and including {{FuncArg|last_frame}}. The audio is similarly trimmed so that it stays synchronized (see {{FuncDef|pad}} below). Remember AviSynth starts counting at frame 0.
 
  
If you set a negative value for the second argument, that is '''-'''{{FuncArg|num_frames}}, you will get a clip starting at {{FuncArg|first_frame}} and running for {{FuncArg|num_frames}} frames. If you set {{FuncArg|last_frame}} to zero, you will get a clip starting at {{FuncArg|first_frame}} and running to the end of the clip.
+
{{FuncDef
 +
|Trim(clip, int ''first_frame'', int -''num_frames'' [, bool ''pad''] )
 +
}}
 +
:With a negative value for the second argument, you get a clip starting at {{FuncArg|first_frame}} and running for {{FuncArg|num_frames}} frames.
 +
:* For example, <tt>Trim(0, -4)</tt> returns source clip frames '''0''', '''1''', '''2''' and '''3'''.
  
{{Par2|end|int|0}}
 
{{Par2|length|int|0}}
 
:In Avisynth v2.60, you may use the alternate syntax with named arguments; for example,
 
:* <tt>Trim(3, 7)&nbsp;</tt> &rarr; <tt>&nbsp;Trim(3, end=7)</tt>
 
:* <tt>Trim(3, -5)</tt> &rarr; <tt>&nbsp;Trim(3, length=5)</tt>
 
:Unlike the first_frame syntax, the alternate syntax has no discontinuous boundary values: {{FuncArg|end}}=0 means end at frame 0; {{FuncArg|length}}=0 means return a zero length clip. These are most useful in avoiding unexpected boundary conditions in your user functions.
 
  
{{Par2|pad|bool|true}}
+
{{FuncDef
:Causes the audio stream to be padded to align with the video stream. Otherwise the tail of a short audio stream is left so. You should use {{FuncArg|pad}}=false when the soundtracks being joined were originally contiguous (see [[Splice]])
+
|Trim(clip, int ''first_frame'', [int ''end'' , bool ''pad''] )
 +
}}
 +
:Returns a clip starting at {{FuncArg|first_frame}} and running up to and including frame {{FuncArg|end}}. From Avisynth v2.60.
 +
:* For example, <tt>Trim(3, {{FuncArg|end}}=7)</tt> ''is equivalent to'' <tt>Trim(3, 7)</tt>; both return frames '''3''', '''4''', '''5''', '''6''' and '''7'''.
 +
:*{{FuncArg|end}} default = 0; must be >= {{FuncArg|first_frame}}.
 +
:*Unlike the {{FuncArg|last_frame}} syntax, the {{FuncArg|end}} syntax has no discontinuous boundary values: {{FuncArg|end}}=0 means end at frame 0. This feature is useful in avoiding unexpected boundary conditions in your user functions.
 +
 
 +
 
 +
{{FuncDef
 +
|Trim(clip, int ''first_frame'', [int ''length'' , bool ''pad''] )
 +
}}
 +
:Returns a clip starting at {{FuncArg|first_frame}} and running for {{FuncArg|length}} frames. From Avisynth v2.60.
 +
:*For example, <tt>Trim(3, {{FuncArg|length}}=5)</tt> ''is equivalent to'' <tt>Trim(3, -5)</tt>; both return frames '''3''', '''4''', '''5''', '''6''' and '''7'''.
 +
:*{{FuncArg|length}} default = 0; must be >= 0.
 +
:*Unlike the {{FuncArg|num_frames}} syntax, the {{FuncArg|length}} syntax has no discontinuous boundary values: {{FuncArg|length}}=0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.
 +
 
 +
====Pad argument====
 +
True by default, {{FuncArg|pad}} causes the audio stream to be padded to align with the video stream. Otherwise the tail of a short audio stream is left so. You should use {{FuncArg|pad}}=false when the soundtracks being joined were originally contiguous (see [[AlignedSplice]], [[UnalignedSplice]] )
  
;Audio-only clips
+
====Trim and Audio-only clips====
 
'''Trim''' cannot trim a clip if there is no video. Use '''AudioTrim''' for that. To use '''Trim''' you must take an existing video source, use [[AudioDub]] to add your audio and '''Trim''' ''that''. Otherwise, AviSynth returns the error message "Trim: Cannot trim if there is no video."
 
'''Trim''' cannot trim a clip if there is no video. Use '''AudioTrim''' for that. To use '''Trim''' you must take an existing video source, use [[AudioDub]] to add your audio and '''Trim''' ''that''. Otherwise, AviSynth returns the error message "Trim: Cannot trim if there is no video."
 
</div>
 
</div>
Line 29: Line 51:
 
== AudioTrim ==
 
== AudioTrim ==
 
<div style="max-width:62em" >
 
<div style="max-width:62em" >
{{Template:Func4Def
+
'''AudioTrim''' (from Avisynth v2.60) trims a clip based on ''time'', not on ''frames''. All time arguments are in seconds. This is most useful for audio-only clips, where "frames" have no meaning anyway, and you may want to edit with finer precision than whole frames (at 30fps, 1 frame=33.3ms).
 +
 
 +
Naturally, {{BoldColor|#4F81BD|100|trims on clips with video are rounded to the nearest whole video frame}}.
 +
 
 +
For convenience, '''AudioTrim''' can be called in four slightly different ways:
 +
 
 +
 
 +
{{FuncDef
 
|AudioTrim(clip, float ''start_time'', float ''end_time'')
 
|AudioTrim(clip, float ''start_time'', float ''end_time'')
 +
}}
 +
:Returns a clip starting at {{FuncArg|start_time}} and running up to and including time {{FuncArg|end_time}}. 
 +
:* For example, <tt>AudioTrim(3.0, 5.0)</tt> returns source clip from [[ShowTime|time]] '''00:00:03.000''' to '''00:00:05.000'''.
 +
:* If you set {{FuncArg|end_time}} to 0.0, you will get a clip starting at {{FuncArg|start_time}} seconds and running to the end of the clip.
 +
 +
 +
{{FuncDef
 
|AudioTrim(clip, float ''start_time'', float -''duration'')
 
|AudioTrim(clip, float ''start_time'', float -''duration'')
|AudioTrim(clip, float ''start_time'' [, float ''"end"''])
 
|AudioTrim(clip, float ''start_time'' [, float ''"length"''])
 
 
}}
 
}}
 +
:With a negative value for the second argument, you will get a clip starting at {{FuncArg|start_time}} and running for {{FuncArg|duration}} seconds.
 +
:* For example, <tt>AudioTrim(0.0, -4.0)</tt> returns the source clip from [[ShowTime|time]] '''00:00:00.000''' to '''00:00:04.000'''.
  
'''AudioTrim''' (in Avisynth v2.60) trims a clip based on ''time'', not on ''frames''. This is most useful for audio-only clips, where "frames" have no meaning anyway, and you may want to edit with finer precision than whole frames (at 30fps, 1 frame=33.3ms). The returned clip includes only the audio (or video+audio) from time {{FuncArg|start_time}} up to and including time {{FuncArg|end_time}}. All time arguments are in seconds.
 
  
If you set a negative value for the second argument, that is '''-'''{{FuncArg|duration}}, you will get a clip starting at {{FuncArg|start_time}} seconds and running for {{FuncArg|duration}} seconds. If you set {{FuncArg|end_time}} to zero, you will get a clip starting at {{FuncArg|start_time}} seconds and running to the end of the clip.
+
{{FuncDef
 +
|AudioTrim(clip, float ''start_time'' [, float ''end''] )
 +
}}
 +
:Returns a clip starting at {{FuncArg|start_time}} and running up to and including time {{FuncArg|end}}.  
 +
:*For example, <tt>AudioTrim(3.0, {{FuncArg|end}}=7.0)</tt> is equivalent to <tt>AudioTrim(3.0, 7.0)</tt>
 +
:*{{FuncArg|end}} default = 0.0; must be >= {{FuncArg|start_time}}.
 +
:*Unlike the {{FuncArg|end_time}} syntax, the {{FuncArg|end}} syntax has no discontinuous boundary values: {{FuncArg|end}}=0.0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.
  
{{Par2|end|float|0.0}}
+
 
{{Par2|length|float|0.0}}
+
{{FuncDef
:You may prefer the alternate syntax with named arguments; for example,
+
|AudioTrim(clip, float ''start_time'' [, float ''length''] )
:* <tt>AudioTrim(3.0, 7.0)&nbsp;</tt> &rarr; <tt>&nbsp;AudioTrim(3.0, end=7.0)</tt>
+
}}
:* <tt>AudioTrim(3.0, -4.0)</tt> &rarr; <tt>&nbsp;AudioTrim(3.0, length=4.0)</tt>
+
:Returns a clip starting at {{FuncArg|start_time}} and running for {{FuncArg|length}} seconds.
</div>
+
:*For example, <tt>AudioTrim(3.0, {{FuncArg|length}}=4.0)</tt> is equivalent to <tt>AudioTrim(3.0, -4.0)</tt>
 +
:*{{FuncArg|length}} default = 0.0; must be >= 0.
 +
:*Unlike the {{FuncArg|duration}} syntax, the {{FuncArg|length}} syntax has no discontinuous boundary values: {{FuncArg|length}}=0.0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.</div>
  
  

Revision as of 06:15, 9 March 2016

Contents

Trim

Trims a clip – removes frames from one or both ends.

The audio is similarly trimmed so that it stays synchronized (see Pad argument below).

For convenience, Trim can be called in four slightly different ways:


Trim(clip, int first_frame, int last_frame [, bool pad] )

Returns a clip starting at first_frame and running up to and including last_frame.
  • For example, Trim(3, 5) returns source clip frames 3, 4 and 5.
  • Remember, AviSynth starts counting at frame 0.
  • If you set last_frame to 0, you will get a clip starting at first_frame and running to the end of the clip.


Trim(clip, int first_frame, int -num_frames [, bool pad] )

With a negative value for the second argument, you get a clip starting at first_frame and running for num_frames frames.
  • For example, Trim(0, -4) returns source clip frames 0, 1, 2 and 3.


Trim(clip, int first_frame, [int end , bool pad] )

Returns a clip starting at first_frame and running up to and including frame end. From Avisynth v2.60.
  • For example, Trim(3, end=7) is equivalent to Trim(3, 7); both return frames 3, 4, 5, 6 and 7.
  • end default = 0; must be >= first_frame.
  • Unlike the last_frame syntax, the end syntax has no discontinuous boundary values: end=0 means end at frame 0. This feature is useful in avoiding unexpected boundary conditions in your user functions.


Trim(clip, int first_frame, [int length , bool pad] )

Returns a clip starting at first_frame and running for length frames. From Avisynth v2.60.
  • For example, Trim(3, length=5) is equivalent to Trim(3, -5); both return frames 3, 4, 5, 6 and 7.
  • length default = 0; must be >= 0.
  • Unlike the num_frames syntax, the length syntax has no discontinuous boundary values: length=0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.

Pad argument

True by default, pad causes the audio stream to be padded to align with the video stream. Otherwise the tail of a short audio stream is left so. You should use pad=false when the soundtracks being joined were originally contiguous (see AlignedSplice, UnalignedSplice )

Trim and Audio-only clips

Trim cannot trim a clip if there is no video. Use AudioTrim for that. To use Trim you must take an existing video source, use AudioDub to add your audio and Trim that. Otherwise, AviSynth returns the error message "Trim: Cannot trim if there is no video."


AudioTrim

AudioTrim (from Avisynth v2.60) trims a clip based on time, not on frames. All time arguments are in seconds. This is most useful for audio-only clips, where "frames" have no meaning anyway, and you may want to edit with finer precision than whole frames (at 30fps, 1 frame=33.3ms).

Naturally, trims on clips with video are rounded to the nearest whole video frame.

For convenience, AudioTrim can be called in four slightly different ways:


AudioTrim(clip, float start_time, float end_time)

Returns a clip starting at start_time and running up to and including time end_time.
  • For example, AudioTrim(3.0, 5.0) returns source clip from time 00:00:03.000 to 00:00:05.000.
  • If you set end_time to 0.0, you will get a clip starting at start_time seconds and running to the end of the clip.


AudioTrim(clip, float start_time, float -duration)

With a negative value for the second argument, you will get a clip starting at start_time and running for duration seconds.
  • For example, AudioTrim(0.0, -4.0) returns the source clip from time 00:00:00.000 to 00:00:04.000.


AudioTrim(clip, float start_time [, float end] )

Returns a clip starting at start_time and running up to and including time end.
  • For example, AudioTrim(3.0, end=7.0) is equivalent to AudioTrim(3.0, 7.0)
  • end default = 0.0; must be >= start_time.
  • Unlike the end_time syntax, the end syntax has no discontinuous boundary values: end=0.0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.


AudioTrim(clip, float start_time [, float length] )

Returns a clip starting at start_time and running for length seconds.
  • For example, AudioTrim(3.0, length=4.0) is equivalent to AudioTrim(3.0, -4.0)
  • length default = 0.0; must be >= 0.
  • Unlike the duration syntax, the length syntax has no discontinuous boundary values: length=0.0 means return a zero length clip. This feature is useful in avoiding unexpected boundary conditions in your user functions.


Examples

Trim(100,0)             # delete the first 100 frames, audio padded
                        # or trimmed to match the video length.
Trim(100,0,false)       # delete the first 100 frames of audio and video,
                        # the resulting stream lengths remain independent.
Trim(100,-100)          # is the same as trim(100,199) ie, start=100, duration=100
Trim(100,199,false)     # audio will be trimmed if longer but not
                        # padded if shorter to frame 199
Trim(0,-1)              # returns only the first frame
Trim(0,end=0)           #
Trim(0,length=1)        #
AudioTrim(1,5.5)        # keeps the audio samples between 1 and 5.5 seconds
AudioTrim(1,end=5.5)    #
AudioTrim(1,-5.5)       # cuts the first second and keeps the following 5.5 seconds
AudioTrim(1,length=5.5) #


Changes

v2.60 Added AudioTrim. Added length and end parameters.
v2.56 Added pad audio.
Personal tools