Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th October 2013, 19:31   #1  |  Link
Pier
Registered User
 
Join Date: Jul 2013
Posts: 26
AVSLib and ScriptClip

Hi, i got a speed issue using AVSLib's Arrays with ScriptClip, here some example:

-Only Decoding.
Quote:
clip = last
Trim(clip,0,100)#590.6 fps
-A Simple and useless editing on two arrays.
Quote:
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.
Quote:
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.
Pier is offline   Reply With Quote
Old 9th October 2013, 21:08   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by Pier View Post
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.

Quote:
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.
I don't understand what you mean here. Can you explain more?
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th October 2013, 03:40   #3  |  Link
Pier
Registered User
 
Join Date: Jul 2013
Posts: 26
I meant something like that:
Quote:
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.
Quote:
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:
Quote:
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.
Pier is offline   Reply With Quote
Old 10th October 2013, 09:42   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
OK, I now undertand your earlier question:
Quote:
Originally Posted by Pier View Post
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.
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.

Quote:
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 part of the process, but it slows down the compile-time part (script loading).

Quote:
Anyway, using ScriptClip and Subtitle without an array:
Code:
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.
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th October 2013, 17:16   #5  |  Link
Pier
Registered User
 
Join Date: Jul 2013
Posts: 26
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.
Quote:
clip = last
Trim(clip,0,100)
ScriptClip("""
last """)#594.1
-An empty ScriptClip call with an unused array.
Quote:
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?
Pier is offline   Reply With Quote
Old 10th October 2013, 18:03   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by Pier View Post
Am I (more or less) correct?
Yes, that's exactly right.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th October 2013, 18:10   #7  |  Link
Pier
Registered User
 
Join Date: Jul 2013
Posts: 26
Thanks for the help
Pier is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.