Log in

View Full Version : Why this simple frame delete script doesn't work?


Valeron
27th August 2006, 21:23
in order to delete certain frames in the clip, i write my own "for" fuction inspired by the tips in the avs manual.

i need to delete 1 frame in 5, the frame index mod 5 should be 4.
the code is like this

v=MPEG2Source("J:\DVD_VIDEO\dvd_pro.d2v")
v=assumetff(v).separatefields().trim(3465,3554)
v=FieldDecimate(v)
return v

function for(string initial,string end_condition,string stepping,string loopbody)
{
assert(IsString(end_condition),"The end condition must be a string with bool returned.")
defined(initial)?eval(initial):eval("""
eval(end_condition)?return:eval("eval(loopbody)
eval(stepping)
return for(end_condition=end_condition,stepping=stepping,loopbody=loopbody))
")""")
}

function FieldDecimate(clip c)
{
function FieldDeleteLoop()
{
iFrameCounter%5==4?DeleteFrame(c,iFrameCounter):NOP()
}
assert(IsClip(c),"The input is not a clip")
for("iFrameCounter=0","iFrameCounter<=c.framecount()","iFrameCounter++","FieldDeleteLoop()")
return c
}

i can load it with VD, but no frame deleted. anything wrong with this script?

foxyshadis
27th August 2006, 21:36
Eval only works its magic at initialization, but conditional fuctions (such as scriptclip and frameevaluate) update every frame.

stickboy
27th August 2006, 22:26
If you're trying to delete every fourth frame, you should use SelectEvery(5, 0, 1, 2, 3). Also see my JDL_DecimatePattern function (http://www.avisynth.org/stickboy/).

You should be wary of using ScriptClip/FrameEvaluate and of trying to write for-loops. They're usually not the appropriate idiom to use for AviSynth scripts, where you should be applying a more functional rather than imperative style.

Valeron
28th August 2006, 05:05
Eval only works its magic at initialization
do you mean there's no way to implement nested block statement with "eval" only in avisynth?
but conditional fuctions (such as scriptclip and frameevaluate) update every frame.
according to the document, this 2 function can only co-work with inernal filters and runtime functions. is there any chance to use it with user-defined ones?

If you're trying to delete every fourth frame, you should use SelectEvery(5, 0, 1, 2, 3).
thx for your idea. i'll try that. but i still wonder if a more powerful "loop", user-defined procedure support, arbitrary initialization and stepping.... a very C-like powerful loop is possible in avs?

thx in advance

foxyshadis
28th August 2006, 06:54
Richard Berg once created a looping structure, which actually works. I'm not sure if it's on the wiki or not. Stickboy's right though, besides finding simpler solutions already existing, if you can wrap your head around functional programming avisynth becomes much simpler.

And I'm not sure what document you're referring to, but conditional functions can use any globally defined function (including a user-defined one) or variable.

Boulder
28th August 2006, 06:57
Richard Berg once created a looping structure, which actually works. I'm not sure if it's on the wiki or not.
http://forum.doom9.org/showthread.php?t=106880

Mug Funky
28th August 2006, 10:04
it is possible to use conditional filtering to mimic DG's "decimate".

it's slow though :)

you create 5 clips, each with a different n-in-m decimation (using selectevery...), then you check each group of 5 frames for dupes using mt_lutxy. then you choose the decimation type that doesn't give you a dupe.

i scripted one once, but it was too slow to use. it was more to see if i could do it.

but basically, conditional filters must return the same number of frames they're fed with - so you have to decimate before you run the filter :)

stickboy
28th August 2006, 11:44
thx for your idea. i'll try that. but i still wonder if a more powerful "loop", user-defined procedure support, arbitrary initialization and stepping.... a very C-like powerful loop is possible in avs?Scripts are evaluated when they are loaded. Any looping construct you have must be expandable at load-time without examining any frame content. Such loops (and really all user-defined functions) are basically macros for syntactical convenience, not run-time control flow.

Again, if you think you need looping, you're probably thinking in the wrong mindset. Filters are transforms on a signal (the clip).

Valeron
28th August 2006, 13:33
@foxyshadis&Boulder:
thank u for the great info. i'll have a look in it.

@Mug Funky:
what i met is a damm hell pattern in this 90 fields/45 frames clip, it's part of an anime openning. it comes like this:
i would like to consider 5 fields as a pattern, the 4th and 5th are dupes, it's neither a 60i nor a film scene.
i've no idea how to manipulate it.
i've tried simply bob it to 60fps, or delete the dupe field then weave it.... bob will give so many artifacts in the deinterlaced edges, weave will leave some frames combs, neither methods give me good result.

the scene is a very bad edit composition, with 3 film overlay together and have a fade in/out duration. one is staff subtitle, the other two layer are two figures fade in and out independantly. these 3 film layers are not synchronize telecined pattern.

any good ideas to deal with this scene?