Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th October 2014, 06:51   #21  |  Link
gnol009
Registered User
 
Join Date: Feb 2010
Posts: 11
Thank you very much. Work like a charm
gnol009 is offline   Reply With Quote
Old 30th March 2015, 00:44   #22  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Prune(), New version v1.11, see 1st post.
Code:
27/Mar/2012 - ver 1.10      - Added Nicknames.
30/Mar/2015 - ver 1.11 - Added v2.6 dll. Shows Nicknames when Show.
v2.6 dll allows view metrics on v2.6 colorspace frames.

EDIT: Added to avs files

Code:
Avisource("D:\avs\test.avi")

ConvertToYV24       # v2.6

V0 = Last
V1 = FlipVertical 
V2 = FlipHorizontal
V3 = TurnRight.BilinearResize(Width,Height)
V4 = TurnLeft.BilinearResize(Width,Height)
V5 = Invert

NickNames ="""  # Psuedonyms for clips (clip index number)
    ButlinsBytheSea_76       = 0
    PontinsRainedOut_77      = 1
    BultinsBognorRegis_78    = 2 
    BultinsSkegness_79       = 3
    PontinsCamberSands_80    = 4 
    PontinsLowestoft_81      = 5
"""

SCMD="""          # Clip editing commands in string, can also use commands in file
    ButlinsBytheSea_76       500,600
    PontinsRainedOut_77      900,1000
    BultinsBognorRegis_78    1400,1600
    BultinsSkegness_79       2000,2400
    PontinsCamberSands_80    2640,3000
    PontinsLowestoft_81      4400,4800
    PontinsRainedOut_77      5000,5400
    5                        6000,6500    # clip index instead of nickname
    1                        6501,7000            
"""

SHOW=True

Prune(V0,V1,V2,V3,V4,V5,scmd=SCMD,nickname=NickNames,show=SHOW,FadeIn=True,FadeSplice=True,FadeOut=True)

return ConvertToRGB32   # For YV24 viewing
EDIT: Also added this [also included in FrameSel() plug zip]
Code:
Function RejectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS") {
    # RejectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
    # Wrapper to delete frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
    #   The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
    #   eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
    #   are only using a single clip here. Prune also does not have a 'reject' arg to delete specified frames rather than select them,
    #   this wrapper also converts a list of frames to delete into a list of frames to select so that we can use Prune and its audio
    #   capability.
    #
    # SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
    # Cmd:  Frames/Ranges specified in file (one frame/range per line, comments also allowed, see FrameSel for Further info).
    # TrimAudio:
    #   True(default), deletes audio belonging to deleted frames
    #   False, returns original audio, probably out of sync.
    # FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
    c
    TrimAudio=Default(TrimAudio,True)   # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
    FadeMS=Float(Default(FadeMS,1.0))   # 1 millisecond linear fadeout/fadein at splices
    PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
    (!TrimAudio)
        \ ? FrameSel(scmd=SCmd,cmd=Cmd,reject=true)
        \ : FrameSel_CmdReWrite(PruneCmd,scmd=SCmd,cmd=Cmd,reject=true,Prune=True,range=true)
    (TrimAudio) ? Prune(Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
    # If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
    (TrimAudio)
        \ ? RT_FileDelete(PruneCmd)
        \ : (c.HasAudio) ? AudioDub(c) : NOP
    Return Last
}

