Trim

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (added category)
(formatting, links, phrasing *** note renamed unnamed variables ***)
Line 1: Line 1:
{{Template:Func8Def|
+
== Trim ==
Trim(clip ''clip'', int ''first_frame'', int ''last_frame'' [, bool ''"pad"''])|
+
{{Template:Func3Def
Trim(clip ''clip'', int ''first_frame'', int ''-num_frames'' [, bool ''"pad"''])|
+
|Trim(clip, int ''first'', int [-]''last'' [, bool ''"pad"''])
Trim(clip, int ''first_frame'', int ''"end"'' [, bool ''"pad"''])|
+
|Trim(clip, int ''first'', [int ''"end"'' , bool ''"pad"''])
Trim(clip, int ''first_frame'', int ''"length"'' [, bool ''"pad"''])|
+
|Trim(clip, int ''first'', [int ''"length"'' , bool ''"pad"''])
AudioTrim(clip ''clip'', float ''start_time'', float ''end_time'')|
+
AudioTrim(clip ''clip'', float ''start_time'', float ''-duration'')|
+
AudioTrim(clip, float ''start_time'', float ''"end"'')|
+
AudioTrim(clip, float ''start_time'', float ''"length"'')
+
 
}}
 
}}
  
Trim trims a video clip so that it includes only the frames ''first_frame'' up to ''last_frame ''(''first_frame'' and'' last_frame'' are included). The audio is similarly trimmed so that it stays synchronized. Remember AviSynth starts counting at frame 0.
+
'''Trim''' trims a clip so that it includes only the frames {{FuncArg|first}} up to and including {{FuncArg|last}}. 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 last frame, that is -''num_frames'', you will get a clip starting at ''first_frame'' and it will be ''num_frames'' frames long. If you set the last frame to zero, you will get a clip starting at ''first_frame'' (cutting only frames at the start of the clip).
+
If you set a negative value for the second argument, that is '''-'''{{FuncArg|last}}, you will get a clip starting at {{FuncArg|first}} and running for {{FuncArg|last}} frames. If you set {{FuncArg|last}} to zero, you will get a clip starting at {{FuncArg|first}} and running to the end of the clip.
  
Prior to v2.60, to trim an audio-only clip, you may not just set a fake frame rate with [[AssumeFPS]]. Instead, you must make a [[BlankClip]], use [[AudioDub]], trim ''that'', and then [[KillVideo]]. Otherwise, AviSynth returns an error message "cannot trim if there is no video".
+
{{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, end=7)&nbsp;&nbsp;&nbsp;</tt> instead of <tt>&nbsp;Trim(3, 7)</tt>
 +
:* <tt>Trim(3, length=5)</tt> instead of <tt>&nbsp;Trim(3, -5)</tt>
 +
:Unlike the first 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.
  
Since v2.60 you can trim the audio using AudioTrim. The ''start_time'', ''end_time'' and ''duration'' need to be specified in seconds (but can be float). Like Trim it keeps only the audio samples corresponding to ''start_time'' up to ''end_time''. The target source clip does not need to have a video track. If present the video is similarly trimmed so that it stays synchronized within 1 frame duration.
+
{{Par2|pad|bool|true}}
 +
: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]])
  
''pad'' (default true) causes the audio stream to be padded to align with the video stream. Otherwise the tail of a short audio stream is left so. When ''last_frame''=0 and ''pad''=false the end of the two streams remains independent.
+
;''Trim'' with audio-only clips
 +
In AviSynth v2.60, to trim an audio-only clip, you simply set a fake frame rate with [[AssumeFPS]]. In earlier versions you cannot do this: you must make a [[BlankClip]], use [[AudioDub]], trim ''that'', and then [[KillVideo]]. Otherwise, AviSynth returns the error message "cannot trim if there is no video".  
  
Since v2.60 you can also use AudioTrim/Trim(3, end=7) instead of AudioTrim/Trim(3, 7) and AudioTrim/Trim(3, length=7) instead of AudioTrim/Trim(3, -7). Note, the End and Length explicitly named parameters have no discontinuous boundary values. End=0 means end at frame 0. Length=0 means return a zero length clip. These are most useful in avoiding unexpected boundary conditions in your user functions.
 
  
'''Examples:'''
+
== AudioTrim ==
 +
{{Template:Func3Def
 +
|AudioTrim(clip, float ''first'', float [-]''last'')
 +
|AudioTrim(clip, float ''first'' [, float ''"end"''])
 +
|AudioTrim(clip, float ''first'' [, float ''"length"''])
 +
}}
 +
 
 +
