Log in

View Full Version : About function declaring....


Kaiousama
8th December 2003, 20:26
I've written this simple script that shows on top left screen margin " Frame : X" where X is actual frame number:


blankclip(600,640,480,"YV12",24,1)

subtitle("Frame",10,20,0,FrameCount, text_color=$FFFFFF)
ScriptClip("subtitle(string(current_frame),70,20,0,FrameCount, text_color=$FFFFFF)")


The script works well, now i like to make it a function:


MyClip=blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
subtitle(VIDEOCLIP,"Frame",10,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)
ScriptClip(VIDEOCLIP,"subtitle(VIDEOCLIP,string(current_frame),70,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)


but loading it in VirtualDub i see only the error "I don't know what"VIDEOCLIP" means ([ScriptClip], line 1)" painted on video.
Where have i done wrong? can anyone show me how my function should be declared?

Thanks.

tempetai
9th December 2003, 10:25
Just a guess,

I think you have to set your VIDEOCLIP to global. You may need a return statement as well at the end of your share function. Try this

code:--------------------------------------------------------------------------------
MyClip=blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
global vidclip = VIDEOCLIP
vidclip = subtitle(vidclip,"Frame",10,20,0,FrameCount(vidclip), text_color=$FFFFFF)
vidclip = ScriptClip(vidclip,"subtitle(vidclip,string(current_frame),70,20,0,FrameCount(vidclip), text_color=$FFFFFF)")
return vidclip
}

ShowFramesOnVideo(MyClip)
--------------------------------------------------------------------------------

Wilbert
9th December 2003, 10:33
blankclip(600,640,480,"YV12",24,1)

ScriptClip("subtitle(string(current_frame),70,20,0,FrameCount, text_color=$FFFFFF)")


Should be enough.

I'm not sure why it doesn't work. Does the following work:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{

ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)

Kaiousama
9th December 2003, 20:44
@Tempetai:

MyClip=blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
global vidclip = VIDEOCLIP
vidclip = subtitle(vidclip,"Frame",10,20,0,FrameCount(vidclip), text_color=$FFFFFF)
vidclip = ScriptClip(vidclip,"subtitle(vidclip,string(current_frame),70,20,0,FrameCount(vidclip), text_color=$FFFFFF)")
return vidclip
}

ShowFramesOnVideo(MyClip)


The error is no longer present but another strange fact is appearing, in the output video you can only see the frame counter, and the word "Frame :" specified by the subtitle line is totally absent (try yourself to load the script into vdub), i've noticed that the same effect comes up if i invert the order of Subtitle and Scriptclip lines in my function declaration example..... mistery O_o

@Wilbert:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{

ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)



It reports exactly the same error : "I don't know what VIDEOCLIP means ([ScriptClip],line 1)"
So i assume something is wrong in scriptclip declaration, but i can't find what it is :(

Maybe there is some bug in ScriptClip function in using it inside another function declaration, or maybe an incompatibility between ScriptClip and some Subtitle parameters i've used like FrameCount(VIDEOCLIP).....
Any idea to discuss is welcome ^_^''

sh0dan
9th December 2003, 20:49
Should be:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20,0,FrameCount(last), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)

Remember - VIDEOCLIP is given to scriptclip as implicit last parameter. This function will also work on multiple clips in contrast to the script further above. The last parameters on subtitle isn't really needed AFAICT, as they are default.

Simple version is:

ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20, text_color=$FFFFFF)")

Kaiousama
9th December 2003, 22:16
Thanks shodan, one half of the matter is solved, the other half could be summarized in this way:

Why such a clip resuls in a "Avisynth open failure: Script Error: expected a , or ) line 5 column 37" error?


MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle("Frame " + string(current_frame),70,20,0,FrameCount(last), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)


I've simply tried to specify the displayed subtitle as an addition of two strings (note that the same command outside the function declaration works properly).

This was what happens if i want to add the "Frame X" visualization all by one function's line, but if i simply use your line and add an additive line to show even the "Frame " subtitle string on video:


MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20,0,FrameCount(last), text_color=$FFFFFF)")
Subtitle(VIDEOCLIP,"Frame",10,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)
}

ShowFramesOnVideo(MyClip)


In the result clip only "Frame " is written on video and the frame counter is disappeared.
If i invert the ScripClip and Subtitle line order i can only see the Frame counter without the "Frame " subtitle.
It's like if when avisynth apply the ScriptClip command, it cleans up the video from the previous Subtitle and vice-versa.

I'm a bit confused.... ?_?

mf
9th December 2003, 22:31
Originally posted by Kaiousama

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle(string(current_frame),70,20,0,FrameCount(last), text_color=$FFFFFF)")
Subtitle(VIDEOCLIP,"Frame",10,20,0,FrameCount(VIDEOCLIP), text_color=$FFFFFF)
}

ShowFramesOnVideo(MyClip)

In the result clip only "Frame " is written on video and the frame counter is disappeared.
If i invert the ScripClip and Subtitle line order i can only see the Frame counter without the "Frame " subtitle.
It's like if when avisynth apply the ScriptClip command, it cleans up the video from the previous Subtitle and vice-versa.

I'm a bit confused.... ?_?
Afaik, should be:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle("Frame: "+string(current_frame),10,20,0,FrameCount(last), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)

Kaiousama
9th December 2003, 22:37
@mf: Try to load your script into virtualdub and you'll also get the "Avisynth open failure: Script Error: expected a , or ) line 5 column 37" error. That's a bit strange because i also believe the function is well declared.

mf
9th December 2003, 23:16
Originally posted by Kaiousama
@mf: Try to load your script into virtualdub and you'll also get the "Avisynth open failure: Script Error: expected a , or ) line 5 column 37" error. That's a bit strange because i also believe the function is well declared.
Oh right, totally forgot. This should work:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle("+Chr(34)+"Frame: "+Chr(34)+"+string(current_frame),10,20,0,FrameCount(last), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)

Kaiousama
9th December 2003, 23:39
@mf: Wondeful!! it works :D *happy*

i have only the last matter to solve, how can i write a second line on video?

for example this script should write the same "Frame: X" on two lines:

MyClip = blankclip(600,640,480,"YV12",24,1)

function ShowFramesOnVideo(clip VIDEOCLIP)
{
ScriptClip(VIDEOCLIP,"subtitle("+Chr(34)+"Frame: "+Chr(34)+"+string(current_frame),10,20,0,FrameCount(last), text_color=$FFFFFF)")
ScriptClip(VIDEOCLIP,"subtitle("+Chr(34)+"Frame: "+Chr(34)+"+string(current_frame),10,50,0,FrameCount(last), text_color=$FFFFFF)")
}

ShowFramesOnVideo(MyClip)


From virtualdub I can only see the second line and not the first, do you know a way to make avisynth display both the lines?

Thanks.