Function SelectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS",Bool "Ordered") {
    # SelectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
    # Wrapper to Select frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
    #   The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
    #   eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
    #   are only using a single clip here.
    #
    # SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
    # Cmd:  Frames/Ranges specified in file (one frame/range per line, comments allowed, see FrameSel for Further info).
    #  *** NOTE ***, If both Cmd and SCmd supplied AND Ordered == False, then will process Cmd file and then SCmd string afterwards, ie
    #    Will select ranges in Cmd file and in order specified (rather than auto ordering ranges) and then append ranges specified in
    #    SCmd string (and in order specified).
    # TrimAudio:
    #   True(default), selects audio belonging to selected frames/ranges
    #   False, returns original audio, probably out of sync (maybe totally out of whack if Ordered == false and selected ranges out of order).
    # FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
    # Ordered:
    #   True(default), all frames/ranges are returned in sequencial order. Any frame specified more than once will return only 1 instance.
    #   False, All frames/Ranges are returned in specified order, Cmd processed first and then SCmd. Frames/ranges specified more than once
    #     will return multiple instances. Allows out-of-order trimming of clip, eg re-sequencing of scenes in movie.
    #
    # Does not make much sense to select individual frames with audio, best used with ranges.
    # Will coalesce individually selected adjacent frames/ranges before any Fade, ie only audio fade where sensible to do so.
    # TrimAudio==false with non Ordered selection will result in completely out of sync audio.
    c
    TrimAudio=Default(TrimAudio,True)   # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
    FadeMS=Float(Default(FadeMS,1.0))   # 1 millisecond linear fadeout/fadein at splices
    Ordered=Default(Ordered,True)       # True (default) frames/ranges will be Ordered and selected only once even if specified more than once.
                                        # False, frames/ranges returned in specified order, Cmd processed 1st and then SCmd.
    PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
    (!TrimAudio)
        \ ? FrameSel(scmd=SCmd,cmd=Cmd,Ordered=Ordered)
        \ : FrameSel_CmdReWrite(PruneCmd,scmd=SCmd,cmd=Cmd,Ordered=Ordered,Prune=True,range=true)
    (TrimAudio) ? Prune(Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
    # If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
    (TrimAudio)
        \ ? RT_FileDelete(PruneCmd)
        \ : (c.HasAudio) ? AudioDub(c) : NOP
    Return Last
}
EDIT: Before anyone points it out, I know I've mis-spelt Butlins wrong in 1st script, just a test to see how observant you all are.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 30th March 2015 at 12:55.
StainlessS is offline   Reply With Quote
Old 30th March 2015, 12:56   #23  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Here frame from supplied avs demo showing audio FadeSplice at 25.0 millisecs (default 1.0 ) duration, using DavidHorman Waveform plug,
3 video frames duration of audio displayed:


FadeSplice avoids 'clicks' and 'cracks' in audio due to splice where significant change in audio phase/amplitude across
the spliced frames. Showing three Tone waveforms Sawtooth, Square and Sine.

FadeSplice implemented due to this thread:- http://forum.doom9.org/showthread.php?t=162907

EDIT: And here script that produced above
Code:
# For testing Prune() Fade

# This script can crash in Avisynth v2.58 due to a bug in the audio Cache.
# It is more likely to happen if AudioGraph is used, so this is disabled for v2.58

# Multiple Scriptclip's can produce a RealTime Video Lag behind Audio if the machine is not powerfull enough
# to cope with it, If so, then try with a lower FPS clip. Output to saved file should be fine. 

FPS     = 10.0                              # Lower if Video Lags behind Audio
CHANS   = 1
HZ      = 48000
BIT16   = false
SHOW    = true          # true = Show Info
VER     = true          # true = Show Version
NOERR   = true          # true = ignore, Ignorable Errors
DV      = 2             # DebugView, 0=Off, 1=Show Errors, 2=Errors+Warnings,3=Info+Errors+Warnings,4 = Debug ie all
FADE    = 25.0          # Default 1 (1 millisecond)
FADEIN  = true          # default False, Fade in 1st frame (if FADE non zero).
FADESPLICE = true       # default False, Fade out/in splices (if FADE non zero).
FADEOUT = true          # default False, Fade out last frame (if FADE non zero).

R0=ColorBars(512,384).AssumeFPS(FPS)

R3=R0.FlipHorizontal().FlipVertical().AudioDub(Tone(3600.0,77.6,HZ,CHANS,"Square",level=0.55)).Trim(0,9999)
R2=R0.FlipVertical().AudioDub(Tone(3600.0,63.5,HZ,CHANS,"Sawtooth",level=0.65)).Trim(0,9999)
R1=R0.FlipHorizontal().AudioDub(Tone(3600.0,59.2,HZ,CHANS,"Triangle",level=0.75)).Trim(0,9999)
R0=R0.AudioDub(Tone(3600.0,53.7,HZ,CHANS,"sine",level=0.95)).Trim(0,9999)

R0=(BIT16) ?R0.ConvertAudioTo16bit(): R0
R1=(BIT16) ?R1.ConvertAudioTo16bit(): R1
R2=(BIT16) ?R2.ConvertAudioTo16bit(): R2
R3=(BIT16) ?R3.ConvertAudioTo16bit(): R3

