Log in

View Full Version : Script help needed to label video frames sequentially every 3 frames


Melvina
20th June 2012, 11:29
Hello,

Hopefully someone may be able to help me out here?

I need a script that will label video frames sequentially every 3 frames.

At the moment I have a method for what I need to do where I take in a video file, and I have to select every third frame. In my video files only 1 out of each 3 will be any good, so currently I use the following bit of script and have to check out all 3 by trial and error:

Selectevery (3,0)
#selectevery (3,1)
#Selectevery (3,2)

What I'm hoping to work out how to do is to get an avisynth script to stamp the number 0, 1 or 2 onto each frame so that I can examine the whole file in one go, decide which of the 3 is good, and then select the relevant selectevery line as above without having to try all 3 all the time.

I tried messing around with modulo functions, but my script writing is pretty rudimentary, and I suspect there is probably a blindingly obvious way of doing this that I don't know about!

Thanks!

Gavino
20th June 2012, 12:21
ScriptClip("Subtitle(string(current_frame % 3))")

IanB
20th June 2012, 23:40
ScriptClip compiles a new Subtitle filter chain every frame. The Subtitle filter is particularly slow to initialise. The ShowFrameNumber and like text tagging variant suffers quite badly from this delay in setting up per frame variable text.

A significantly faster, but clumsier implementation. This is an all compile once at the script start solution :-...Source...
A=SelectEvery(3, 0).Subtitle("0")
B=SelectEvery(3, 1).Subtitle("1")
C=SelectEvery(3, 2).Subtitle("2")
Interleave(A, B, C)
...

Another alternative based on the "only compile the decision not the function" philosophy :-...Source...
T0=Subtitle("0")
T1=Subtitle("1")
T2=Subtitle("2")
ConditionalSelect (http://avisynth.org/mediawiki/ConditionalSelect)(current_frame % 3, T0,T1,T2)
...ConditionalSelect (http://avisynth.org/mediawiki/ConditionalSelect) is a new feature currently only available in CVS.

The above 2 solutions will be roughly the same speed. The selection criteria here, (current_frame % 3), is quite trivial, but other scripting needs may be a lot more expressive perhaps involving runtime functions like AverageLuma() and friends that may see a significant advantage.

Melvina
22nd June 2012, 05:47
Excellent!

Thanks both, I'll have a play around with those, seems to be exactly the sort of thing I need.