Log in

View Full Version : SelectRangeEvery with alternating direction?


TomArrow
21st September 2021, 19:50
This is a bit of an exotic request I suppose. I have a repetitive clip (with small changes in each repetition) and I want to get only a specific range out of each repetition. SelectRangeEvery can do that. But what I would like is to reverse the direction of the range in every second range so that I get a more continuous, back-and-forth pendulum kinda effect.

Is there any built in way I could do this? I'd try to modify myself but it's an internal function and not a plugin so I'm not sure how I would go about that.

poisondeathray
21st September 2021, 20:40
How about 2 sets of ranges SelectRangeEvery, then breaking them up with SelectEvery, then Interleave the desired combination ?

TomArrow
22nd September 2021, 00:54
How about 2 sets of ranges SelectRangeEvery, then breaking them up with SelectEvery, then Interleave the desired combination ?

I thought about something like that, but if I invert one of them, it will also invert the order of the ranges. I would still like it to be in the order of range 1, range 2, range 3 etc. Just with every second inverted in direction.

But maybe I'm just not thinking about it deeply enough.

poisondeathray
22nd September 2021, 00:57
Can you illustrate what you mean with semi concrete example using numbers ?

TomArrow
22nd September 2021, 01:16
Sure. Let's say there's a repeating pattern of 6 frames.

[1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6][1,2,3,4,5,6]

But they're not identical, just almost identical. Small changes in each iteration.

And I would, for example, want [3,4] out of each of those groups. But every second one reversed. So for example:

[3,4][4,3][3,4][4,3][3,4][4,3][3,4][4,3][3,4][4,3]

But ofc it would be more than 2 frames, this is just for illustration as you asked. It could also be repeating groups of 100, with 20 in the middle being interesting.

poisondeathray
22nd September 2021, 01:42
Ok I just wrote up an example before I saw you posted, hopefully it illustrates what I mean with breaking up the selection sets

eg. let's say normally you want to select 5 frames from every 200 frames
0,1,2,3,4, 200,201,202,203,204, 400,401,402,403,404...


blankclip(length=10000)
showframenumber()
selectrangeevery(200,5)


But you want every 2nd set reversed instead:
0,1,2,3,4, 204,203,202,201,200, 400,401,402,403,404, 604,603,602,601,600...


create 2 selection sets, separate with selectevery, and interleave in the desired order


orig=blankclip(length=10000).showframenumber()

a=orig.selectrangeevery(400,5) #0,1,2,3,4, 400,401,402,203,404, 800,801802,803,804,...
b=orig.selectrangeevery(400,5,200) #200,201,202,203,204, 600,601,602,603,604, 1000,1001,1002,1003,1004,...

a0 = selectevery(a, 5,0)
a1 = selectevery(a, 5,1)
a2 = selectevery(a, 5,2)
a3 = selectevery(a, 5,3)
a4 = selectevery(a, 5,4)

b0 = selectevery(b, 5,0)
b1 = selectevery(b, 5,1)
b2 = selectevery(b, 5,2)
b3 = selectevery(b, 5,3)
b4 = selectevery(b, 5,4)

Interleave(a0,a1,a2,a3,a4,b4,b3,b2,b1,b0)

TomArrow
22nd September 2021, 02:36
Aah, that makes sense. Clever. Not very flexible tho sadly. Would be nice to have it parametrized.

Frank62
23rd September 2021, 11:29
Why not simply:
Edit: Not that simple, as I thought. :)

johnmeyer
23rd September 2021, 20:09
I think this does what the OP wants, as specified in Post #6 (http://forum.doom9.org/showpost.php?p=1952855&postcount=5). It is easy to adjust the paramaters. Only the third and fourth frame of every six frames is selected, and every other set of 3,4 is reversed to 4,3.

AviSource("E:\fs.avi")
c=Last
normal = selectevery(c,6,3,4)
reverse = selectevery(c,6,4,3)
output = conditionalSelect(normal,"(current_frame/2 %2 <> 0) ? 0 : 1",normal,reverse)
return output

TomArrow
24th September 2021, 15:29
Thanks johnmeyer, that looks at least better than what came before, but it's too complicated and still possibly not flexible enough for my taste.

I just went ahead and made the new version of the filter that does what I want: https://github.com/TomArrow/SelectRangeEveryReversing

Even does audio.

Though, I'm not quite sure what kind of copyright notice I should include since I modified the original code from AviSynth+. Any advice would be appreciated and will then be pushed to the repository asap. Not experienced with this legalese stuff.

Incidentally, I found a bug in the original SelectRangeEvery I think. Due to a little oversight in the code, the audio output of SelectRangeEvery is pretty much useless. I've created an issue about this on the AviSynth+ Github.