Log in

View Full Version : Throwing an EOF in Avisynth


Schlumpf
29th December 2004, 02:32
Hello, people.
I got the following script in Avisynth:


### should be changed, depending on the source ###
global howmuchiwant=50
global minimumdistance=24
global sensitivity=45

### should not be changed ###
global thresh=0
global number=0


Source = AVISource("C:\path\filename").Killaudio().ConvertToYV12(interlaced=false)

Main=Source.AssumeFPS(Source.framerate*8).ReduceBy2().ReduceBy2()


Clip1=Source.AssumeFPS(Source.framerate*8).Killaudio().ConvertToRGB24(interlaced=false).ImageWriter("c:\path\filename", 0, 0, "PNG").ConvertToYV12(interlaced=false).ReduceBy2().ReduceBy2().ReduceBy2().ReduceBy2()

Minimum=BlankClip(Main).ReduceBy2().ReduceBy2()

ConditionalFilter(Main,Clip1.Trim(1,0).FrameEvaluate("thresh = current_frame").FrameEvaluate("number= number+1"),Minimum,"(YDifferenceFromPrevious > sensitivity) && (thresh+minimumdistance <= current_frame) && (number < howmuchiwant)" , "equals","true", show=false)

This script is for taking a set amount of screenshots from scenechanges in a videofile, and only that amount.
The problem is how to stop processing of the whole videostream once the variable number has reached the amount of the variable howmuchiwant. In its current state the script will just keep on playing, thus wasting processsortime.
How could I make Avisynth throw a quasi-EOF?
Another thing: Virtual Dub can scan for Keyframes in a given videostream. Is there some way to do that with Avisynth? Then I could lay the suboptimal YDifferenceFromPrevious aside.

stickboy
29th December 2004, 04:56
Please use \s to break up lines so we don't have to do so much horizontal scrolling. :)
Originally posted by Schlumpf:
How could I make Avisynth throw a quasi-EOF?I don't think this is possible. You can't change the number of frames in a clip mid-filter.

I think the best you can do is to optimize your script so that if you've met your how muchiwant requirement, it doesn't process (or does minimal processing of) any additional frames.

Or maybe you could Assert(false) to try to abort, since by then all of your results should have been written to disk already, but I'm not certain that will work.
Another thing: Virtual Dub can scan for Keyframes in a given videostream. Is there some way to do that with Avisynth? Then I could lay the suboptimal YDifferenceFromPrevious aside.No, AVISource decodes all requested frames. Filters can't distinguish keyframes from non-keyframes.

Schlumpf
30th December 2004, 02:10
Originally posted by stickboy
Please use \s to break up lines so we don't have to do so much horizontal scrolling. :)
Sorry, I just don't get how ;__;

I don't think this is possible. You can't change the number of frames in a clip mid-filter.
I think we have a little misunderstanding here. OK, the term EOF was misleading, but I would already be pleased, if the script would stop processing. I don't want to trick Avisynth into thinking there are suddenly less frames than before ;)

I think the best you can do is to optimize your script so that if you've met your how muchiwant requirement, it doesn't process (or does minimal processing of) any additional frames.
The first part is a good suggestion. I already edited the script above to run faster. Now about the "make it so that it doesn't process the additional frames", that's exactly what I'm looking for. I just don't know how to make Avisynth stop, once the limit is reached.
I tried it with a second ConditionalFilter-line which would only evaluate and output Blankclips when the limit is reached, but in my tests avisynth never processed more than one of the two conditionalfilter-commands.

Or maybe you could Assert(false) to try to abort, since by then all of your results should have been written to disk already, but I'm not certain that will work.
I don't really know how Assert should help here. Doesn't it simply show some textmessages to the user? The help on it in the Avisynth docs isn't that extensive, unfortunately.

No, AVISource decodes all requested frames. Filters can't distinguish keyframes from non-keyframes.
I'll ask differently then: Can AVISource recognize keyframes in the source? And if yes: is it possible to pass on those values?

stickboy
30th December 2004, 02:32
Originally posted by Schlumpf
Originally posted by stickboy:
Please use \s to break up lines so we don't have to do so much horizontal scrolling.Sorry, I just don't get how ;__;
Clip1 = Source.AssumeFPS(Source.framerate*8).Killaudio()
\ .ConvertToRGB24(interlaced=false)
\ .ImageWriter("c:\path\filename", 0, 0, "PNG")
\ .ConvertToYV12(interlaced=false)
\ .ReduceBy2().ReduceBy2().ReduceBy2().ReduceBy2()
I don't really know how Assert should help here. Doesn't it simply show some textmessages to the user? The help on it in the Avisynth docs isn't that extensive, unfortunately.Typically assertions are evaluated (like most other things) when the script loaded. If the Assert fails, then the script fails to load, and the application displays an error dialog.

I'm not sure how it would behave within FrameEvaluate, but you could try it...
I'll ask differently then: Can AVISource recognize keyframes in the source? And if yes: is it possible to pass on those values?I guess in theory it would be possible, but it doesn't.

Bidoche
30th December 2004, 03:15
AviSource can recognize keyframes, but 2.5 is not really able to pass the info.