Log in

View Full Version : Switch between 2 clips every x second?


novablue
1st November 2023, 03:08
Hello,

i would like to load two clips identical in length, size and so on and show clip1 for 10 seconds then show clip2 for 10 seconds, where clip 2 continuous at the position where clip 1 left off, then play clip 1 again where clip 2 left off and so on. I basically want to swap between the two clips back an fourth in an interval. Is there any way to do this automatically? i looked at plugins like ApplyEvery() \ InterleaveEvery() \ ClipClop() but i can't figure out how to do it.

Much help appreciated.

StainlessS
1st November 2023, 04:22
How many frames is 10 seconds ? [whole number please]

StainlessS
1st November 2023, 04:42
How does this do ?


SrcClip=BlankClip(Length=200000,Color=$FF0000,Pixel_type="YV12").ShowFrameNumber
AltClip=BlankClip(Length=200000,Color=$0000FF,Pixel_type="YV12").ShowFrameNumber

BLKCNT=10 # 10 seconds { however many frames there are in 10 seconds }

SSS=""" Return ((current_frame / BLKCNT) % 2 == 0) ? Last : AltClip """

ScriptClip(SrcClip,SSS)

EDIT: Changed 'SrcClip' inside SSS to 'Last'.

novablue
1st November 2023, 06:10
How does this do ?


SrcClip=BlankClip(Length=200000,Color=$FF0000,Pixel_type="YV12").ShowFrameNumber
AltClip=BlankClip(Length=200000,Color=$0000FF,Pixel_type="YV12").ShowFrameNumber

BLKCNT=10 # 10 seconds { however many frames there are in 10 seconds }

SSS=""" Return ((current_frame / BLKCNT) % 2 == 0) ? Last : AltClip """

ScriptClip(SrcClip,SSS)

EDIT: Changed 'SrcClip' inside SSS to 'Last'.

Thanks this is exactly what i needed. How come i can not put it into a function?

Function MyFunc(SrcClip, AltClip) {
BLKCNT=10 # 10 seconds

SSS=""" Return ((current_frame / BLKCNT) % 2 == 0) ? SrcClip : AltClip """

ScriptClip(SrcClip,SSS)
}

SrcClip=BlankClip(Length=200000,Color=$FF0000,Pixel_type="YV12").ShowFrameNumber
AltClip=BlankClip(Length=200000,Color=$0000FF,Pixel_type="YV12").ShowFrameNumber

MyFunc(SrcClip, AltClip)

wonkey_monkey
1st November 2023, 12:17
Isn't ScriptClip a bit overhead-y?

I think this should work:

function SwapEveryN(clip a, clip b, int n) {
Interleave(a,b)
Trim(0, n*2 - 2) + last #
SelectRangeEvery(n*4, n*4 - 1)
Trim(n*2 - 1,0)
Assumefps(n*4 - 1)
ChangeFPS(n*4, linear = false) # edit: speed-up
Trim(1, 0)
SelectEven
Assumefps(FrameRate(a)).AudioDubEx(a)
}

StainlessS
1st November 2023, 16:10
Isn't ScriptClip a bit overhead-y?
Dont know, you tell me.

(Changed framelength to 50,000, curtail time measurements)

ScriptClip

SrcClip=BlankClip(Length=50000,Color=$FF0000,Pixel_type="YV12").ShowFrameNumber
AltClip=BlankClip(Length=50000,Color=$0000FF,Pixel_type="YV12").ShowFrameNumber

BLKCNT=10 # 10 seconds { however many frames there are in 10 seconds }

SSS=""" Return ((current_frame / BLKCNT) % 2 == 0) ? Last : AltClip """

ScriptClip(SrcClip,SSS)

Wonkey

SrcClip=BlankClip(Length=50000,Color=$FF0000,Pixel_type="YV12").ShowFrameNumber
AltClip=BlankClip(Length=50000,Color=$0000FF,Pixel_type="YV12").ShowFrameNumber

BLKCNT=10 # 10 seconds { however many frames there are in 10 seconds }

return SwapEveryN(SrcClip,AltClip,BLKCNT)


