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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 5th January 2019, 02:04   #1  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Cyclic clip switching?

If I have 3 synchronized video clips and I want to cycle between them on a periodic basis, is there a more elegant way to do this than a very long list of unalignedsplice'd trim statements?

Code:
source1=AVIsource("Test1.avi", audio = false, pixel_type = "YV12")
source2=AVIsource("Test2.avi", audio = false, pixel_type = "YV12")
source3=AVIsource("Test3.avi", audio = false, pixel_type = "YV12")

(source1.trim(0,499) + source2.trim(500,999) + source3.trim (1000,1499) + source1,trim(1500,1999) + ... )
This was the best I could come up with, which is better, but still a tad complicated as I have to generate the test.txt file.

Code:
source1=AVIsource("Test1.avi", audio = false, pixel_type = "YV12")
source2=AVIsource("Test2.avi", audio = false, pixel_type = "YV12")
source3=AVIsource("Test3.avi", audio = false, pixel_type = "YV12")

ConditionalSelect(source1, "(xyx_out==1) ? 0  : ((xyx_out==2) ? 1 : 2)",  source1, source2, source3, false)
ConditionalReader("test.txt", "xyx_out", false)
with a test.txt file that looks like:
Code:
Type int
Default 0

R 0 499 1
R 500 999 2
R 1000 1499 3
R 1500 1999 1
...
This seemed like a good start
Code:
source1=AVIsource("Test1.avi", audio = false, pixel_type = "YV12").selectrangeevery(1500,500,0)
source2=AVIsource("Test2.avi", audio = false, pixel_type = "YV12").selectrangeevery(1500,500,499)
source3=AVIsource("Test3.avi", audio = false, pixel_type = "YV12").selectrangeevery(1500,500,999)
but I can't figure out how to interleave the resulting three clips every 500 frames as the interleave filter doesn't allow an range interval to be specified and only works on a per frame basis

Is there some cleaner/easier solution I'm missing? (I'm using AVIsynth+ if it matters)
Stereodude is offline   Reply With Quote
Old 5th January 2019, 03:27   #2  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Maybe some looping with GScript?
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 5th January 2019, 05:02   #3  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,377
another hackish way is to use a mask to control visibility of a layer


rough script, proof of concept

Code:
length=500

r=blankclip(length=10000, color=color_red).showframenumber()
g=blankclip(length=10000, color=color_green).showframenumber()
b=blankclip(length=10000, color=color_blue).showframenumber()

black=blankclip(r).trim(0,length-1)
white=blankclip(r,color=color_white).trim(0,length-1)

white+black+black
loop(1000) #should calculate, but big loop# for testing now
wbb_loop=last

black+black+white
loop(1000) #should calculate, but big loop# for testing now
bbw_loop=last

gr=overlay(g,r,mask=wbb_loop)

overlay(gr,b , mask=bbw_loop)
needs cleanup:

-you need to replace the r,g,b with a,b,c avisource() or real source filter, but blankclip should take on the characteristics of the "a" clip)

-there is probably a smarter way to calcuate the length, like a.length*3 for 3* frames, to replace the loop() command

-remember to make the mask layers fullrange if using YUV, YUV sources

-maybe masktools mask (mt_merge) better way to control visibility, it's supposed to be faster processing, but not sure of current benchmarks in avs+
poisondeathray is offline   Reply With Quote
Old 5th January 2019, 05:19   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by Groucho2004 View Post
Maybe some looping with GScript?
this seems to work-ish
Code:
LEN=10000
BLKSZ=10         # Set to 500
A=BlankClip(Length=LEN,Pixel_type="YV12",COLOR=$FF0000).ShowFrameNumber
B=BlankClip(Length=LEN,Pixel_type="YV12",COLOR=$00FF00).ShowFrameNumber
C=BlankClip(Length=LEN,Pixel_type="YV12",COLOR=$0000FF).ShowFrameNumber

