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 28th September 2008, 15:00   #21  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
@MOmonster: I assume your problem was that the attachment was still awaiting approval. It should be OK now.
Gavino is offline   Reply With Quote
Old 28th September 2008, 17:50   #22  |  Link
MOmonster
Registered User
 
Join Date: May 2005
Location: Germany
Posts: 495
Yes, thanks.
MOmonster is offline   Reply With Quote
Old 17th September 2009, 18:28   #23  |  Link
canuckerfan
Registered User
 
Join Date: Jul 2005
Posts: 317
Currently I'm using AviSynth 2.5.8's built-in scriptclip and conditionalreader. anyway I can adapt this code so that I can use Gavino's versions?

Code:
Filtered = RemoveNoiseMC(rdlimit=18,rgrain=1,denoise=0,sharp=true) 
ScriptClip("ABC1 ? Filtered : Last")
ConditionalReader("seriously.txt","ABC1",false)

Last edited by canuckerfan; 17th September 2009 at 19:00.
canuckerfan is offline   Reply With Quote
Old 17th September 2009, 19:06   #24  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
If you just load the GRunT plugin (or install it in the plugin folder), it will use my version automatically (if running on Avisynth 2.58).

For your example, where the run-time script is very simple, you wouldn't actually gain very much.
However, it would allow you to replace the ScriptClip call by
ConditionalFilter(Filtered, last, "ABC1")
which would be slightly faster.

Even without GRunT, it could also be changed, although with the standard ConditionalFilter you would have to write
ConditionalFilter(Filtered, last, "ABC1", "==", "true")

GRunT does not have its own version of ConditionalReader, so you would continue to use the standard version.
Gavino is offline   Reply With Quote
Old 17th September 2009, 20:03   #25  |  Link
canuckerfan
Registered User
 
Join Date: Jul 2005
Posts: 317
^Thank you
canuckerfan is offline   Reply With Quote
Old 13th March 2016, 04:56   #26  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
I have tried everything that I can think of. What I need is a single pass solution to step through a video and only retain frames where AverageLuma(a)>16 (IOW, retain only non-blank frames). Scriptclip can step through the video and conditionally test the AverageLuma value, but I can't get the new video out of the Scriptclip, even with GRunT. Any suggestions?
Forensic is offline   Reply With Quote
Old 13th March 2016, 06:26   #27  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Yo dude, long time no see.

So far as I know, Scriptclip must produce same number of output frames as input. (+ same size, colorspace etc).
So 1 single pass solution is unlikely. Although could do it as realtime 1st pass, with auto second pass.
No idea what IOW means.

But see here:- http://forum.doom9.org/showthread.php?t=172904

You might want to use YPlaneMinMaxDifference (Threshold=eg 0.2) to establish 'blank frame', and YPlaneMin or AverageLuma to establish level.
__________________
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 13th March 2016, 07:05   #28  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Something like this (writing frames to reject in realtime pass, as likely fewer than writing all selected frames)

Code:
Avisource("D:\V\StarWars.avi").Trim(0,10000)

GSCript("""
    Function Test(Clip c, int n,int v1,Float th,String File,Bool Show) {
        c
        mx   = RT_YPlaneMax(n,Threshold=th)
        if(mx < v1) {
            RT_WriteFile(File,"%d",n,Append=True)                       # Write unwanted frames (fewer than wanted)
            (Show) ? RT_SubTitle("%d] mx=%d - DELETING",n,mx) : NOP
        } else {(Show) ? RT_SubTitle("%d] mx=%d",n,mx) : NOP}
        Return Last    
    }    
""")

OutFile = "Frames.txt"
RT_FileDelete(OutFile)      # Delete existing  
V1 = 18                     # Was not deleteing anything for me at 16
th = 0.2                    # Avoid 0.2% of noise above v1
Show=True                   # CHANGE to FALSE when happy with numbers
SSS = "Test(current_frame,V1,th,OutFile,Show)"
ARGS= "v1,th,OutFile,Show"
ScriptClip(SSS,args=ARGS,after_frame=True)

