Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th September 2015, 17:08   #1  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
WriteFile[If](append=false) overwrites only on first call

Spooling through
Code:
file = "current_frame.txt"
BlankClip(length=10)
WriteFileStart(file, """"Start of file"""", append=false)
WriteFileIf(file, "true", "current_frame", append=false, flush=true)
produces
Quote:
0
1
2
3
4
5
6
7
8
9
In other words, only the first call to WriteFileIf() over-wrote the existing file (created by WriteFileStart()). All subsequent calls append. WriteFile() behaves similarly.

Is there any way of getting WriteFile[If]() to overwrite the output file at each call?
fvisagie is offline   Reply With Quote
Old 8th September 2015, 22:29   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
WriteFile[If](..., append=false) overwrites any existing file, but data is written for each rendered frame. Normally, that is what one wants.

If for some reason you only want to see the data for the last rendered frame, you can use:
ScriptClip("""WriteFile[If](..., append=false)""")

With this, a separate instance of WriteFile[If] is created for every frame, each one overwriting the data written by previous one.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 8th September 2015, 23:40   #3  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 769
Or maybe another "if" to only output if the current frame is the last one?
ajp_anton is offline   Reply With Quote
Old 9th September 2015, 07:47   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Yes, that would work.
When writing the script, you would have to take into account that the last frame rendered is not necessarily the final frame of the source clip (eg if there are following trims).
In a complex script, it may not be obvious what frame number to check for.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 9th September 2015, 09:06   #5  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Quote:
Originally Posted by Gavino View Post
If for some reason you only want to see the data for the last rendered frame, you can use:
ScriptClip("""WriteFile[If](..., append=false)""")

With this, a separate instance of WriteFile[If] is created for every frame, each one overwriting the data written by previous one.
That should do the trick. Thanks, Gavino.

Quote:
Originally Posted by ajp_anton View Post
Or maybe another "if" to only output if the current frame is the last one?
I'm afraid I don't follow you here as well as Gavino did. Please elaborate on the sequence of per-frame events you foresee here? In case it makes any difference, I was looking for a way to over-write the output file at each rendered frame, which Gavino addressed above.
fvisagie is offline   Reply With Quote
Old 10th September 2015, 08:24   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
What he meant was instead of repeatedly overwriting the file, you could add an extra condition so that the file was written only for the last frame.
WritefileIf(..., "... && current_frame == frameCount-1", append=false)

That works fine for simple cases, but as I pointed out, the last frame rendered is not always the final source frame and it may not be obvious what frame number to use instead of 'frameCount-1'.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th September 2015, 08:54   #7  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Thank you.
fvisagie is offline   Reply With Quote
Old 10th September 2015, 14:45   #8  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
If I am reading the source correctly, WriteFileIf seems to append always, regardless of the script argument...
Code:
(conditional_reader.cpp)

PVideoFrame __stdcall Write::GetFrame(int n, IScriptEnvironment* env) {
...
       if (Write::DoEval(env)) {
               Write::FileOut(env, AplusT);
       }
...
raffriff42 is offline   Reply With Quote
Old 10th September 2015, 17:56   #9  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by raffriff42 View Post
If I am reading the source correctly, WriteFileIf seems to append always, regardless of the script argument...
That is the per-frame code, which always appends, as stated earlier.
However the initial opening of the file is done in the constructor and the mode depends on the 'append' argument:
Code:
	fout = fopen(filename, append ? AplusT : WplusT);	//append or purge file
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 11th September 2015, 05:44   #10  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
Quote:
Originally Posted by Gavino View Post
WriteFile[If](..., append=false) overwrites any existing file, but data is written for each rendered frame. Normally, that is what one wants...
OK after rereading, I see what you mean, Gavino. I have tried to clarify this in the wiki.
raffriff42 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:39.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.