PDA

View Full Version : How to apply filter on every n-th frame?


AsTimeGoesBy
28th July 2005, 02:29
For a short period i like to get negative colors for every 3rd frame.
I have had in mind something like:
if ( frameNumber(clip)%3==1 ) clip = Levels(clip,0,1,255,255,0)
But there is no such command frameNumber() and how FrameEvaluate() may work i don't see...

There is ConditionalFilter() too, but i have problem to set up the condition. Moreover i don't like to create an alterative video stream.


A search with 'n-th frame' or 'how get frame number' didn't hit the problem but i hope there exists a solution for this!?

mg262
28th July 2005, 02:46
In this instance I think the easiest solution is

#source
a=selectevery(3,0)
b=selectevery(3,1)
c=selectevery(3,2)

#process a
#e.g.
a=a.greyscale

interleave(a,b,c)

AsTimeGoesBy
28th July 2005, 04:57
Indeed that works! Thanks!

But generally, is there really no way to get the actual frame number to depend on user-defined calculations or functions?

stickboy
28th July 2005, 08:16
Alternatively, there's my JDL_SimpleApplyEvery function (which requires my ApplyEvery plugin (http://www.avisynth.org/stickboy/)):
AVISource("foo.avi")
JDL_SimplyApplyEvery("Levels(0,1,255,255,0)", 3, "0")

mg262
28th July 2005, 12:37
But generally, is there really no way to get the actual frame number to depend on user-defined calculations or functions?ConditionalFilter, as you say, would have done the task... but the ConditionalFilter/ScriptClip mechanism is the one part of AVISynth that I really don't like,* so I am not going to try and expand...

*I hope this doesn't offend anybody... I just mean to express a personal opinion.

AsTimeGoesBy
28th July 2005, 15:26
Alternatively, there's my JDL_SimpleApplyEvery function (which requires my ApplyEvery plugin (http://www.avisynth.org/stickboy/)):
AVISource("foo.avi")
JDL_SimplyApplyEvery("Levels(0,1,255,255,0)", 3, "0")Thanks! Your functions save me again! :)

import("D:\Programs\Video\AviSynth\Plugins\jdl-range.avsi")
# JDL_SimpleApplyEvery(clip c, string thunk, int period, string "offsets")
# USAGE:
# Converts frames 1, 3, 11, 13, 21, 23, 31, 33, ... to greyscale.
# JDL_SimpleApplyEvery("Greyscale()", 10, "1, 3")

imagereader("800x600.jpg",0,127,fps=25)

applyrange( 33,45, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "0" )
applyrange( 81,93, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "0" )
But why it isn't possible to set here offsets = "1" to get the 2nd frame in the period of 3 frames?




ConditionalFilter, as you say, would have done the task... [...] Ok, i will retry it once just to see if i'm able to get a suitable result.

mg262
28th July 2005, 15:29
Ok, i will retry it once just to see if i'm able to get a suitable result.if you get stuck and you post your script, someone willprobably give you a pointer...

stickboy
28th July 2005, 18:57
applyrange( 33,45, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "0" )
applyrange( 81,93, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "0" )
But why it isn't possible to set here offsets = "1" to get the 2nd frame in the period of 3 frames?What do you mean?applyrange( 81,93, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "1" )Should work... does it not?

If you mean you mean that:applyrange( 81,93, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, offsets="1" )doesn't work, that's because ApplyRange can't handle named parameters. (Since ApplyRange is an ordinary functions like any other, any named parameters you use would be names of parameters to ApplyRange, not to the function you want ApplyRange to call.)

AsTimeGoesBy
28th July 2005, 20:14
What do you mean?applyrange( 81,93, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 3, "1" )Should work... does it not?
Well, it does not work correctly with me. It causes an error by line 6 and 7 saying:
Avisynth open failure. Assert: assertion failed. ... jdl-range.avsi, line 215

Also the following line is affected:
JDL_SimpleApplyEvery( "Levels(0,1,255,255,0)" , 3, "1" )

But the next line works fine again:

applyrange( 30,50, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 6, "0, 3" )
There are exaclty negative colors at frame 30, 33, 36, ...

stickboy
28th July 2005, 23:07
Hm... that's probably a bug. I'll take a look. How many frames are there in the clip you're using JDL_SimpleApplyEvery on?

AsTimeGoesBy
29th July 2005, 11:22
Hm... that's probably a bug. I'll take a look. How many frames are there in the clip you're using JDL_SimpleApplyEvery on?Actually i only have made some tests. That test video was made by imagereader() containing some about 200 frames.

Finally i would like to apply it on a longer video using at some places e.g. applyrange( 4502,4508, "JDL_SimpleApplyEvery", "Levels(0,1,255,255,0)" , 2, "0" )

stickboy
30th July 2005, 23:07
Okay, I've updated my ApplyEvery plug-in with what is hopefully a fix to that bug. Thanks for pointing it out.