'''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. The returned clip includes only the audio (or video+audio) from time {{FuncArg|first}} up to and including time {{FuncArg|last}}. All time arguments are in seconds.
 +
 
 +
If you set a negative value for the second argument, that is '''-'''{{FuncArg|last}}, you will get a clip starting at {{FuncArg|first}} seconds and running for {{FuncArg|last}} seconds. If you set {{FuncArg|last}} to zero, you will get a clip starting at {{FuncArg|first}} seconds and running to the end of the clip.
 +
 
 +
{{Par2|end|float|0.0}}
 +
{{Par2|length|float|0.0}}
 +
:You may prefer the alternate syntax with named arguments; for example,
 +
:* <tt>AudioTrim(3.0, end=7.0)&nbsp;&nbsp;&nbsp;</tt> instead of <tt>&nbsp;AudioTrim(3.0, 7.0)</tt>
 +
:* <tt>AudioTrim(3.0, length=4.0)</tt> instead of <tt>&nbsp;AudioTrim(3.0, -4.0)</tt>
 +
 
 +
{{Par2|pad|bool|true}}
 +
::Causes the audio stream to be padded to align with the video stream, if one is present. Works in the same way as for '''Trim'''.
 +
 
 +
 
 +
== Examples ==
  
 
  Trim(100,0)            # delete the first 100 frames, audio padded
 
  Trim(100,0)            # delete the first 100 frames, audio padded
 
                         # or trimmed to match the video length.
 
                         # or trimmed to match the video length.
 +
 
  Trim(100,0,false)      # delete the first 100 frames of audio and video,
 
  Trim(100,0,false)      # delete the first 100 frames of audio and video,
 
                         # the resulting stream lengths remain independent.
 
                         # the resulting stream lengths remain independent.
 +
 
  Trim(100,-100)          # is the same as trim(100,199) ie, start=100, duration=100
 
  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
 
  Trim(100,199,false)    # audio will be trimmed if longer but not
 
                         # padded if shorter to frame 199
 
                         # padded if shorter to frame 199
 +
 
  Trim(0,-1)              # returns only the first frame
 
  Trim(0,-1)              # returns only the first frame
  Trim(0,End=0)          #
+
  Trim(0,end=0)          #
  Trim(0,Length=1)        #
+
  Trim(0,length=1)        #
 +
 
 
  AudioTrim(1,5.5)        # keeps the audio samples between 1 and 5.5 seconds
 
  AudioTrim(1,5.5)        # keeps the audio samples between 1 and 5.5 seconds
  AudioTrim(1,End=5.5)    #
+
  AudioTrim(1,end=5.5)    #
 +
 
 
  AudioTrim(1,-5.5)      # cuts the first second and keeps the following 5.5 seconds
 
  AudioTrim(1,-5.5)      # cuts the first second and keeps the following 5.5 seconds
  AudioTrim(1,Length=5.5) #
+
  AudioTrim(1,length=5.5) #
  
'''Changes:'''
 
  
 +
== Changes ==
 
{| border="1"
 
{| border="1"
 
|-  
 
|-  

Revision as of 14:02, 7 January 2016

Contents

Trim

Trim(clip, int first, int [-]last [, bool "pad"])
Trim(clip, int first, [int "end" , bool "pad"])
Trim(clip, int first, [int "length" , bool "pad"])

Trim trims a clip so that it includes only the frames first up to and including last. The audio is similarly trimmed so that it stays synchronized (see pad below). Remember AviSynth starts counting at frame 0.

If you set a negative value for the second argument, that is -last, you will get a clip starting at first and running for last frames. If you set last to zero, you will get a clip starting at first and running to the end of the clip.

int  end = 0
int  length = 0

In Avisynth v2.60, you may use the alternate syntax with named arguments; for example,
  • Trim(3, end=7)    instead of  Trim(3, 7)
  • Trim(3, length=5) instead of  Trim(3, -5)
Unlike the first syntax, the alternate syntax has no discontinuous boundary values: end=0 means end at frame 0; length=0 means return a zero length clip. These are most useful in avoiding unexpected boundary conditions in your user functions.

bool  pad = true

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 Splice)
Trim with audio-only clips

In AviSynth v2.60, to trim an audio-only clip, you simply set a fake frame rate with AssumeFPS. In earlier versions you cannot do this: you must make a BlankClip, use AudioDub, trim that, and then KillVideo. Otherwise, AviSynth returns the error message "cannot trim if there is no video".


AudioTrim

AudioTrim(clip, float first, float [-]last)
AudioTrim(clip, float first [, float "end"])
AudioTrim(clip, float first [, float "length"])

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. The returned clip includes only the audio (or video+audio) from time first up to and including time last. All time arguments are in seconds.

If you set a negative value for the second argument, that is -last, you will get a clip starting at first seconds and running for last seconds. If you set last to zero, you will get a clip starting at first seconds and running to the end of the clip.

float  end = 0.0
float  length = 0.0

You may prefer the alternate syntax with named arguments; for example,
  • AudioTrim(3.0, end=7.0)    instead of  AudioTrim(3.0, 7.0)
  • AudioTrim(3.0, length=4.0) instead of  AudioTrim(3.0, -4.0)

bool  pad = true

Causes the audio stream to be padded to align with the video stream, if one is present. Works in the same way as for Trim.


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