Function SwapEveryN(clip a, clip b, int n) {
Interleave(a,b)
Trim(0, n*2 - 2) + last #
SelectRangeEvery(n*4, n*4 - 1)
Trim(n*2 - 1,0)
Assumefps(n*4 - 1)
ChangeFPS(n*4)
Trim(1, 0)
SelectEven
# Assumefps(FrameRate(a)).AudioDubEx(a) # EDIT: fixed FrameRate and AudioSamples
}


###############

ScriptClip AvsMeter64

AVSMeter 3.0.9.0 (x64), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.3 (r4017, master, x86_64) (3.7.3.0)

Number of frames: 50000
Length (hh:mm:ss.ms): 00:34:43.333
Frame width: 640
Frame height: 480
Framerate: 24.000 (24/1)
Colorspace: YV12
Audio channels: 1
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 91875000

Frames processed: 50000 (0 - 49999)
FPS (min | max | average): 221.8 | 398.2 | 374.3
Process memory usage (max): 71 MiB
Thread count: 13
CPU usage (average): 8.2%

Time (elapsed): 00:02:13.572

Wonkey AvsMeter64

AVSMeter 3.0.9.0 (x64), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.3 (r4017, master, x86_64) (3.7.3.0)

Number of frames: 50000
Length (hh:mm:ss.ms): 00:41:40.000
Frame width: 640
Frame height: 480
Framerate: 20.000 (20/1)
Colorspace: YV12
Audio channels: 1
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 110248898

Frames processed: 50000 (0 - 49999)
FPS (min | max | average): 38.35 | 208.2 | 191.0
Process memory usage (max): 68 MiB
Thread count: 13
CPU usage (average): 8.2%

Time (elapsed): 00:04:21.791


EDIT: Your clip length [EDIT: duration] is reading higher for some reason (in avsmeter), 00:34:43.333 vs 00:41:40.000.
EDIT: Your FrameRate is 20.0FPS, mine 24.0. [also, audio samples differ]

EDIT: Frames are identical.

N=Import(".\nb.avs")
M=Import(".\nbwm.avs")
StackHorizontal(N,M)


EDIT: This fixes it.

Function SwapEveryN(clip a, clip b, int n) {
Interleave(a,b)
Trim(0, n*2 - 2) + last #
SelectRangeEvery(n*4, n*4 - 1)
Trim(n*2 - 1,0)
Assumefps(n*4 - 1)
ChangeFPS(n*4)
Trim(1, 0)
SelectEven
Assumefps(FrameRate(a)).AudioDubEx(a)
}

wonkey_monkey
1st November 2023, 17:59
I find the difference in speed very surprising. ChangeFPS seems to be the culprit. I can't understand why it would be so slow.

Edit:

ChangeFPS(n*4, linear = false)

This fixes it. linear = true seems a strange default choice.

wonkey_monkey
1st November 2023, 18:09
Now:


ScriptClip:
FPS (min | max | average): 74.66 | 48780 | 44597

SwapEveryN:
FPS (min | max | average): 662.0 | 909091 | 827504


Little difference with a real source filter of course, but Every Little Helps™

StainlessS
1st November 2023, 19:23
Very nice :)

Rob105
1st November 2023, 21:36
Wrong thread)

anton_foy
1st November 2023, 21:47
Then they are not identical sadly. Could a dup detector be of assistance for this?

poisondeathray
1st November 2023, 22:26
Actually my frames are so far apart (fast panning) that i am getting real mess merging just 2 frames together.

This is from merging one frame with the next one, you can see the tree stem on the left of the house is so far apart.

24fps panning speed 17.5° a second.

Guess i am out of options here except using something like Topaz Video AI to rebuild the missing frames?


What are you trying to do exactly ? / What is the scenario or background information ?

What does this have to do with switching clips ?, or wrong thread ?

Rob105
2nd November 2023, 11:24
What are you trying to do exactly ? / What is the scenario or background information ?

What does this have to do with switching clips ?, or wrong thread ?

Wrong thread yeah, pardon.

coolgit
5th November 2023, 10:53
What about loop function?