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. |
14th March 2011, 16:46 | #1 | Link |
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) 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. |
14th March 2011, 17:03 | #2 | Link |
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) 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. |
20th March 2011, 16:23 | #3 | Link |
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?
|
20th March 2011, 18:46 | #4 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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. |
20th March 2011, 20:36 | #5 | Link |
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. |
20th March 2011, 20:44 | #6 | Link |
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 ) Last edited by -Vit-; 20th March 2011 at 20:50. Reason: tweak |
20th March 2011, 21:19 | #7 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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) |
21st March 2011, 10:36 | #9 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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).
|
21st March 2011, 18:12 | #10 | Link |
Registered User
Join Date: Jul 2010
Posts: 448
|
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.
|
21st March 2011, 19:44 | #11 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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. |
23rd March 2011, 18:24 | #12 | Link |
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! |
25th March 2011, 05:06 | #13 | Link |
interlace this!
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 |
25th March 2011, 12:15 | #14 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,437
|
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. |
Tags |
scriptclip, variable |
Thread Tools | Search this Thread |
Display Modes | |
|
|