PDA

View Full Version : How do I convert current_frame??


drgonzo62
10th October 2006, 20:06
Man, I'm about to give up on this..

I can't figure out how to convert current_frame from
"1" to something like "0001".

My script loads a padded image sequence and I'd like to write some
output to a text file with the current frame number being padded
by leading zeros just like the input file.
I.E.: If the input frame was "0001.png" I'd like to write that instead
of just "1", which is what my WriteFileIF() is giving me so far.

dirPath="D:\Dirt\Movie 2\"
filePrefix="Clip_1_"
fileExtension=".png"

imagesource(dirPath + filePrefix + "%04d" + fileExtension,0,24)

ConvertToYV12()

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", "Current_Frame")


How do add my padding to "current_frame"?


Any help is greatly appreciated.

Richard Berg
10th October 2006, 22:56
Completely untested, but should be close:

function pad(string num, int width)
{
return len(num) < width ? pad("0" + num, width) : num
}

current_size_padded = pad(string(current_size), 4)

Mug Funky
11th October 2006, 02:49
try:

string(current_frame,"%04.0f")

the formatting string handles the zero padding for you :)



String (float / int / string, format_string): converts a number to a string.

If the variable is float or integer, it converts it to a float and uses the format_string to convert it to a string.

The syntax of the format_string is as follows:

%[flags][width][.precision]f
width: the minimum width (the string is never truncated)
precision: the number of digits printed
flags:
- left align (instead right align)
+ always print the +/- sign
0 padding with leading zeros
' ' print a blank instead of a "+"
# always print the decimal point


e.g. Subtitle ("Clip height is " + String (last.height) )

String(1.23, "%f") = '1.23'
String(1.23, "%5.1f") = ' 1.2'
String(1.23, "%1.3f") = '1.230'

drgonzo62
11th October 2006, 16:38
try:

string(current_frame,"%04.0f")

the formatting string handles the zero padding for you :)
One would think so, but I had already tried that.

a=string(current_frame,"%04.0f")

for example returns the error:
"I don't know what "current_frame" means".

drgonzo62
11th October 2006, 16:42
Completely untested, but should be close:

function pad(string num, int width)
{
return len(num) < width ? pad("0" + num, width) : num
}

current_size_padded = pad(string(current_size), 4)
Where does current_frame come into this?

Did you mean
current_size_padded = pad(string(current_frame), 4) ?

In this case it's the same problem. The variable current_frame
can't be accessed this way. I tried..

Richard Berg
11th October 2006, 16:58
You're doing conditional filtering. Current_Frame is not a normal variable. Have you tried something like

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", "pad(string(Current_Frame), 4")

or

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame, "%04.0f")""")

?

drgonzo62
11th October 2006, 17:24
You're doing conditional filtering. Current_Frame is not a normal variable. Have you tried something like

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", "pad(string(Current_Frame), 4")

or

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame, "%04.0f")""")

?
Thanks Richard,

yes, I have tried. Same error "I don't know what current_frame means".
As far as I can tell, string() can't be used with current_frame.

This "variable" seems to be specific to only a few functions, like
WriteFileIF() and ScriptClip().

Is there no other way to get the current frame number?

drgonzo62
11th October 2006, 17:51
Well, who knew..? ;)

This works:
a="%04.0f"
WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", "string(Current_Frame,a)")

This doesn't:
WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", "string(Current_Frame,"%04.0f")")

Go figure.. :D

Richard Berg
11th October 2006, 18:59
Interesting!

drgonzo62
11th October 2006, 19:14
Interesting!
I thought so too.
The syntax shouldn't make a difference.

You can't beat the ol' trial & error approach.. :D

scharfis_brain
11th October 2006, 19:43
WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame,"%04.0f")""")

try this.

you need triple quotation marks in order to use quotation marks within quotation marks.

drgonzo62
11th October 2006, 20:52
WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame,"%04.0f")""")

try this.

you need triple quotation marks in order to use quotation marks within quotation marks.
Richard suggested this earlier. It won't work..
You try it! :D

Trotzdem, danke für die Antwort..

foxyshadis
11th October 2006, 23:49
Richard suggested it, but the code you copied into your post had only single quotes, so it wouldn't work. Triple-quoting works perfectly on mine.

drgonzo62
12th October 2006, 18:04
Richard suggested it, but the code you copied into your post had only single quotes, so it wouldn't work. Triple-quoting works perfectly on mine.
Sorry, I pasted the wrong line. But trust me, I tried triple quotes.

When I try:
WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame,"%04.0f")""")as the only line in a script it seems ok,
but when I put it together with the rest of my script, I'm getting
a syntax error:

http://www.kaysievert.com/cpg144/albums/userpics/10001/untitled.jpg

Strange, isn't it?

Here's the full script that will give me the error:
dirPath="D:\Dirt\Test\"
filePrefix="Clip_1_"
fileExtension=".png"

imagesource(dirPath + filePrefix + "%04d" + fileExtension,0,24)

ConvertToYV12()

WriteFileIF("MapFrameFile.txt", "IsCombed() ? True : False", """string(Current_Frame,"%04.0f")""")

foxyshadis
12th October 2006, 20:59
I bet this is a vdubmod bug, not an avisynth one. Does it work if you load it in the old fashioned way?