Write

writing to a file at script runtime

for AviSynth 2.5x

Write (clip, string "filename", string "expression1", ... , string "expression10", bool "linecheck", bool "flush", bool "append", bool "nofail")

Write evaluates "expressionN", converts it to a string and puts the result into a file.

The "run-time" variable "current_frame" is set so that you can use it in an "expression"
(this works similar as with ScriptClip, look there in the docu for more infos).

This is best explained with some simple examples:

LoadPlugin("c:\myprojects\dvinfo\release\CHR.dll")

filename = "c:\myprojects\output.txt"

Version() # create a test video to get frames
Write(filename, "current_frame") # the expression here is only a variable, which is evaluated and put in the file # you will get a file with the framenumber in each line

At the time the script is loaded, the expressions are evaluated, too with current_frame = -1.
This can be used for writing a header, as we will see later.

With "flush=true" (default) the file will be closed after each frame (you can open the file and see the results), with "flush=false" it will be closed only when the script is closed (which may be a little faster).

With "append=false" (default) each time you start the script the file will be deleted first.

"nofail=true" (default) will print the expression itself, if it can't be evaluated, "nofail=false" will print the error message.

Write(filename, "this is nonsense")

with nofail=true will result in:         this is nonsense

and with nofail=false in:                I don't know what "this" means


There are easier ways to write numbers in a file, BUT:

...with this example you can see how to use the "runtime functions" together with FrameEvaluate:

Version.FadeIn(50).ConvertToYV12       # create a test video to get different frames

Write(filename, "current_frame", ":", "AverageLuma") # this will print the frame number, a ":" and the average luma for that frame

Or maybe you want the actual time printed, too:

Version.FadeIn(50).ConvertToYV12       # create a test video to get different frames


# this will print the frame number, the current time and the average luma for that frame
# the chr(34) is necessary as there is no way to put quotes inside a string
Write(last, filename, "current_frame", "time(" + chr(34) + " %H:%M:%S " + chr(34) + ")", "AverageLuma")

Attention::

The clip that is used by AverageLuma must be the end of the filter chain for that clip.
Use a intermediate variable if you process the clip farther:

This will crash:

Version.FadeIn(50).ConvertToYV12 Write(last, filename, "AverageLuma") Subtitle("TEST")
This is OK:

Version.FadeIn(50).ConvertToYV12 tmp=last Write(last, filename, "AverageLuma(tmp)") Subtitle("TEST")


More examples:

If you set linecheck=true the FIRST expression is expected to be boolean (true or false).
Only if it is TRUE the other expressions are evaluated and the line is printed.
(Remember: && is AND, || is OR, == is EQUAL, != is NOT EQUAL)
That way you can ommit lines completely from your file.

Version.FadeIn(50).ConvertToYV12       # create a test video to get different frames

# this will print the frame number, but only of frames where AverageLuma is between 30 and 60 Write(last, filename, "(AverageLuma>30) && (AverageLuma<60)", "current_frame", ":", "AverageLuma")


String

conversion with number formatting

for AviSynth 2.5x

String (variable, format_string)

Does the same as the standard String, but 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

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


Ernst Peché, 2003-09-20