(!Show)                 ? ForceProcessAVI()         : NOP               # Force Pass 1 (From TWriteAVI v2.0) ie force writing of frames file    
(!Show&&Exist(OutFile)) ? RejectRanges(Cmd=Outfile) : NOP               # If Outfile does not exist, then none to Reject.

Return last    
                            
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
}
and to view rejected frames only
Code:
Avisource("D:\V\StarWars.avi").Trim(0,10000)

    OutFile = "Frames.txt"
    SelectRanges(Cmd=Outfile)  # or change to RejectRanges to view kept after 1st pass script    
    Return last    
    
# From Prune [req FrameSel]            
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
}
You can rearrange logic however you will, above was just a quick knock-up.

Requires RT_Stats, FrameSel, Prune, and TWriteAVI v2.0. http://forum.doom9.org/showthread.ph...ight=twriteavi

EDIT:: Oops, and GSCript and Grunt too.

EDIT: This is more like what you asked for, set Show = False to do it for real, when true only shows metric
On my clip it was not deleting anything as all frames were above Ave luma 16.
Code:
Avisource("D:\V\StarWars.avi").Trim(0,10000)

GSCript("""
    Function Test(Clip c, int n,Float th,String File,Bool Show) {
        c
        Ave = RT_AverageLuma(n)    
        if(Ave < th) {
            RT_WriteFile(File,"%d",n,Append=True)           # Write unwanted frames (fewer than wanted)
            (Show) ? RT_SubTitle("%d] %f - DELETING",n,Ave) : NOP
        } else {(Show) ? RT_SubTitle("%d] %f",n,Ave) : NOP}
        Return Last    
    }    
""")

OutFile = "Frames.txt"
RT_FileDelete(OutFile)      # Delete existing  
th = 18.0                   # Keep >= 18.0
Show = True                 # CHANGE to FALSE when happy with numbers
SSS = """Test(current_frame,th,OutFile,Show)"""
ARGS="th,OutFile,Show"
ScriptClip(SSS,args=ARGS,after_frame=True)

(!Show)                 ? ForceProcessAVI()         : NOP   # Force Pass 1 (From TWriteAVI v2.0) ie force writing of frames file
(!Show&&Exist(Outfile)) ? RejectRanges(Cmd=Outfile) : NOP   # If Outfile does not exist, then none to Reject. 

Return last    
                
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
}
__________________
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; 13th March 2016 at 09:50.
StainlessS is offline   Reply With Quote
Old 13th March 2016, 08:25   #29  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
StainlessS. Thank you for this. I have been quite busy with my lab and creating FOSS (Free Open Source Software) that now has over 30,000 downloads and is relied upon by law enforcement worldwide. This would never have been possible without amazing programmers like you and Gavino. Your work has helped to solve crimes and has saved lives!!!! As for this script, it requires two functions I didn't have. I found "ForceProcessAVI" in your TWriteAVI_dll DLL but where do I find "RejectRanges"? Also IOW is a mostly American expression short for "In Other Words" which just means that something is being restated in another way.
Forensic is offline   Reply With Quote
Old 13th March 2016, 08:40   #30  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Select/Reject Ranges is in the Prune AVS directory. (also requires FrameSel to do the clever Select to Reject conversion for Prune).

IOW, I thought it could not possibly stand for "Isle Of White"

Prune: http://forum.doom9.org/showthread.ph...ighlight=Prune
FrameSel: http://forum.doom9.org/showthread.ph...light=FrameSel

