Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st November 2023, 03:08   #1  |  Link
novablue
Registered User
 
Join Date: Apr 2021
Posts: 4
Switch between 2 clips every x second?

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.
novablue is offline   Reply With Quote
Old 1st November 2023, 04:22   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
How many frames is 10 seconds ? [whole number please]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 1st November 2023, 04:42   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
How does this do ?

Code:
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'.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st November 2023 at 05:46.
StainlessS is offline   Reply With Quote
Old 1st November 2023, 06:10   #4  |  Link
novablue
Registered User
 
Join Date: Apr 2021
Posts: 4
Quote:
Originally Posted by StainlessS View Post
How does this do ?

Code:
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?

Code:
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)
novablue is offline   Reply With Quote
Old 1st November 2023, 12:17   #5  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,512
Isn't ScriptClip a bit overhead-y?

I think this should work:

Code:
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)
}
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 1st November 2023 at 18:06.
wonkey_monkey is offline   Reply With Quote
Old 1st November 2023, 16:10   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Isn't ScriptClip a bit overhead-y?
Dont know, you tell me.

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

ScriptClip
Code:
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
Code:
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
Code:
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
Code:
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.
Code:
N=Import(".\nb.avs")
M=Import(".\nbwm.avs")
StackHorizontal(N,M)
EDIT: This fixes it.
Code:
 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)
}
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st November 2023 at 16:51.
StainlessS is offline   Reply With Quote
Old 1st November 2023, 17:59   #7  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,512
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:

Code:
    ChangeFPS(n*4, linear = false)
This fixes it. linear = true seems a strange default choice.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 1st November 2023 at 18:25.
wonkey_monkey is offline   Reply With Quote
Old 1st November 2023, 18:09   #8  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,512
Now:

Code:
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™
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 1st November 2023, 19:23   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Very nice
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 1st November 2023, 21:36   #10  |  Link
Rob105
Registered User
 
Join Date: Oct 2021
Posts: 43
Wrong thread)

Last edited by Rob105; 2nd November 2023 at 11:24.
Rob105 is offline   Reply With Quote
Old 1st November 2023, 21:47   #11  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Then they are not identical sadly. Could a dup detector be of assistance for this?
anton_foy is offline   Reply With Quote
Old 1st November 2023, 22:26   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,409
Quote:
Originally Posted by Rob105 View Post
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 ?
poisondeathray is offline   Reply With Quote
Old 2nd November 2023, 11:24   #13  |  Link
Rob105
Registered User
 
Join Date: Oct 2021
Posts: 43
Quote:
Originally Posted by poisondeathray View Post
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.
Rob105 is offline   Reply With Quote
Old 5th November 2023, 10:53   #14  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 226
What about loop function?
coolgit is offline   Reply With Quote
Reply

Tags
avisynth

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:40.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.