View Single Post
Old 17th June 2008, 16:57   #4  |  Link
gzarkadas
Registered User
 
gzarkadas's Avatar
 
Join Date: Sep 2005
Location: 100011110010001000001 10000011111111000001
Posts: 221
I made some modifications to my script to simulate your proposed solution of setting current_frame at the end of runtime filters, by backing up its value in a chained FrameEvaluate and restoring at the end of each script block:
Code:
# 100 frames black + 100 white, to give predictable luma
BlankClip(100, pixel_type="YV12")+BlankClip(100, pixel_type="YV12", color=color_white)
ScriptClip("""
  SubTitle(String(current_frame), y=10)
  current_frame = backup2
  SubTitle(String(current_frame), y=10, x=320)
""")
FrameEvaluate("backup2 = current_frame")
Trim(50, 149)
ScriptClip("""
  f1 = current_frame
  a1 = AverageLuma() # OK
  f2 = current_frame
  a2 = AverageLuma() # gives wrong value
  f3 = current_frame
  SubTitle("a1="+string(a1)+" a2="+string(a2), y=30) # shows a1 != a2
  SubTitle(String(f1)+","+String(f2)+","+String(f3), y=50)
  current_frame = backup1
  SubTitle(String(f1), y=70)
  SubTitle(String(current_frame), y=70, x=320)
""")
FrameEvaluate("backup1 = current_frame")
However, this does not work; the output is exactly (disregarding the added text) the same as the non-corrected script's.

In order to correct the output, the backup/restore of current_frame has to be done inline the second script, as I suggested at my previous post:
Code:
# 100 frames black + 100 white, to give predictable luma
BlankClip(100, pixel_type="YV12")+BlankClip(100, pixel_type="YV12", color=color_white)
ScriptClip("""
  SubTitle(String(current_frame), y=10)
  current_frame = backup2
  SubTitle(String(current_frame), y=10, x=320)
""")
FrameEvaluate("backup2 = current_frame")
Trim(50, 149)
ScriptClip("""
  f1 = current_frame
  a1 = AverageLuma() # OK
  current_frame = f1
  a2 = AverageLuma() # OK
  current_frame = f1
  SubTitle("a1="+string(a1)+" a2="+string(a2), y=30) # OK
  current_frame = backup1
  SubTitle(String(f1), y=50)
  SubTitle(String(current_frame), y=50, x=320)
""")
FrameEvaluate("backup1 = current_frame")
The reason is that the entire script's evaluation inside runtime filters is just a line of code (here from ScriptClip's GetFrame):
Code:
    ScriptParser parser(env, script.AsString(), "[ScriptClip]");
    PExpression exp = parser.Parse();
    result = exp->Evaluate(env);
thus the runtime filter does not have the chance to properly restore the value of current_frame (which happens inside the Evaluate call), unless a hook is placed either at the parser or at the Evaluate method to analyse the chain and recognise that a situation such the one that we talk about occures and apply logic to overcome it. This solution is costly in terms of performance; the price would have to be paid at every frame.
__________________
AVSLib, a free extension library for Avisynth. Current version: 1.1.0 (beta), 14/05/2007.
[ Home page | Download page ]
gzarkadas is offline   Reply With Quote