R0=R0.ScriptClip("""subtitle(Align=5,size=48,"R0("+string(current_frame)+")")""")
R1=R1.ScriptClip("""subtitle(Align=5,size=48,"R1("+string(current_frame)+")")""")
R2=R2.ScriptClip("""subtitle(Align=5,size=48,"R2("+string(current_frame)+")")""")
R3=R3.ScriptClip("""subtitle(Align=5,size=48,"R3("+string(current_frame)+")")""")

cmd="Prune_Fade_Test_Cmd.txt"

SCmd="
    R0 1
    R1 2
    R2 3
    R3 4
    R0 5,6
    R1 7,10
    R2 12,17
    R3 2
    "

#cmd=""                 # Uncomment to switch Off Command file
#scmd=""                # Uncomment to switch Off Command String

Prune(R0,R1,R2,R3,CMD=Cmd,SCmd=SCmd,show=SHOW,ver=VER,Noerr=NOERR,dv=DV,fade=FADE,FadeIn=FADEIN,FadeSplice=FADESPLICE,FadeOut=FADEOUT)

# Not very interesting without the below Audio Graph in v2.58.
#(VersionNumber<> 2.58)?AudioGraph(1):Last       # AudioGraph more likely exposes Avisnynth v2.58 Audio Cache Bug
(VersionNumber<> 2.58)?waveform(1):Last            # waveform more likely exposes Avisnynth v2.58 Audio Cache Bug
Contents of additional file, Prune_Fade_Test_Cmd.txt
Code:
R0 77,-1
R1 34,-2
R2 150,-3
R3 66,-4
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 21st December 2018 at 01:12.
StainlessS is offline   Reply With Quote
Old 1st April 2015, 19:16   #24  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Prune v1.12, see 1st post.
Minor mod, Display NickNames in original casing when Show=true (was all uppercased).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 21st December 2018, 00:24   #25  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Prune v1.13, see first post.
Moved to VS2008, added version resource, and x64.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 22nd December 2018, 00:36   #26  |  Link
gispos
Registered User
 
Join Date: Oct 2018
Location: Germany
Posts: 996
Very nice that you reworked your plugins and you now also offer in 64bit.
Thank you.
__________________
Live and let live
gispos is offline   Reply With Quote
Old 27th July 2021, 21:41   #27  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Prune v1.14, see 1st post.
[Available only on MediaFire in sig below this post, having problems getting into my SendSpace account].

Code:
	27/Mar/2012 - ver 1.10      - Added Nicknames.
	30/Mar/2015 - ver 1.11 - Added v2.6 dll. Shows Nicknames when Show.
	01/Apr/2015 - ver 1.12 - Display Nicknames in original casing when Show.
	20/Dec/2018 - ver 1.13 - Moved to VS2008, Add x64.
	27/Jul/2021 - ver 1.14 - Add HBD text render [Show/Ver] using DDigit v2.0.
Would previously work just fine with HBD clips, except where Show = true OR Ver = True, ie printing metrics text on frame.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th July 2021 at 21:45.
StainlessS is offline   Reply With Quote
Old 28th July 2021, 12:41   #28  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Just a heads up,
the 3 recently updated plugs, FrameSel, Prune, and ClipClop,
all show an older version and date in forum [Avisynth Usage] lists,
when thread is older than some age, thread titles cannot be updated, however shows
correct version and date on the first thread post.
Forum VBulletin software problem.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 10th December 2021, 06:27   #29  |  Link
lewyturn
Registered User
 
Join Date: May 2019
Posts: 18
How to use 'Prune', can you give me an example?
lewyturn is offline   Reply With Quote
Old 10th December 2021, 12:07   #30  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
From post #22
Code:
Avisource("D:\avs\test.avi")

ConvertToYV24       # v2.6

V0 = Last
V1 = FlipVertical 
V2 = FlipHorizontal
V3 = TurnRight.BilinearResize(Width,Height)
V4 = TurnLeft.BilinearResize(Width,Height)
V5 = Invert

NickNames ="""  # Psuedonyms for clips (clip index number)
    ButlinsBytheSea_76       = 0
    PontinsRainedOut_77      = 1
    BultinsBognorRegis_78    = 2 
    BultinsSkegness_79       = 3
    PontinsCamberSands_80    = 4 
    PontinsLowestoft_81      = 5
"""

