Trim

From Avisynth wiki
Revision as of 01:00, 21 January 2016 by Raffriff42 (Talk | contribs)

Jump to: navigation, search

Contents

Trim

Trim(clip, int first_frame, int last_frame [, bool "pad"])
Trim(clip, int first_frame, int -num_frames [, bool "pad"])
Trim(clip, int first_frame, [int "end" , bool "pad"])
Trim(clip, int first_frame, [int "length" , bool "pad"])

Trim trims a clip so that it includes only the frames first_frame up to and including last_frame. 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 -num_frames, you will get a clip starting at first_frame and running for num_frames frames. If you set last_frame to zero, you will get a clip starting at first_frame 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, 7)  Trim(3, end=7)
  • Trim(3, -5) Trim(3, length=5)
Unlike the first_frame 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)
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(clip, float start_time, float end_time)
AudioTrim(clip, float start_time, float -duration)
AudioTrim(clip, float start_time [, float "end"])
AudioTrim(clip, float start_time [, 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 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 start_time up to and including time end_time. All time arguments are in seconds.

If you set a negative value for the second argument, that is -duration, you will get a clip starting at start_time seconds and running for duration seconds. If you set end_time to zero, you will get a clip starting at start_time 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, 7.0)  AudioTrim(3.0, end=7.0)
  • AudioTrim(3.0, -4.0) AudioTrim(3.0, length=4.0)


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