View Full Version : WriteFileIf Error 'Invalid arguments'


gispos
19th July 2020, 20:59
I rewrote a found function that does not work under Avs + (every frame is written in the log file) for whatever reason.

Now I get an error with WriteFileIf. With Neo I don't get an error, but I have to declare all variables as global because Neo and Grunt are incompatible.

'Invalid argument to' WriteFileIf '
What am I doing wrong?

the original by 06_taro

Function SCDetect(clip c, string "scFile", int "thSCD1", int "thSCD2", float "mDiff", int "pel", int "search", int "searchparam", bool "preblur", bool "info"){

scFile = Default(scFile, "scFile.log")
thSCD1 = Default(thSCD1, 360)
thSCD2 = Default(thSCD2, 120)
mDiff = Default(mDiff, 2.5)
pel = Default(pel, 1)
search = Default(search, 4)
searchparam = Default(searchparam, 2)
preblur = Default(preblur, true)
info = Default(info, false)

last = preblur ? c.RemoveGrain(20, 0) : c

Assert( IsYV12 , "SCDetect needs YV12 input!" )

super = MSuper(pel=pel, chroma=false)
vector = super.MAnalyse(pelsearch=pel, search=search, searchparam=searchparam, chroma=false)
global scMask = MSCDetection(vector, thSCD1=thSCD1, thSCD2=thSCD2).Crop(0,0,16,16)

global SC_mD = mDiff
global mean = Histogram(mode="Color").Crop(width+64, 64, 128, 128)

SCTrue = c.Subtitle("Scene change: true" )
SCFalse = c.Subtitle("Scene change: false")

info ? ConditionalFilter( last, SCTrue, SCFalse, "boolSC", "==", "true" )
\ : nop
FrameEvaluate( """global boolSC =
\ (
\ ( scMask.YPlaneMax == 255 ) &&
\ (
\ (mean.YDifferenceFromPrevious > SC_mD*3) ||
\ (
\ (mean.YDifferenceFromPrevious > SC_mD) &&
\ (mean.YDifferenceFromPrevious > (mean.YDifferenceToNext+mean.loop(0, 0, -1).YDifferenceToNext+mean.loop(0, 0, 1).YDifferenceToNext)/1.2)
\ )
\ )
\ )""" )

( scFile != "nul" ) ? WriteFileStart( scFile, """ "# Scene change frame list" """ ).WriteFileIf( scFile, "boolSC==true", "current_frame" ) : nop

return last
}


my changes

Function SCDetect(clip c, string "scFile", int "thSCD1", int "thSCD2", float "mDiff", int "pel", int "search", int "searchparam", bool "preblur", bool "info"){

scFile = Default(scFile, "scFile.log")
thSCD1 = Default(thSCD1, 360)
thSCD2 = Default(thSCD2, 120)
mDiff = Default(mDiff, 2.5)
pel = Default(pel, 1)
search = Default(search, 4)
searchparam = Default(searchparam, 2)
preblur = Default(preblur, true)
info = Default(info, false)

last = preblur ? c.RemoveGrain(20, 0) : c
Assert( IsYV12 , "SCDetect needs YV12 input!" )

super = MSuper(pel=pel, chroma=false)
vector = super.MAnalyse(pelsearch=pel, search=search, searchparam=searchparam, chroma=false)
scMask = MSCDetection(vector, thSCD1=thSCD1, thSCD2=thSCD2).Crop(0,0,16,16)

SC_mD = mDiff
mean = Histogram(mode="Color").Crop(width+64, 64, 128, 128)

SCTrue = c.Subtitle("Scene change: true" )
SCFalse = c.Subtitle("Scene change: false")
info ? ConditionalFilter( last, SCTrue, SCFalse, "boolSC", "==", "true" ) : nop

sss = """
global boolSC =
\ (
\ (scMask.YPlaneMax == 255 ) &&
\ (
\ (mean.YDifferenceFromPrevious > SC_mD*3) ||
\ (
\ (mean.YDifferenceFromPrevious > SC_mD) &&
\ (mean.YDifferenceFromPrevious > (mean.YDifferenceToNext+mean.loop(0, 0, -1).YDifferenceToNext+mean.loop(0, 0, 1).YDifferenceToNext)/1.2)
\ )
\ )
\ )
(scFile != "nul") ? WriteFileIf( scFile, "boolSC==True", "current_frame" ) : nop

return last
"""
return ScriptClip(sss, Args="scFile, scMask, SC_mD, mean, info")
}

real.finder
19th July 2020, 22:00
if you remove grunt it will work, I think it's bug in last avs+, old avs+ work fine

gispos
19th July 2020, 22:12
if you remove grunt it will work, I think it's bug in last avs+, old avs+ work fine
Yes, I was just about to post it, it works with older versions.

real.finder
20th July 2020, 00:08
this grunt seems work https://www.solidfiles.com/v/Lwxa2MYmRazx6

I just remove these from the source

if (avsVersion >= 2.58f) {
// mechanism for same-name filters only works on 2.58 and later
env->AddFunction("ScriptClip", "cs[showx]b[after_frame]b[args]s[local]b", MakeScriptClip, 0);
env->AddFunction("FrameEvaluate", "cs[showx]b[after_frame]b[args]s[local]b", MakeFrameEvaluate, 0);
env->AddFunction("ConditionalFilter","cccsss[showx]b[args]s[local]b", MakeConditionalFilter, 0);
env->AddFunction("ConditionalFilter","cccs[showx]b[args]s[local]b", MakeConditionalFilter2, 0);
env->AddFunction("WriteFile", "c[filenamex]ss+[append]b[flush]b[args]s[local]b", MakeWriteFile, 0);
env->AddFunction("WriteFileIf", "c[filenamex]ss+[append]b[flush]b[args]s[local]b", MakeWriteFileIf, 0);
}


edit: well it's not, the gWriteFileIf still not work

real.finder
20th July 2020, 00:31
if I make it gWriteFileIf(filename=scFile, "boolSC==true", "current_frame" )

https://i.postimg.cc/bJ9MGjHN/Untitled.png (https://postimages.org/)

there are something wrong with how avs+ deal with this kind of parameters

real.finder
1st September 2020, 09:58
try this https://github.com/AviSynth/AviSynthPlus/issues/186#issuecomment-683817906

it's work now for me

StainlessS
1st September 2020, 11:08
Good job RF, nice to see you keeping Pinterf on his toes :)

gispos
1st September 2020, 17:52
Yes it works.
Thank you real.finder for your persistence.:)