Trim
跳至導覽
跳至搜尋
Trim(clip clip, int first_frame, int last_frame [, bool pad_audio])
參數
Trim截取一個視頻片段中從first_frame到last_frame幀數(first_frame和last_frame也包含在內)。如果該片段包含音頻,則音頻也會一併被截取。截取時請注意,AviSynth計算幀數從0開始,既一個片段的第一幀的編號並不是1,而是0。當last_frame為0時,Trim會一直截取到視頻最後一幀。
Trim不能被用作單獨截取音頻片段。如果需要截取音頻片段,您需要首先用BlankClip生成一個空白視頻片段,再用AudioDub將音頻視頻結合,再將這個片段用Trim截取後,通過KillVideo刪除視頻部分,只留下音頻。
pad_audio (默認: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_audio=false the end of the two streams remains independent.
一般用例
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) 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,100)+Trim(200,300) # returns frames 0 to 100 and 200 to 300 (i.e. removing 101 to 199)
對視頻進行分段處理
簡單的分段處理
v = avisource("source.avi") #载入视频 v1 = v.trim(0 , 99) #将视频分为v1、v2、v3三段,对v2用blur滤镜进行处理,保留v1、v3原样不动。 v2 = v.trim(100 , 1999).blur() v3 = v.trim(2000, 0) v1 + v2 + v3 #将三个段落重新进行拼接。
使用對混合型視頻進行分段處理:
- 假設視頻0~99幀為30i(需要進行deinterlace);
- 100~1999幀是pulldown(需要進行IVTC);
- 2000幀之後全部為30p(不需要進行任何處理,直接保留原樣)。
v = mpeg2source("source.d2v") #载入视频 v1 = v.trim(0 , 99).nnedi3() #对0~99帧用nnedi3进行deinterlace。 v2 = v.trim(100 , 1999).tfm(mode=3).tdecimate(mode=1).AssumeFPS(30000/1001) #用TIVTC对v2段落进行IVTC。由于IVTC之后帧率降为23.976,没办法与v1和v2直接拼接, #所以这里用AssumeFPS将v2的帧率修改为29.970(=30000/1001)。 v3 = v.trim(2000, 0) v1 + v2 + v3 #将三个段落重新进行拼接。
當然,視頻輸出之後,還需要寫對應的Timecode,封裝為mkv才能讓視頻正確播放。
高級分段處理
由於單純依靠Trim進行複雜的分段和拼接比較麻煩,且分段腳本較為複雜繁冗,不便於閱讀和維護,不少用戶通過自定義腳本函數的方式實現了更加方便的分段處理。 請參考:
版本歷史
v2.56 | Added pad audio. |