Log in

View Full Version : FrameEvaluate on reduced, ScriptClip on original


shindigo
26th February 2007, 05:21
Hi -

I've been working on scripts that analyze frames. In most case I want to write information about frames that have certain properties to a text file and show the number of frames found so far with those properties as a subtitle on the source video.

The form of these scripts is like this test script:
# FrameEvalTest
c = BlankClip(length=19, color=color_white, pixel_type="YV12")
b = BlankClip(length=1, color=color_black, pixel_type="YV12")
c = c + b + c + b + c + b
global writeFrame = false
global numBlack = 0
global c2 = c.ReduceBy2.Greyscale
c2 = c2.ScriptClip("subtitle(string(numBlack), align=3)") # this shows how many so far.
c2 = c2.WriteFileIf("FrameEvalTest.txt", "(writeFrame)", "numBlack = numBlack + 1", "current_frame") # this does the counting and logging.
c2 = c2.FrameEvaluate("writeFrame = (AverageLuma <= 16.5)") # this will be some long calculation and condition.
return c2

This works fine (it counts the number of black frames in the video)

But, I have been trying to figure out how to do the calculations on the reduced video, but have the ScriptClip subtitle show on the original video.

I have tried replacing c2 = c2.ScriptClip(... with c = c.ScriptClip(... and returning c, but it never increments the numBlack counter.

Also, why does it never count the final black frame?

TIA

sh-

foxyshadis
26th February 2007, 07:45
I'm too tired to think about why it isn't counting the last frame, but the scriptclip problem is easy: Just use c2.scriptclip(""" c.subtitle(...) """), then make sure c is global, so at least the last assignment must have a global prefix.

I always triple-quote anything that can contain strings out of habit; not required but helpful.

shindigo
26th February 2007, 15:27
Thanks for the quick answer. Makes sense to me. I will give it a try tonight.

sh-

shindigo
27th February 2007, 03:55
ok -

So with your advice I have:

# FrameEvalTest
c = BlankClip(length=19, color=color_white, pixel_type="YV12")
b = BlankClip(length=1, color=color_black, pixel_type="YV12")
global c = c + b + c + b + c + b
global writeFrame = false
global numBlack = 0
global c2 = c.ReduceBy2.Greyscale
c2 = c2.ScriptClip(""" c.subtitle(string(numBlack), align=3) """) # this shows how many so far.
c2 = c2.WriteFileIf("FrameEvalTest.txt", "(writeFrame)", "numBlack = numBlack + 1", "current_frame") # this does the counting and logging.
c2 = c2.FrameEvaluate("writeFrame = (AverageLuma <= 16.5)") # this will be some long calculation and condition.
return c

but its still not working. I get the original video, but with no subtitle at all.

I have also tried c2 = c2.ScriptClip(""" c = c.subtitle(string(numBlack), align=3) """), also c2.ScriptClip(""" c.subtitle(string(numBlack), align=3) """) and a couple of other possibilities, but still no good.

Any ideas?

foxyshadis
27th February 2007, 05:19
With a return c on the end, that's no surprise; the original worked because it returned c2. =p