EDIT: Or Select/Reject Ranges both posted in above code snippits, but still need the Prune and FrameSel plugins.
__________________
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; 13th March 2016 at 08:47.
StainlessS is offline   Reply With Quote
Old 13th March 2016, 09:33   #31  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by Forensic View Post
I have tried everything that I can think of. What I need is a single pass solution to step through a video and only retain frames where AverageLuma(a)>16 (IOW, retain only non-blank frames). Scriptclip can step through the video and conditionally test the AverageLuma value, but I can't get the new video out of the Scriptclip, even with GRunT. Any suggestions?
As an alternative to StainlessS's solution, you could use my DeleteFrames() function, like this:
Code:
DeleteFrames("AverageLuma() <= 16")
(It works out at compile-time which frames to delete, so the script will take a noticeable time to load for a long video.)

BTW Nice to hear my code is being used in real practical applications!
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 13th March 2016, 09:37   #32  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Yes indeed big G.
Although, an advantage of the frames file method is that it is easily repeatable without a second compile time run.
Also, RT_AverageLuma is faster than built-in so would cut down overhead on longer clips.
__________________
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; 13th March 2016 at 10:15.
StainlessS is offline   Reply With Quote
Old 13th March 2016, 18:19   #33  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
Thank you StainlessS & Gavino. DeleteFrames("RT_AverageLuma() <= 16") works like a charm. Simple single pass, and just what I wanted! Much appreciated.
Forensic is offline   Reply With Quote
Old 16th May 2016, 21:26   #34  |  Link
yesmanitsbearman
Registered User
 
Join Date: May 2015
Posts: 18
Hey,

Does anyone have a x64 version of this? Need it for srestore and it's the only one I can't find a x64 build for.
yesmanitsbearman is offline   Reply With Quote
Old 17th May 2016, 20:02   #35  |  Link
yesmanitsbearman
Registered User
 
Join Date: May 2015
Posts: 18
I've taken the liberty to compile the .dll myself. Had to also change some stuff to make it compile with latest avs+ headers. Hopefully this comes useful to someone. srestore now tested working on a fully x64 setup.

here it is
Attached Files
File Type: rar grunt-x64.rar (18.4 KB, 993 views)
yesmanitsbearman is offline   Reply With Quote
Old 18th May 2016, 03:24   #36  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,593
Quote:
Originally Posted by yesmanitsbearman View Post
I've taken the liberty to compile the .dll myself. Had to also change some stuff to make it compile with latest avs+ headers. Hopefully this comes useful to someone. srestore now tested working on a fully x64 setup.

here it is
can we have one work with 2.5 x64?
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 18th May 2016, 03:38   #37  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,669
Quote:
Originally Posted by real.finder View Post
can we have one work with 2.5 x64?
Why? 2.5 is outdated and there's no reason to be using it.

Quote:
Originally Posted by yesmanitsbearman View Post
... Perhaps someone can add it to the wiki.
Thanks for the build, I'll add it to the wiki.
Reel.Deel is offline   Reply With Quote
Old 18th May 2016, 03:49   #38  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,593
Quote:
Originally Posted by Reel.Deel View Post
Why? 2.5 is outdated and there's no reason to be using it.
yes, but I use it some times (for setmtmode) and 2.5 plugin work with avs+ too
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 20th May 2016, 10:36   #39  |  Link
yesmanitsbearman
Registered User
 
Join Date: May 2015
Posts: 18
I could never say no to you for all the times you helped me

here

Not tested though. Let me know if it's fine.
Attached Files
File Type: rar GrunT-x64-25.rar (12.9 KB, 145 views)
yesmanitsbearman is offline   Reply With Quote
Old 20th May 2016, 15:51   #40  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,593
Quote:
Originally Posted by yesmanitsbearman View Post
I could never say no to you for all the times you helped me

here

Not tested though. Let me know if it's fine.
thank you

with srestore(frate=23.976) I get http://i.imgur.com/yHVtNvM.png in the top of video frame

but with same GrunT-x64-25 in avs+ it's fine!
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Reply

Tags
conditional, plugin, run-time, scriptclip

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 17:13.


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