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 14th March 2011, 16:46   #1  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
global variable within ScriptClip?

Hey,

In short, I'd like to store an information into a variable within the ScriptClip environment and query the variable at a (much) later point in the script.

A little longer explanation: in a video the first 10,000 frames are different (softer), so need different treatment. In the middle of the script, I do a Trim(), trimming down frames from both the beginning and end of the video, and after the Trim() command I have to apply a filter to the first segment (what remained from the originally 10,000 frames after trimming).

What I had in mind was this (rough example):

Code:
  ScriptClip("""
	arethesecredits=(current_frame<10000)?true:false
  """)
  ...
  Trim(2654,128609)
  ...
  <lots of scripting here>
  ...
  (arethesecredits == true ) ? Sharp(1.0) : Blur (0.25)
It turned out it doesn't work. Not even with putting the last line into another ScriptClip().

I know there are theoretical roundabouts to this, such as applying the filter before the trimming, or do everything within one ScriptClip() command, but in this case these wouldn't really work in the practice. Modifying the script to achieve this simple thing would make my life difficult as hell.

Does anyone know how to implement the original idea? It'd be very-very helpful to me.
zee944 is offline   Reply With Quote
Old 14th March 2011, 17:03   #2  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
Are you decimating or otherwise adding/removing frames after that trim? If not then this will do it:
Code:
Credits=10000

<process, process>

TrimStart=2654
Trim(TrimStart,128609)

result = <more processing>

TrimCredits=Credits-TrimStart
result.Trim(0,TrimCredits-1).Sharp(1.0) + result.Trim(TrimCredits,0).Blur (0.25)
Or you can use ApplyRange for a similar result.
Obviously you don't have to use variables (TrimStart etc.) you can just put the actual values. I find it easier to tweak in a single place
You would need to alter the trims on the result if that latter processing changed the number of frames in any way.

Last edited by -Vit-; 14th March 2011 at 17:07.
-Vit- is offline   Reply With Quote
Old 20th March 2011, 16:23   #3  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
Thanks, it would work indeed, but it's still a roundabout. The Trim() lines are generated by an external software (pls don't ask me to go into the details, it's way too complicated why it's like this), I can't use a variable in it. I have to achieve my orginal idea, else everything will go upside down. No way?
zee944 is offline   Reply With Quote
Old 20th March 2011, 18:46   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Which parts of the script are generated by the external program?
Can't you edit its output to produce the final script along the lines of -Vit-'s solution?
Or write another program to process the results of the first, if you want an automated solution.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th March 2011, 20:36   #5  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
I could certainly modify the script to use variables, but there are hundreds of scripts that partly generated by the program. I wrote the program, but I wanted to avoid modifying it because the whole process is very complicated already and the current program is tested hundreds of times, modifying it is quite risky.

I take it that it's just not possible what I want.
zee944 is offline   Reply With Quote
Old 20th March 2011, 20:44   #6  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
I think it's possible, just ugly. I have no way to test at the moment, so this is just a concept. Embed the conditional data into the clip itself:
Code:
src = WhateverSource("...")

credits=10000
selector = BlankClip(src,color=$000000,length=credits) + BlankClip(src,color=$ffffff,length=FrameCount(src)-credits)

result1 = <process, process>

h=Height()
StackVertical( result1, selector )

Trim(2654,128609) # Machine generated

selector = Crop(0,h,0,0)
Crop(0,0,0,-h)

result2 = <more processing>

mt_merge( result2.Sharp(1.0), result2.Blur(0.25), selector, U=3,V=3 )
I'm sure it could be made more efficient.

Last edited by -Vit-; 20th March 2011 at 20:50. Reason: tweak
-Vit- is offline   Reply With Quote
Old 20th March 2011, 21:19   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
One possibility based on your original idea would be to do this:
Code:
FrameEvaluate("arethesecredits=(current_frame<10000)")
...
Trim(2654,128609)
...
<lots of scripting here>
...
ScriptClip("arethesecredits ? Sharp(1.0) : Blur (0.25)", after_frame=true)
-Vit-'s solution is neat, but would have to be amended if any of the processing changes the clip width or does any kind of frame decimation.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 21st March 2011, 02:48   #8  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
That looks much better than my effort, although I imagine it would need sequential access or any caching will throw it off..?
-Vit- is offline   Reply With Quote
Old 21st March 2011, 10:36   #9  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by -Vit- View Post
I imagine it would need sequential access or any caching will throw it off..?
It doesn't have to be sequential, but it does require that each output frame is derived from exactly one input frame, and no frame is repeated. So frames could be re-ordered, but any temporal filtering could throw it off (at least around the boundary between credits and the rest).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 21st March 2011, 18:12   #10  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
Quote:
Originally Posted by Gavino View Post
... and no frame is repeated..
Which is the situation I meant to describe. If you view that script as-is in Vdub and navigate the timeline around the sharp/blur transition, then it becomes confused about which frames are blurred/sharp. I imagine it's because the caching (of the Trim) means the FrameEvaluate is skipped. No problem for straight encoding though.
-Vit- is offline   Reply With Quote
Old 21st March 2011, 19:44   #11  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
That's right.
By "sequential access", I thought you were referring to the processing in the script, rather than manually jumping around on the timeline, but of course they both have the same effect as far as Avisynth is concerned.

Note that here you can jump around freely as long as you never jump backwards across the transition point.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 23rd March 2011, 18:24   #12  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
I went with Gavino's solution. Although there is temporal filtering in the script, it works fine on the test encode.

It's a big relief I don't have to modify the external software... huhh. Thank you very much for both solutions!
zee944 is offline   Reply With Quote
Old 25th March 2011, 05:06   #13  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
you can have globals in the scriptclip environment.

you have to initialise them first in the main script.

so:

global foo=0

scriptclip(""" blankclip().subtitle(string(foo))""")

should work.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 25th March 2011, 12:15   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
The question wasn't really about global variables, more about how to communicate per-frame information from one part of the filter graph to another. As you can see, neither of the solutions posted by -Vit- or me involved using a global.

In your example, foo does not need to be global either, as run-time scripts (eg within ScriptClip) are evaluated at the same scope level as the main script.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Reply

Tags
scriptclip, variable

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 00:34.


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