View Full Version : AVSLib and ScriptClip
Pier
9th October 2013, 19:31
Hi, i got a speed issue using AVSLib's Arrays with ScriptClip, here some example:
-Only Decoding.
clip = last
Trim(clip,0,100)#590.6 fps
-A Simple and useless editing on two arrays.
clip = last
Trim(clip,0,100)
LoadPackage("avslib","array")
x = ArrayCreate("Ax","Bx","Cx")
y = ArrayCreate("Ay","By","Cy")
yxx = ArraySet(x,0,ArrayGet(y,0)).ArraySum()
xyx = ArraySet(x,1,ArrayGet(y,1)).ArraySum()
xyy = ArraySet(y,0,ArrayGet(x,0)).ArraySum()
Subtitle(String(xyx))#580.5 fps
-As above but with ScriptClip.
clip = last
Trim(clip,0,100)
LoadPackage("avslib","array")
ScriptClip("""
x = ArrayCreate("Ax","Bx","Cx")
y = ArrayCreate("Ay","By","Cy")
yxx = ArraySet(x,0,ArrayGet(y,0)).ArraySum()
xyx = ArraySet(x,1,ArrayGet(y,1)).ArraySum()
xyy = ArraySet(y,0,ArrayGet(x,0)).ArraySum()
Subtitle(String(xyy)) """)#2.633 fps
I understand that the same code will be repeated for each frame, and it will slower, and that in this case is just stupid, but it is to show how a so simple and fast code gets really slow with ScriptClip. I mean that it doesn't look logic to me, thus i'd like to know the reason why it is, and how to fix it if it possible. Also if you change the string with something like the prev,current,next frame, it will be the same, i will get the same frame as output but it will be much slower like above. :confused:
Gavino
9th October 2013, 21:08
I understand that the same code will be repeated for each frame, and it will slower, and that in this case is just stupid, but it is to show how a so simple and fast code gets really slow with ScriptClip. I mean that it doesn't look logic to me, thus i'd like to know the reason why it is, and how to fix it if it possible.
The comparison is misleading, since in the first example, the array manipulation is all done at compile-time and its per-frame cost is exactly zero - only the Subtitle() adds to the per-frame cost. I would expect the additional script load time for that example to be roughly equal to the per-frame cost of the ScriptClip() in the second example.
Also if you change the string with something like the prev,current,next frame, it will be the same, i will get the same frame as output but it will be much slower like above. :confused:
I don't understand what you mean here. Can you explain more?
Pier
10th October 2013, 03:40
I meant something like that:
Ar = ArrayCreate(DuplicateFrame(0),last,DeleteFrame(0))
# ArrayGet(Ar,0) // Previous-Frame
# ArrayGet(Ar,1) // Current-Frame
# ArrayGet(Ar,2) // Next-Frame
# Whatever_you_wish()
But it appens with any kind of array, it was to show that the problem was not related to the type of data stored in the array.
The comparison is misleading, since in the first example, the array manipulation is all done at compile-time and its per-frame cost is exactly zero - only the Subtitle() adds to the per-frame cost. I would expect the additional script load time for that example to be roughly equal to the per-frame cost of the ScriptClip() in the second example.
I see, so the array creation doesn't slow down the process, i didn't know that.
Anyway, using ScriptClip and Subtitle without an array:
clip = last
Trim(clip,0,100)
ScriptClip("""
Subtitle("xyy") """)#66.27 fps
Not sure what does it means, it is "normal" or i'm doing it wrong? There are like 64fps of difference, due to something that shouldn't slow down the process. :confused:
Gavino
10th October 2013, 09:42
OK, I now undertand your earlier question:
Also if you change the string with something like the prev,current,next frame, it will be the same, i will get the same frame as output but it will be much slower like above. :confused:
The array operations (inside ScriptClip) are executed for every frame, slowing down frame serving, but do not deliver any frames themselves, so you still get the same frame output.
I see, so the array creation doesn't slow down the process, i didn't know that.
It doesn't slow down the frame serving (http://avisynth.nl/index.php/The_script_execution_model) part of the process, but it slows down the compile-time part (script loading).
Anyway, using ScriptClip and Subtitle without an array:
clip = last
Trim(clip,0,100)
ScriptClip("""
Subtitle("xyy") """)#66.27 fps
Not sure what does it means, it is "normal" or i'm doing it wrong? There are like 64fps of difference, due to something that shouldn't slow down the process. :confused:
Using a filter inside ScriptClip() is always slower than outside, because the filter initialisation is done for every frame instead of just once. In the case of Subtitle(), the difference is dramatic, because Subtitle() does the (relatively slow) rendering of the text to a bitmap during this initialisation.
Pier
10th October 2013, 17:16
I'm starting to understand the situation, but the array part (the reason why i get 2 fps) is still unclear to me, here a more simple example:
-An empty ScriptClip call.
clip = last
Trim(clip,0,100)
ScriptClip("""
last """)#594.1
-An empty ScriptClip call with an unused array.
clip = last
Trim(clip,0,100)
LoadPackage("avslib","array")
ScriptClip("""
Ar = ArrayCreate("Something")
last """)#30.1
1-Even if the array is not requested by the output it is still rendered becouse ScriptClip needs to evaluate all the filters above to get the filter graph.
2-The array itself is a slow process and outside ScriptClip it is rendered only once, when the script is loaded, this makes it look "fast".
3-Inside ScriptClip instead, it is loaded for each frame, and it slows down a lot the process since the creation of an array is a slow process.
Am I (more or less) correct?
Gavino
10th October 2013, 18:03
Am I (more or less) correct?
Yes, that's exactly right.
Pier
10th October 2013, 18:10
Thanks for the help :D
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.