Trim

From Avisynth wiki
Revision as of 16:04, 28 December 2013 by Admin (Talk | contribs)

Jump to: navigation, search

Trim(clip clip, int first_frame, int last_frame [, bool "pad"])
Trim(clip 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"])
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.

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).

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".

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.

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.

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:

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