Log in

View Full Version : How can I interleave groups of frames from different clips?


Prettz
19th September 2006, 06:55
I'd really like to be able to interleave ranges of frames from 2 different clips, like the Interleave() function, but instead of the sequence being like "a1, b1, a2, b2, a3, b3..." I want it to be like "a1, a2, a3, b1, b2, b3, a4, a5, a6, b4, b5, b6...".

The reason I want to do this is because I'm analyzing the effects of different filter chains on the noise in a film, but Interleave()'s frame-by-frame behavior isn't helping. The noisiness in a certain scene is so violent and abrupt that a background area of the picture between two frames bear no resemblence to one another. What I need to see is the difference in the the motion of the noise between the two filter chains. So I want to have it giving me 15 or so frames of one clip, then the same 15 frames of the other, then the next 15 frames of the first clip, ect.

After looking at Animate for a while I concluded it can't do what I want it to.

I've now tried making 2 different versions of a recursive function:

function MultiInterleave(clip c1, clip c2, int start) {
return ( c1.Trim(start,start+14) + c2.Trim(start,start+14) \
+ MultiInterleave(c1,c2,start+15) ) //tail recursion is supposed to be better
}

function MultiInterleave(clip c1, clip c2, int start) {
return (start >= 100000 ? \
(c1.Trim(start,start+14) + c2.Trim(start,start+14)) : \
(c1.Trim(start,start+14) + c2.Trim(start,start+14) \
+ MultiInterleave(c1,c2,start+15)) )
}

MultiInterleave(a.Subtitle("a"), b.Subtitle("b"), 0)

The 100000 is just an arbitrary limit I hoped might limit memory usage.

Both of these functions cause VirtualDubMod to silently crash just a second after I open the script. There doesn't seem to be any way I can tell if it was caused by memory because it closes too fast.

Is there any other way to interleave two clips together like I want to, and that doesn't crash?

Didée
19th September 2006, 08:07
Amongst the neat things of stickboy's Avisynth Stuff (http://www.avisynth.org/stickboy/), there is also InterleaveEvery() (part of ApplyEvery). That will do exactly what you want.

In case it's more than two clips you want to interleave like that, it can be done with a simple function, too. Just make a plain interleave, and then SelectEvery() the correct order.
E.g., to interleave frames from clips a, b, c in this order: a1 a2 a3 b1 b2 b3 c1 c2 c3, that would be

interleave(a,b,c)
SelectEvery(9, 0,3,6,1,4,7,2,5,8)

Prettz
19th September 2006, 08:15
Thanks a lot, I'll give those a try.

Incidentally I just got that second recursive function to work by using a very low limit of 10,000. It uses around 600MB of RAM at that point. :scared:
And it's not as useful as I thought it would be either, even when I insert a black frame in between each set of 30 frames. On the plus side, the doubled framerate makes Decimate's lag disappear when trying to go through it in real time.

foxyshadis
19th September 2006, 18:19
Maybe a heads up would be better anyway, either same half side-by-side or processing only the right:


# view two clips side-by-side, 3rd parameter defines window:
# 0: left 1: center (default) 2: right
function SXS (clip "_c1", clip "_c2", int "_scale", string "s1", string "s2") {
_scale = default(_scale,1)
s1 = default(s1,"")
s2 = default(s2,"")
_w1 = select(_scale,0,round(Width(_c1)/8)*2,round(Width(_c1)/4)*2)
_w2 = round(width(_c1) / 4)*2
return Stackhorizontal(_c1.crop(_w1,0,_w2,0).subtitle(s1),_c2.crop(_w1,0,_w2,0).subtitle(s2))
}

# process only one side of scene
# 0: left 1: right (default)
function SP (clip "_c1", clip "_c2", int "_scale", string "s1", string "s2") {
_scale = default(_scale,1)
s1 = default(s1,"")
s2 = default(s2,"")
_w1 = round(Width(_c1)/4)*2
c1 = select(_scale,_c2,_c1)
c2 = select(_scale,_c1,_c2)
return Stackhorizontal(c1.crop(0,0,_w1,0).subtitle(s1),c2.crop(_w1,0,0,0).subtitle(s2))
}


Both have been invaluable while playing with filters, when interleave isn't good enough. (For some reason I really liked underscores back when I made those.)

btw, if processing is jerky and you want fluidity, what I usually do is scroll up ~40 frames, then scroll back while they're all in the cache.

squid_80
19th September 2006, 18:44
Can't...read...tiny script.....

foxyshadis
19th September 2006, 18:58
Ian gets angry when anyone posts wide scripts, so I did that... I guess I'll just shrink it a bit then.

Oh geez, size=1 is smaller than it used to be, no wonder. Silly vbb.

AVIL
19th September 2006, 19:36
@squid_80

You can magnify the text:

Internet explorer menu:

View->Text size->Bigger

(Or anything similar as my program is in spanish)

Good luck

squid_80
19th September 2006, 19:44
That's pretty nifty... Selecting "larger" makes it normal size and it actually fills the indented rectangle, instead of a big gap being at the bottom and right side.