SCMD="""          # Clip editing commands in string, can also use commands in file
    ButlinsBytheSea_76       500,600
    PontinsRainedOut_77      900,1000
    BultinsBognorRegis_78    1400,1600
    BultinsSkegness_79       2000,2400
    PontinsCamberSands_80    2640,3000
    PontinsLowestoft_81      4400,4800
    PontinsRainedOut_77      5000,5400
    5                        6000,6500    # clip index instead of nickname
    1                        6501,7000            
"""

SHOW=True

Prune(V0,V1,V2,V3,V4,V5,scmd=SCMD,nickname=NickNames,show=SHOW,FadeIn=True,FadeSplice=True,FadeOut=True)

return ConvertToRGB32   # For YV24 viewing
It just does trim and splice based on a command file, with up to 256 source clips.
Above uses Nicknames, might be more usual to use clip index numbers.
Scriptor can create command file via some detect script.

Its for scriptors/scriptess's, if you dont know what you want it for then you probably dont need it.

EDIT: SelectRanges/RejectRanges, functions using Prune[also requires FrameSel and RT_Stats]:- https://forum.doom9.org/showthread.p...59#post1683559

Code:
Function RejectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS") {
    # RejectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
    # Wrapper to delete frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
    #   The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
    #   eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
    #   are only using a single clip here. Prune also does not have a 'reject' arg to delete specified frames rather than select them,
    #   this wrapper also converts a list of frames to delete into a list of frames to select so that we can use Prune and its audio
    #   capability.
    #
    # SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
    # Cmd:  Frames/Ranges specified in file (one frame/range per line, comments also allowed, see FrameSel for Further info).
    # TrimAudio:
    #   True(default), deletes audio belonging to deleted frames
    #   False, returns original audio, probably out of sync.
    # FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
    c
    TrimAudio=Default(TrimAudio,True)   # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
    FadeMS=Float(Default(FadeMS,1.0))   # 1 millisecond linear fadeout/fadein at splices
    PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
    (!TrimAudio)
        \ ? FrameSel(Last,scmd=SCmd,cmd=Cmd,reject=true)
        \ : FrameSel_CmdReWrite(Last,PruneCmd,scmd=SCmd,cmd=Cmd,reject=true,Prune=True,range=true)
    (TrimAudio) ? Prune(Last,Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
    # If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
    (TrimAudio)
        \ ? RT_FileDelete(PruneCmd)
        \ : (c.HasAudio) ? AudioDub(c) : NOP
    Return Last
}
Client script for RejectRanges [delete frames/ranges specified in command file, from a clip]
Code:
avisource("d:\avs\flashtest.avi").trim(1000,-20).showframenumber # 20 frames

SCMD="""    # This is a comment
    1       # delete frame 1
    9       # delete frame 9
    11,15   # delete range 11 to 15
"""

# del.txt = file containing eg "3"+chr(10)+"5"+chr(10)+"7"+chr(10)
RejectRanges(scmd=SCMD,cmd="del.txt")    		# Delete frames 1 & 9, 11 to 15, and frames in del.txt 3 and 5 and 7, trim audio 1 ms fade
#RejectRanges(scmd="1;9;11,15",cmd="del.txt")           # Exactly the same as above
Same sorta thing but for selecting ranges rather than deleting them

SelectRanges, Script function to select ranges from clip, together with audio.
Code:
Function SelectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS",Bool "Ordered") {
    # SelectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
    # Wrapper to Select frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
    #   The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
    #   eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
    #   are only using a single clip here.
    #
    # SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
    # Cmd:  Frames/Ranges specified in file (one frame/range per line, comments allowed, see FrameSel for Further info).
    #  *** NOTE ***, If both Cmd and SCmd supplied AND Ordered == False, then will process Cmd file and then SCmd string afterwards, ie
    #    Will select ranges in Cmd file and in order specified (rather than auto ordering ranges) and then append ranges specified in
    #    SCmd string (and in order specified).
    # TrimAudio:
    #   True(default), selects audio belonging to selected frames/ranges
    #   False, returns original audio, probably out of sync (maybe totally out of whack if Ordered == false and selected ranges out of order).
    # FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
    # Ordered:
    #   True(default), all frames/ranges are returned in sequencial order. Any frame specified more than once will return only 1 instance.
    #   False, All frames/Ranges are returned in specified order, Cmd processed first and then SCmd. Frames/ranges specified more than once
    #     will return multiple instances. Allows out-of-order trimming of clip, eg re-sequencing of scenes in movie.
    #
    # Does not make much sense to select individual frames with audio, best used with ranges.
    # Will coalesce individually selected adjacent frames/ranges before any Fade, ie only audio fade where sensible to do so.
    # TrimAudio==false with non Ordered selection will result in completely out of sync audio.
    c
    TrimAudio=Default(TrimAudio,True)   # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
    FadeMS=Float(Default(FadeMS,1.0))   # 1 millisecond linear fadeout/fadein at splices
    Ordered=Default(Ordered,True)       # True (default) frames/ranges will be Ordered and selected only once even if specified more than once.
                                        # False, frames/ranges returned in specified order, Cmd processed 1st and then SCmd.
    PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
    (!TrimAudio)
        \ ? FrameSel(Last,scmd=SCmd,cmd=Cmd,Ordered=Ordered)
        \ : FrameSel_CmdReWrite(Last,PruneCmd,scmd=SCmd,cmd=Cmd,Ordered=Ordered,Prune=True,range=true)
    (TrimAudio) ? Prune(Last,Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
    # If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
    (TrimAudio)
        \ ? RT_FileDelete(PruneCmd)
        \ : (c.HasAudio) ? AudioDub(c) : NOP
    Return Last
}

