View Full Version : Import script command not working?
hazel-ra
9th January 2008, 21:14
Hello all -
I'm new to avisynth. I'm working on a long project, and I broke it up into several scripts.
My plan was to create a master script, one that called all the other scripts in the proper order. However, the Import() command only seems to play the very last script called!
What am I doing wrong? Is this a syntax problem, or am I going about this the wrong way?
The sub-scripts I have are fairly simple I think; they just trim a bunch of clips and mix them together at the end, like this:
AVISource( "clip1source.avi).BilinearResize( horiz, vert ).AssumeFPS("ntsc_film", true).ResampleAudio( 48000 )
clip1 = Trim( 4162, 4245)
AVISource( "clip2source.avi).BilinearResize( horiz, vert ).AssumeFPS("ntsc_film", true).ResampleAudio( 48000 )
clip2 = Trim( 500, 550 )
clip1 + clip2
foxyshadis
9th January 2008, 21:59
Post your master script and a couple of specific examples of the subscripts, just to check whether the syntax is okay.
IanB
9th January 2008, 22:00
:script:s (plural) and exact error text. Press Control-C in the error message box to copy the text.
Import is a direct textual inclusion in the main script. If you paste the text of the subscript in place of the Import that is what you get as a total script.
hazel-ra
9th January 2008, 23:03
OK, there's no error per se ( and thus no error text ), just unexpected behavior.
Here's two example scripts:
script1.avs:
path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
AVISource( path + "60s_Perversion_For_Profit.avi") .BilinearResize( horiz, vert ).AssumeFPS(23.976)
clip1 = trim(5180, 6177)
clip2 = trim( 6178, 6840 )
## mix ##
clip1 + clip2
script2.avs:
path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
AVISource( path + "How_Much_Affection.avi") .BilinearResize( horiz, vert ).AssumeFPS(23.976)
clip1 = trim(5180, 6177)
clip2 = trim( 6178, 6840 )
## mix ##
clip1 + clip2
Both do what I expect when I run them.
Now, I would like to run them both, one after the other, but keeping each script in a separate file. ( This is so I can edit my scripts individually, without creating on gigantic script for my entire project. )
master.avs:
Import( "C:\Documents and Settings\user\Desktop\script1.avs")
Import( "C:\Documents and Settings\user\Desktop\script2.avs")
When I run master.avs, I see only the video from script2.avs. I expect to see script1.avs, and then script2.avs, but obviously I'm misunderstanding something.
hazel-ra
9th January 2008, 23:07
Hey all --
I tried renaming the clips in script2.avs, incase there was a naming collision with the clips from the first script:
path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
AVISource( path + "How_Much_Affection.avi") .BilinearResize( horiz, vert ).AssumeFPS(23.976)
clip3 = trim(5180, 6177)
clip4 = trim( 6178, 6840 )
## mix ##
clip3 + clip4
But no luck. I wouldn't think than name collisions would be a problem anyway, since I'm mixing clip1 + clip2 in the first script, before I'm assigning new clips to those names in the second script.
mitsubishi
9th January 2008, 23:13
Try it like this:
Import( "C:\Documents and Settings\user\Desktop\script1.avs") + Import( "C:\Documents and Settings\user\Desktop\script2.avs")
or like this
a=Import( "C:\Documents and Settings\user\Desktop\script1.avs")
b=Import( "C:\Documents and Settings\user\Desktop\script2.avs")
a+b
hazel-ra
9th January 2008, 23:44
That's it! Thanks.
Didée
9th January 2008, 23:45
@ mitsubishi - that way, you'll get syntax error. Assignments like variable = import( [lengthy multiline script] ) can't work. It would require to enclose the entity of each subscript with Eval( """[...whole subscript here...]""" ).
@ hazel-ra: you stumbled over Avisynth's concept of "implicit last". That's a common pitfall.
What happens in your setup is that each subscript assigns its result simply to the system variable "last". This means that when scriptX is putting its result into "last", it thereby is overwriting what previously has been put into "last". That's why you only get the results from the last subscript.
One of the quickest ways to modify your scripts to do what you want is this:
1) Leave the very first subscript as it is.
2) Modify all other subscripts like this:
- add previous = last as first line into all subscripts (except the 1st one)
- change the last line of all subscripts (except the 1st one) to previous ++ clip1 ++ clip2
Edit:
Darn, mitsubishi's suggestion DOES work. Seems Avisynth internally is calling Eval() on imports ... I was always using the simple picture of "Import()ing a script is the same as copy-pasting its content at that position".
You learn every day. :D
mitsubishi
10th January 2008, 00:08
I thought:
a=import("foo.avs")
was equivalent to
import("foo.avs")
a=last
Because even the variables still get propagated
eg
foo.avs
a=AVISource("foo.avi")
b=a.FlipVertical()
a
bar.avs
c=import("foo.avs")
c+b
Works just fine.
mitsubishi
10th January 2008, 00:35
Oh, it is eval then, it's in the docs:
Import(filename): evals contents of another AviSynth script (imports the text of another script)
I guess that's why even this works:
bar.avs
import("foo.avs")+b
IanB
10th January 2008, 01:04
@hazel-ra,
If you expand your 3 scripts out, you can see where your 1 part output went, you just discarded it. All of mitsubishi's suggestions correct the issue.path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
AVISource( path + "60s_Perversion_For_Profit.avi") .BilinearResize( horiz, vert ).AssumeFPS(23.976)
clip1 = trim(5180, 6177)
clip2 = trim( 6178, 6840 )
## mix ##
clip1 + clip2 # This result is discarded!!!
path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
AVISource( path + "How_Much_Affection.avi") .BilinearResize( horiz, vert ).AssumeFPS(23.976)
clip1 = trim(5180, 6177)
clip2 = trim( 6178, 6840 )
## mix ##
clip1 + clip2 # This is the final result of the script
You need to ultimatly form this sort of concept.Import( "C:\Documents and Settings\user\Desktop\script1.avs")
A=Last # Save 1st part result
Import( "C:\Documents and Settings\user\Desktop\script2.avs")
B=Last # Save 2nd part result
...
A ++ B ++ ... # Assemble all parts
And of course mitsubishi's suggestion is probably the cleanest implementationa=Import( "C:\Documents and Settings\user\Desktop\script1.avs")
b=Import( "C:\Documents and Settings\user\Desktop\script2.avs")
a+b
stickboy
10th January 2008, 20:38
@hazel-ra,
And of course mitsubishi's suggestion is probably the cleanest implementationa=Import( "C:\Documents and Settings\user\Desktop\script1.avs")
b=Import( "C:\Documents and Settings\user\Desktop\script2.avs")
a+bIn principle:
a = AVISource("C:\Documents and Settings\user\Desktop\script1.avs")
b = AVISource("C:\Documents and Settings\user\Desktop\script2.avs")
a + bis the proper way to do it since it avoids name collisions.
hazel-ra
10th January 2008, 20:58
Hey all --
Thanks for the informational replies.
Here's what tripped me up:
"Import(filename): evals contents of another AviSynth script (imports the text of another script)"
From the included Avisynth 2.57 documentation .
I missed the word 'eval' and read "imports the text of another script" . I took that to mean that the literal text of the imported script existed right where the import statement was, like a PHP include.
Perhaps others might fall into the same trap :rolleyes:
IanB
11th January 2008, 00:50
@Stickboy,
Yes it has some distinct advantages but it is worth noting, your suggestion gets 3 full Avisynth environments, complete with caches, var stacks, strings spaces, etc plus 2 extra VFW environments.
@hazel-ra,
"eval" has nothing to do with your problem. Yes it is a text replacement like in PHP import or a C #include.
Once the text in included it of course is "eval"ed or compiled if you like, then if an assignment is require the current value of "Last" is used.
"Last" is the other piece of the puzzle.
If an outer script does not end with a Return statement, then a "Return Last" is assumed.
A script likeAviSource("xxx.avi")
Trim(100, 200)is implicitlyLast=AviSource("xxx.avi")
Last=Trim(Last, 100, 200)
Return Last
You script was compiled as if it were this :-...
Last=clip1 + clip2 # This result is discarded!!!
path = "E:\Movies\historical\"
horiz = 720
vert = 300
### Clips ###
Last=AVISource( path + "How ...The assignment to Last from AviSource replaces the earlier assignment from Clip1+Clip2
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.