View Full Version : ReplaceEvery


jmac698
30th July 2012, 22:00
There's a function I need but I don't know how to do it. I need something like a ReplaceEvery(clip original, clip replacement, int cycle, int phase)
Which can replace 1 of every cycle frames in the original clip with the frames in the replacement clip.
For example, original contains frames 0,1,2,3,4,5
The replacement contains two frames, replacement for 0 and replacement for 3.
Then ReplaceEvery(clip1, clip2, 3, 0) would return
new0, 1, 2, new3, 4, 5

IanB
30th July 2012, 22:39
...
cycle=3
phase=0
ConditionalFilter(Clip2, Clip1, "current_frame % cycle", "equals", "phase")

jmac698
30th July 2012, 22:47
Ah! Brilliant. I've got a few scripts I've got to fix now.
Thanks.

Of course, I have to change the framerate of clip2 with changefps to match clip1, since it has less frames.

Gavino
30th July 2012, 23:18
ConditionalFilter(Clip2, Clip1, "current_frame % cycle", "equals", "phase")
Since ConditionalFilter has three clip arguments, it should be
ConditionalFilter(Clip1, Clip2, Clip1, "current_frame % cycle", "equals", "phase")
(unless 'last' is set to Clip1 (or Clip2).)

Of course, I have to change the framerate of clip2 with changefps to match clip1, since it has less frames.
Not specifically to match clip1 (that's not necessary), but to repeat each frame 'cycle' times (though here that comes to the same thing, ie multiply the frame rate by 3).

jmac698
30th July 2012, 23:24
But what if the clips have different properties? I don't see any mention of it in the docs.
And yes, I could be replacing multiple frames per cycle.

aha! I think I found a bug. The framerates don't have to match, but the resulting clip has the lower framerate, and the operation is done assuming they are the same framerate regardless.

This kind of thing annoys me. You probably remember me complaining before, but I need everything to be documented precisely so I know what to expect when programming. That's how I found the pointresize issue.

Gavino
30th July 2012, 23:30
But what if the clips have different properties?
The clips 'source1' and 'source2' must have the same width, height and colorspace.
All other properties of the result (incl framerate and audio) are taken from 'source1' only.

jmac698
30th July 2012, 23:41
Ok, confirmed, but at least in 2.58, the clips are operated frame by frame regardless of their framerates.

Gavino
30th July 2012, 23:54
Ok, confirmed, but at least in 2.58, the clips are operated frame by frame regardless of their framerates.
That's what I meant - source2 is treated as just a sequence of frames, the actual frame rate is irrelevant.

jmac698
31st July 2012, 00:11
Ok, I have a question
I put
conditionalfilter(last,newf3.changefps(exfr),last,"current_frame % cycle", "equals", "offset+3")
in a function, and cycle is a local variable, but it's not recognized in conditionalfilter. Is the only solution to make it global?

Gavino
31st July 2012, 00:26
Ok, I have a question
I put
conditionalfilter(last,newf3.changefps(exfr),last,"current_frame % cycle", "equals", "offset+3")
in a function, and cycle is a local variable, but it's not recognized in conditionalfilter. Is the only solution to make it global?
That's one way, but it won't work if you call the function more than once with different values of 'cycle'.
A cleaner way is to use the extended version of ConditionalFilter from GRunT:
eg ConditionalFilter(..., args="cycle")

jmac698
31st July 2012, 01:16
Got it. Totally need GRunT in this case.