PDA

View Full Version : FileWriteEnd issue


tacman1123
10th July 2008, 13:46
I'm trying to use AviSynth to create a chapters list, and am experiencing very inconsistent behavior with FileWriteEnd. Perhaps there's a better way for me to be doing this.

chapter_string = ""
FR=25
f=BlankClip(fps=FR).KillAudio().Trim(0, 1)
# Version() <--- uncommenting this helps, a little.

chapter_string = chapter_string + f.chapter("One")
f = f + ColorBars().Trim(0, 10).AssumeFPS(F).KillAudio()

chapter_string = chapter_string + f.chapter("Two")

f = f + ColorBars().Trim(0, 25).AssumeFPS(F).KillAudio()

WriteFileEnd("chapters.txt", """ chapter_string """)

f


function chapter(clip, title) {
return String(clip.FrameCount) + " " + title + "\n"
}


When I run this, I get the error "Invalid Arguments to WriteFileEnd". By trial and error, I discovered that if I put something on the stack, e.g. a simple Version() call that doesn't do anything, at least the script runs, but it doesn't print anything to chapters.txt:


What I'm trying to do is take a bunch of smaller scripts (one.avs, two.avs) and create a chapter list that indicates the frame start when they're appended together, so the final file would be something like


0 One
10 Two
35 Three


Perhaps there's a better way to do this, but I'd still like to understand how to use FileWriteEnd, as often I'd like to write things out while processing or at the end, and I'm not understanding how to do something as simple as write something to a file.

Thx,

Tac

Gavino
10th July 2008, 15:54
In your example, you need to use

f = WriteFileEnd(f, "chapters.txt", """ chapter_string """)

Adding Version() worked because it set implicit 'last'.

The reason it didn't write anything may be that you need to use the full pathname for the file, eg "C:\folder\chapters.txt".
I seem to recall having problems with this, although it may be fixed in Avisynth 2.58.

And I assume you understand that nothing gets written until the script is closed in the rendering application.

EDIT: Also, note that "\n" is interpreted literally as backslash + 'n'. If you want a newline you have to use chr(13) + chr(10) or just literally have a line break inside quotes.
However, \n does work with Subtitle which I guess treats it as a special case.

tacman1123
11th July 2008, 19:25
Perfect, thanks! Indeed, one of the things that really hurt during testing is that I opened up WMP and played the script to the end, but then didn't see any output (because I hadn't closed WMP, even though the script was finished).

Anyway, it's working, thanks.

I don't understand why f = WriteFileEnd(f, ...) is needed, since "f" doesn't really play a part in the function in any way. I guess all functions need a clip to work on. Would dummy = FileWriteEnd(BlankClip, ...) be just as valid? This is more just curiosity, to understand how the function calls work.

Thx,

Tac

PS I've been having a lot of trouble posting from Firefox lately, getting an invalid security token error. I've contacted the forum admin's, no response yet. Anyone else seeing this? I've upgraded to Firefox 3, not sure if that's relevant, this message is being posted from IE.

Gavino
11th July 2008, 20:24
I don't understand why f = WriteFileEnd(f, ...) is needed, since "f" doesn't really play a part in the function in any way. I guess all functions need a clip to work on. Would dummy = FileWriteEnd(BlankClip, ...) be just as valid?
Yes, I think it would here. :D

I think it's mostly for consistency with the normal WriteFile, which shares the same code. And I suppose it means you can use it in a chain without upsetting 'last'.

One curiosity (perhaps you could even call it a bug!) is that
WriteFileEnd(f, filename, "Framecount()") does not print the Framecount of 'f' (as it would with WriteFile) but the Framecount of 'last'. So, as you say, 'f' plays no part, other than being passed on as the result.

stickboy
12th July 2008, 00:25
Since you're writing out stuff that can be computed when the script is loaded, maybe you should try my LogOpen/LogClose/LogString functions from my TestHarness plug-in (http://www.avisynth.org/stickboy/)?