PDA

View Full Version : Stacking the frames of a clip


JanBing
16th March 2007, 02:23
Is there actually a way to take an input clip, and stack its frames on top of each other?

For example, I have an image-sequence consisting of 100 strips of a 3D-rendering. They all fit together perfectly, so instead of using...

a = ImageSource("xxx1")
b = ImageSource("xxx2")
c = ImageSource("xxx3")
.
.
.
StackVertical(a, b, c, ...)
Return last
... which is quite cumbersome, is there a way to do something along the lines of...

c = ImageSource("xxx%", 0, 100)
StackFramesVertical(c)
Return last
?

neuron2
16th March 2007, 03:28
Write a simple program that accepts your syntax and generates the cumbersome script.

It will be interesting to see if StackVertical can accept 100 arguments. :)

JanBing
16th March 2007, 06:15
Write a simple program that accepts your syntax and generates the cumbersome script.

It will be interesting to see if StackVertical can accept 100 arguments. :)

Yeah, simple program... I don't even know how to do that ;)

Which gave me the chance to test how many arguments StackVertical can cope with:

*drumroll*

60!

Whyever!?

gzarkadas
16th March 2007, 06:33
60!

Whyever!?

This is the maximum number of arguments accepted by any Avisynth function.

gzarkadas
16th March 2007, 07:02
Well, since I enjoy to code "weird" utilities :D , here is the solution to your problem (provided under the GNU GPL (http://www.gnu.org/licenses/gpl.html)).


Function StackFramesVertical(clip c, int "__fr") {
rewind = !Defined(__fr) # in first invocation clear stacked
__fr = Default(__fr, 0)
Assert(__fr >= 0, "StackFramesVertical: only clip must be passed as argument")
global stacked = __fr < c.Framecount ? \
(rewind ? c.Trim(__fr, -1) : StackVertical(stacked, c.Trim(__fr, -1))) : \
stacked
return __fr < c.Framecount ? StackFramesVertical(c, __fr + 1) : stacked
}


The __fr argument is "private", it should never be supplied; intended usage is StackFramesVertical(c) where c is the clip with the image sequence that is to be stacked.

stickboy
16th March 2007, 09:46
global? Tsk tsk. :)

gzarkadas
16th March 2007, 11:27
Yes, dirty, but works :) .

JanBing
18th March 2007, 20:45
:eek:

Wow... thank you very much! :)

I've gotta admit, I would've never come up with anything CLOSE to your aproach. Or anything else, obviously. Thanks again! :cool:

stickboy
19th March 2007, 09:25
Yes, dirty, but works :) .Well, I'm just wondering why you didn't implement it like:
function StackFramesVertical(clip c)
{
Assert(c.FrameCount() > 0)
return (c.FrameCount() == 1)
\ ? c
\ : StackVertical(c.Trim(0, -1),
\ StackFramesVertical(c.Trim(1, 0)))
}