BLKS = Min(A.FrameCount,B.FrameCount,C.FrameCount) / BLKSZ

Z = A.BlankClip(Length=0)

for(n=0,BLKS-1) {
    M = n % 3
    Z = Z ++ (M==0?A:M==1?B:C).Trim(n*BLKSZ,-BLKSZ)
}

Return Z
EDIT: No attempt to make it play nice at end of clip [based on shortest clip, may be truncated].
EDIT: Not sure if I remember that stickboy has an InterLeaveEvery() type function.
EDIT: YES he does, here (In the ApplyEvery plugin):- http://www.avisynth.nl/users/stickboy/
__________________
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; 5th January 2019 at 11:49.
StainlessS is offline   Reply With Quote
Old 7th January 2019, 02:39   #5  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Thanks for the replies and suggestions guys. I need to take a closer look at some of them.
Stereodude is offline   Reply With Quote
Old 7th January 2019, 18:05   #6  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
I ended up taking a slight different tack for my task. I wanted to make a script that compared the original source with my post processed version. After trying my original idea cycling between three different static side by side comparison views I decided to try something I thought would be better.

Your scripts gave me the basic template to modify. I would have never gotten to what I wanted without your templates showing me what was possible. So, a big thank you to you guys!

Now I just need the bug I discovered in AVIsynth+ fixed. (The script crashes if LEN is too large and for this to work in a single script needs to be the same as LEN2)
Code:
LEN2=103848
LEN=15900
A=BlankClip(Length=LEN2, height=786, width=1920, Pixel_type="YV12",COLOR=$FF0000).ShowFrameNumber
B=BlankClip(Length=LEN2, height=786, width=1920, Pixel_type="YV12",COLOR=$00FF00).ShowFrameNumber

Z = A.BlankClip(Length=0)
frame=0

while( frame < LEN) {
for(n=2, 958, 2) {
	Z = Z ++ stackhorizontal(stackhorizontal(A.crop(0,0,n,-0),B.crop(n,0,960,-0)),A.crop(960+n,0,-0,-0)).trim(frame,end=frame)
	frame = frame + 1
	if ( frame == LEN) { Return Z }
}

for(n=958, 2, -2) {
	Z = Z ++ stackhorizontal(stackhorizontal(A.crop(0,0,n,-0),B.crop(n,0,960,-0)),A.crop(960+n,0,-0,-0)).trim(frame,end=frame)
	frame = frame + 1
	if ( frame == LEN) { Return Z }
}
}

Return Z
Stereodude is offline   Reply With Quote
Old 7th January 2019, 18:34   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I doubt that its a problem in avs+, me guesses that it is your very mysterious script that is the problem.

Can you put into words what it is that its intended to do.
__________________
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 7th January 2019, 18:51   #8  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 1,436
Quote:
Originally Posted by StainlessS View Post
I doubt that its a problem in avs+, me guesses that it is your very mysterious script that is the problem.

Can you put into words what it is that its intended to do.
Well, you could run it and see. The sample script I posted is completely self-contained and shows the crashing issue. It is not dependent on any external files.

But, the idea is to have a 960 pixel wide window that slides left and right bouncing between the two edges of the complete frame that has a window to the original source in it. The rest of the video frame contains the post processed version. It's like a moving before / after split screen.

The script crashes depending on the length of the while loop and the limit isn't hard or exact. The limit changes a little bit depending on the program loading the script.
Stereodude is offline   Reply With Quote
Old 9th January 2019, 18:23   #9  |  Link
Frank62
Registered User
 
Join Date: Mar 2017
Location: Germany
Posts: 234
After a bit thinking, I found this:
First mix up, then "rotate" one frame, and select back, what you want:

v=interleave(a,b,c)
v=selectrangeevery(v,1501,1500,0)
v=selectevery(v,3,0)

Unfortunately you will miss one frame with each "rotation", but I am sure there is a solution for this.
Frank62 is offline   Reply With Quote
Reply


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 11:17.


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