Client script for SelectRanges
Code:
avisource("d:\avs\flashtest.avi").trim(1000,-20).showframenumber # 20 frames

SCMD="""    # This is a comment
    1,3     # Select Range 1 to 3
    9,11    # Select Range 9 to 11
    14,15   # Select Range 14 to 15
    2,5     # Select Range 2 to 5, If Ordered==True then already previously selected 1st range above (1,3) extended to 1,5
"""

ORDERED=True
SelectRanges(scmd=SCMD,Ordered=ORDERED)                      # Select SCmd ranges, trim audio 1 ms fade.
#SelectRanges(scmd="1,3;9,11;14,15;2,5",Ordered=ORDERED)     # Exactly the same as above
EDIT:
Post #16, has template command file creator scripts, to delete or keep frames based on some runtime function [eg AverageLuma, YDifferenceFromPrevious, etc].
https://forum.doom9.org/showthread.p...98#post1539598
EDIT:

Command Generator functions
PruneGenny.avsi
Code:
# PruneGenny.avsi
Function PruneKeepFrames(clip c, string fileName, string condition, bool "Fast") {
# Conditional KEEP frames Command File generator for Prune()
# MUST call with correct colorspace for condition eg YDifferenceFromPrevious requires a Planar colorspace.
# May require additional condition for end frames for eg YDifferenceFromPrevious and YDifferenceToNext.
#  Any-DifferenceFromPrevious,
#     Gives 0 for frame zero and so you may want to add to condition " || current_frame==0" to include frame 0.
#  Any-DifferenceToNext,
#     Gives 0 for last frame and so you may want to add to condition " || current_frame==framecount-1 " to include last frame.

    c=(Default(Fast,true))?c.AssumeFPS(250.0):c         # Fast as we can if Fast = true (Default true)
    WriteFileIf(c, fileName, condition, """ "0," """, "current_frame", append=false)
} 

Function PruneDeleteFrames(clip c, string fileName, string condition, bool "Fast") {
# Conditional DELETE frames Command File generator for Prune()
# MUST call with correct colorspace for condition eg YDifferenceFromPrevious requires a Planar colorspace.
# Is EXACT opposite of PruneKeepFrames() for same conditional.
# NOTE, any additional end frame condition as used in PruneKeepFrames, will also be inverted
#   eg " || current_frame==0", frame 0 would be deleted.

    c=(Default(Fast,true))?c.AssumeFPS(250.0):c         # Fast as we can if Fast = true (Default true)
    condition = "!(" + condition + ")"
    WriteFileIf(c, fileName, condition, """ "0," """, "current_frame", append=false)
}

