View Full Version : AvsPmod Removing Sections of Video??
BlockABoots
10th January 2013, 20:39
I know in AvsPmod (Avisynth) you can remove a single frame at a time but if you wanted to remove say a whole 5-10min section from a video is there a command for this?. As the only way i can see doing it is removing ever single frame for the 5-10mins but this just wouldnt be realistic and would take forever to script.
So is there a command where you can specify a starting frame and end frame to remove a whole section of video?
IanB
10th January 2013, 21:33
Trim(clip clip, int first_frame, int last_frame [, bool "pad"]) (http://avisynth.org/mediawiki/Trim)
mastrboy
10th January 2013, 21:34
You can do it the "other way around" with trim...
Lets say you want to remove frames 1000-2000, the command would be trim(0,999) ++ trim(2001,0)
(++ is short for alignedsplice)
BlockABoots
10th January 2013, 22:36
Trim(clip clip, int first_frame, int last_frame [, bool "pad"]) (http://avisynth.org/mediawiki/Trim)
Hmmm doing that seems to cut the whole video and only leave me with those frames when viewing in the preview video in PvsPmod?
BlockABoots
2nd February 2013, 21:52
Ok the command, trim(video,0,1000) ++ trim(video,9000,0) as mastrboy suggested works fine if you just have 1 section you want to remove from your video, but what command do i need to use if i have 2 sections or more i need to remove from a video, for example if i wanted frames 1000 to 9000, 12000 to 16000 and 16900 to 17900 removed. so 3 sections of a video.
What script do i need for such a thing?, would it be...
trim(0,1000) ++ trim(9000,1200) ++ trim(16000,16900) ++ trim(17900,0)
So basically im scritping the range of frame i want to keep and any frames that are not included in the range is removed?
StainlessS
2nd February 2013, 22:03
Trim(0,559)++Trim(1501,0) # drop frames 560 to 1500
Both previously suggested solutions are correct.
StainlessS
2nd February 2013, 22:13
I see that you've altered/edited your requirements.
Trim(Video,1000,9000)++Trim(Video,12000,16000)
EDIT: I see that you've changed your requirements yet again. You specify the frames that
you want to keep, not the ones that you want to remove.
Ok the command, trim(video,0,1000) ++ trim(video,9000,0) as mastrboy suggested works fine if you just have 1 section you want to remove from your video, but what command do i need to use if i have 2 sections or more i need to remove from a video, for example if i wanted frames 1000 to 9000, 12000 to 16000 and 16900 to 17900 removed. so 3 sections of a video.
What script do i need for such a thing?, would it be...
trim(0,1000) ++ trim(9000,1200) ++ trim(16000,16900) ++ trim(17900,0)
So basically im scritping the range of frame i want to keep and any frames that are not included in the range is removed?
Nearly,
trim(0,999) ++ trim(9001,11999) ++ trim(16001,16899) ++ trim(17901,0)
You need to think in terms of what you want, not what you dont want, the other road leads to
confusion.
EDIT: If you have a LOT of sections that you wish to splice together, you might find Prune()
of use. Prune takes up to 256 source clips, and a command string or file, eg:
V0=AviSource("D:\avs\avi\1.avi")
V1=AviSource("D:\avs\avi\2.avi")
SCMD=" # Command string to select video sections to splice together
0,1000,9000 # frames 1000 - 9000 from clip 0 ie V0
0,12000,16000 # frames 12000-16000 from clip 0 ie V0
1,10000,11000 # frames 10000-11000 from clip 1 ie V1
0,20000,30000 # frames 20000-30000 from clip 0 ie V0
# Etc
"
Result=Prune(V0,V1,scmd=SCMD)
Return Result
http://forum.doom9.org/showthread.php?t=162446&highlight=prune
bruno321
20th December 2020, 12:48
I'm reviving this because I'm interested in a simple, one-command solution. If I want to remove frames x to y, isn't there a command that does just that? Something like DeleteRange(x,y).
I've never written an avisynth function, and my first naive attempt failed miserably:
Function DeleteRange(clip c, int "from", int "to") {
Trim(0,from-1)++Trim(to+1,0)
}
:D
How could I make that idea work?
gispos
20th December 2020, 13:11
I know in AvsPmod (Avisynth) you can remove a single frame at a time but if you wanted to remove say a whole 5-10min section from a video is there a command for this?. As the only way i can see doing it is removing ever single frame for the 5-10mins but this just wouldnt be realistic and would take forever to script.
So is there a command where you can specify a starting frame and end frame to remove a whole section of video?
Take a look at the AvsPmod 'Trim editor'
hello_hello
20th December 2020, 14:11
I'm reviving this because I'm interested in a simple, one-command solution. If I want to remove frames x to y, isn't there a command that does just that? Something like DeleteRange(x,y).
How could I make that idea work?
The frame numbers you specify for DeleteRange are included in the range of deleted frames.
DeleteRange() would play the clip normally.
As would just specifying a single frame number. DeleteRange(50)
function DeleteRange(clip Vid, int "From", int "To") {
From = default(From, FrameCount(Vid) - 1) - 1
To = default(To, From) + 1
Vid.Trim(0, From) ++ Vid.Trim(To, 0) }
ScriptClip("subtitle(string(current_frame), align=5, size=30)")
# Line above for testing
DeleteRange(50, 100)
bruno321
20th December 2020, 19:26
Thanks gispos, I use avspmod all the time but I never really investigated what the trim editor can do for me, I'll take a look!
hello_hello, that works great, it was precisely what I had tried (and failed) to accomplish with my pseudocode:D
hello_hello
20th December 2020, 21:01
bruno321,
I had some time to kill, so here's a new and improved version. The earlier one probably wouldn't cope with things like deleting frame ranges starting or ending with zero. Hopefully there's no gremlins. There's error messages when you specify illegal frame ranges, such as an end frame number greater than the final video frame number. The error message will tell you what that frame number is.
# ===============================================================================
#
# DeleteFR() - Delete Frame Range
# https://forum.doom9.org/showthread.php?p=1931523#post1931523
#
# ===============================================================================
#
# For the First frame, zero always means frame zero (the first video frame).
# For the Last frame, zero means zero if the First frame is zero,
# otherwise zero means the final video frame.
#
# DeleteFR() Outputs the video untouched
# DeleteFR(0, 0) Only removes frame number 0 (the first video frame)
# DeleteFR(17, 17) Only removes frame number 17
# DeleteFR(17, 251) Removes frames 17 to 251
# DeleteFR(0, 386) Removes frames 0 to 386
# DeleteFR(924, 0) Removes every frame from 924 onwards
# DeleteFR(63, 21) Produces an error message
# DeleteFR(63) Produces an error message
#
# DeleteFR(17, 251, true, true) Displays before & after frame numbers
#
# ===============================================================================
function DeleteFR(clip Vid, int "First", int "Last", bool "Before", bool "After") {
End = FrameCount(Vid) - 1
IsFirst = defined(First)
IsLast = defined(Last)
First = default(First, 0)
Last = default(Last, 0)
Before = default(Before, false)
After = default(After, false)
Num1 = string(End, "%.0f ")
Num2 = string(End-1, "%.0f ")
assert((First >= 0) && (Last >= 0), " DeleteFR " + chr(10) + \
" First & Last can't be negative " + chr(10))
assert((!IsFirst && !IsLast) || (IsFirst && IsLast), " DeleteFR " + chr(10) + \
" First & Last must both be specified (or unspecified) " + chr(10))
assert((First <= End), " DeleteFR " + chr(10) + \
" For this clip, the max frame number for First is " + Num1 + chr(10))
assert((Last == 0) || (First <= Last), " DeleteFR " + chr(10) + \
" First must be less than or equal to Last, unless Last=0 " + chr(10))
assert((First != 0) || (Last <= (End-1)), " DeleteFR " + chr(10) + \
" For this clip, when First=0, the max frame number for Last is " + Num2 + chr(10))
assert((First == 0) || (Last <= End), " DeleteFR " + chr(10) + \
" For this clip, when First>0, the max frame number for Last is " + Num1 + chr(10))
Output = \
!Before ? Vid : \
Vid.ScriptClip("""
S = height() * 0.045
Y = (height() / 3.0) + S
subtitle("Before DeleteFR\n" + \
string(current_frame), align=2, y=Y, size=S, lsp=10) """)
Output = \
!IsFirst && !IsLast ? Output : \
(First == 0 == Last) ? Output.Trim(1, 0) : \
(First == 0) ? Output.Trim(Last+1, 0) : \
(Last == 0) || (Last == End) ? Output.Trim(0, First-1) : \
Output.Trim(0, end=First-1) ++ Output.Trim(Last+1, 0)
return \
!After ? Output : \
Output.ScriptClip("""
S = height() * 0.045
Y = (height() / 3.0) + (S * 6.0)
subtitle("After DeleteFR\n" + \
string(current_frame), align=2, y=Y, size=S, lsp=10) """) }
# ===============================================================================
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.