###########################
# Below :HINT ON USE:
/* ################
  Avisource("In.avi").ConvertToYV12()     # Planar Required for AverageLuma and YDifferenceFromPrevious
#####  pick one of below [can replace 0.1 with whatever threshold you like]
  #PruneKeepFrames(".\cmd.txt","AverageLuma>=0.1")
  #PruneDeleteFrames(".\cmd.txt","AverageLuma>=0.1")
#####  Or with additional conditional for end frame [YDifferenceFromPrevious ALWAYS 0.0 on frame 0, YDifferenceToNext ALWAYS 0.0 on last frame]
  #PruneKeepFrames(".\cmd.txt","YDifferenceFromPrevious>=0.1 || current_frame==0")           # Always keeps first frame 0 (else delete)
  #PruneDeleteFrames(".\cmd.txt","YDifferenceFromPrevious>=0.1 || current_frame==0")         # Always deletes first frame 0 (else keep)
  #PruneKeepFrames(".\cmd.txt","YDifferenceToNext>=0.1 || current_frame==framecount-1")      # Always keeps last frame (else delete)
  #PruneDeleteFrames(".\cmd.txt","YDifferenceToNext>=0.1 || current_frame==framecount-1")    # Always deletes last frame (else keep)
  Return last

#####  And Pass2
  Avisource("In.avi") #.ConvertToYV12()  # Planar Required for AverageLuma and YDifferenceFromPrevious NOT REQUIRED HERE
  Return Prune(cmd=".\cmd.txt")
################ */
Template function calls for above command generators
Code:
# Import(".\PruneGenny.avsi"
Avisource("In.avi").ConvertToYV12()     # Planar Required for AverageLuma and YDifferenceFromPrevious
# pick one of below [can replace 0.1 with whatever threshold you like]

#PruneKeepFrames(".\cmd.txt","AverageLuma>=0.1")
#PruneDeleteFrames(".\cmd.txt","AverageLuma>=0.1")

# Or with additional conditional for end frame [YDifferenceFromPrevious ALWAYS 0.0 on frame 0, YDifferenceToNext ALWAYS 0.0 on last frame]

#PruneKeepFrames(".\cmd.txt","YDifferenceFromPrevious>=0.1 || current_frame==0")           # Always keeps first frame 0 (else delete)
#PruneDeleteFrames(".\cmd.txt","YDifferenceFromPrevious>=0.1 || current_frame==0")         # Always deletes first frame 0 (else keep)
#PruneKeepFrames(".\cmd.txt","YDifferenceToNext>=0.1 || current_frame==framecount-1")      # Always keeps last frame (else delete)
#PruneDeleteFrames(".\cmd.txt","YDifferenceToNext>=0.1 || current_frame==framecount-1")    # Always deletes last frame (else keep)
Return last
And Pass2
Code:
    Avisource("In.avi") #.ConvertToYV12()  # Planar Required for AverageLuma and YDifferenceFromPrevious NOT REQUIRED HERE
    Return Prune(cmd=".\cmd.txt")


Below from another thread: http://forum.doom9.org/showthread.php?t=165345
Where a user wanted to delete based on a averageLuma of cropped area
Code:
# PASS 1
source=avisource("D:\avs\avi\1.avi").ConvertToYV12()

X       =   40          # X-Coord of Crop area, For your Area of Interest.
Y       =   40          # Y-Coord of Crop area
W       =   32          # Width  of Crop area, YV12, MOD4
H       =   32          # Height of Crop area, YV12, MOD4

METRICS =   True        # True To Show Metrics (NO Pass1 CMD file Created)
DIM     =   True        # True will dim NON Area Of Interest when viewing Metrics
Thresh  =   128.0       # 0.0 -> 255.0, Threshold for frame drops. SET using view metrics
ALIGN   =   7           # METRICS SubTitle Alignment 7=TopLeft, 1=BotLeft (As KeyPad)

# -----------------------

cropped=source.Crop(X,Y,W,H)    # Your area of interest

source = (DIM) ? source.levels(0,1.0,255,0,128).Overlay(cropped,x=X,y=Y,opacity=1.0) : source

Return (METRICS)\
        ? source.ScriptClip(""" TmpAL=cropped.AverageLuma() Subtitle(String(TmpAL) + ((TmpAL>Thresh)?" DROP":""),align=ALIGN)""" ) \
        : cropped.PruneDeleteFrames(".\cmd.txt","AverageLuma>Thresh",Fast=True)
And Pass2
Code:
    avisource("D:\avs\avi\1.avi") # .ConvertToYV12(), Not Necessary here.
    Return Prune(cmd=".\Cmd.txt")
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 10th December 2021 at 15:22.
StainlessS is offline   Reply With Quote
Old 1st January 2022, 11:13   #31  |  Link
lewyturn
Registered User
 
Join Date: May 2019
Posts: 18
Only the "R0" line can be executed. Help me see what's wrong
-------------------------------------------------------
v=directshowsource("I:\test\002\001.mp4")
SCmd="
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"
Prune(v,SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
---------------------------------------------------------------
lewyturn is offline   Reply With Quote
Old 1st January 2022, 11:49   #32  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 985
Quote:
Originally Posted by lewyturn View Post
Only the "R0" line can be executed. Help me see what's wrong
Shouldn't it be like this:

Code:
SCmd="""
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"""
VoodooFX is offline   Reply With Quote
Old 1st January 2022, 12:47   #33  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
SCmd="""
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"""

Either single or triple quotes ok there [only requires triple if eg double quote in a comment].

Above same as

SCmd="""
0 0,2200
1 6150,9150
2 9300,12425
3 15075,19125
"""
where R0 or 0 is clip index [R0 is a reserved name for clip 0],
However,

Quote:
Prune(v,SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
Will not work as you only provide a single clip, ie clip v, you also need provide clips 1, clip 2 and clip 3 to match the SCMD command string args. [or R1, R2, R3].

Eg,
Code:
v=directshowsource("I:\test\002\001.mp4")
v1 = v.Fliphorizontal
v2 = v.Flipvertical
v3 = v.Invert

SCmd="
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"
Prune(v,v1,v2,v3,   SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
Untested. [EDIT: Mod as per Gavino correction]

EDIT: If you want only single clip trim/splice
Code:
v=directshowsource("I:\test\002\001.mp4")

SCmd="          # OR
R0 0,2200       # 0 0,2200
R0 6150,9150    # 0 6150,9150
R0 9300,12425   # 0 9300,12425
R0 15075,19125  # 0 0,15075,19125
"
Prune(v,   SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
OR Better to use eg
Code:
v=directshowsource("I:\test\002\001.mp4")

SCmd="
0,2200
6150,9150
9300,12425
15075,19125
"
SelectRanges(v,   SCmd=SCmd)
Where you only need to provide the clip ranges, and a single clip v.
Prunes clip index's are for where you have multiple source clips.

EDIT:
Quote:
Originally Posted by lewyturn View Post
Only the "R0" line can be executed. Help me see what's wrong
-------------------------------------------------------
v=directshowsource("I:\test\002\001.mp4")
SCmd="
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"
Prune(v,SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
---------------------------------------------------------------
NoERR=True, is only for when you are 100% sure you know what you are doing, and want to ignore some errors,
in above script, the R1, R2, and R3 ranges will simply be ignored [because you did not provide those source clips].
The output to DebugView [google debugview] will show the commands that are ignored because you told it to ignore errors.
[Implemented as per Cretindesalpes request for same NoErr in ClipClop plugin].
From docs
Code:
       NoErr,  bool, Default false

                false = Stop on ANY command error. (usual mode)
                     You will be informed in DebugView which (if any) errors can be ignored if switched to NoErr==true.

                true =  Suppress trivial errors where possible.
                     Only use after you have viewed and dismissed as unimportant any DebugView errors displayed when NoErr==false.
                     Not all errors are ignorable.
EDIT: If you set NoErr=False, and use Debugview, it will produce an error, and show you in DebugView window the errors
and tell you if those errors can be ignored when you set NoErr=True.
IIRC, when you set NoErr=False, it will show in DebugView all errors in command, before eventual error abort with the first encountered error, as message.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st January 2022 at 19:17.
StainlessS is offline   Reply With Quote
Old 1st January 2022, 18:52   #34  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by StainlessS View Post
Code:
v=directshowsource("I:\test\002\001.mp4")
v1.v.Fliphorizontal
v2.v.Flipvertical
v3.v.Invert

SCmd="
R0 0,2200
R1 6150,9150
R2 9300,12425
R3 15075,19125
"
Prune(v,v1,v2,v3,   SCmd=SCmd, Show=true, Ver=true, dv=4, NoErr=true, Fade=25.0, FadeIn=true, FadeSplice=false, FadeOut=false, Nickname="")
Happy New Year, StainlessS!
I'm sure you meant to write
Code:
v=directshowsource("I:\test\002\001.mp4")
v1 = v.Fliphorizontal
v2 = v.Flipvertical
v3 = v.Invert
...
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 1st January 2022, 19:18   #35  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Yep, thanks Big G, fixed.
And a Happy New Year to you too
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Reply

Tags
editing, range, splice, trim

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.