View Full Version : how join 3 clips by lines to get tripple height clip
Terka
31st March 2010, 16:53
similar to weave() but for 3 clips.
is gscript needed?
Didée
31st March 2010, 18:13
Finally someone asks that question!
For YV12, weaving 3 (or more) clips is at least problematic ... perhaps inpossible. Smells like a only-YUY2-or-RGB operation.
Gavino
31st March 2010, 19:12
Yes, I think this only makes sense for RGB or YUY2. It could be done with GScript, applying Crop and StackVertical in a loop to build up the result 3 lines at a time. But I think this would be quite slow (see here where something similar was done).
A better way would be to PointResize each clip to 3*height and Overlay them with appropriate masks.
Didée
31st March 2010, 19:47
A better way would be to PointResize each clip to 3*height and Overlay them with appropriate masks.
That's what I would had thought of, too.
Also, -correcting myself- there shouldn't be a technical problem with YV12 footage. It's all just samples, and those samples surely can be interleaved. The result wouldn't make much sense visually, because the chroma samples would be interpreted wrongly upon display. But for purposes of intermediate processing, followed by separating back to original state, it should work.
___
Related, I found something in the deep dark dungeons of my HDDs: a weaveS() plugin. :)
It probably has been done by MarcFD, I'm not sure. There is zero documentation for the plugin.
Link: weaveS.dll (http://www.mediafire.com/file/jmmnrwduwgl/weaveS.dll)
Example usage:
LoadPlugin("weaveS.dll")
orig = colorbars().converttoyuy2()
c1 = orig.addborders(0,0,0,8) # !! Using addborders because weaveS will throw away the last line for some clips !!
c2 = c1.levels(0,1.0,255,0,128,false)
c3 = c1.levels(0,1.0,255,128,255,false)
interleave(c1,c2,c3)
weaveS_weave(last, 3) # 3 clips have been interleaved
first = extract(0,3) .crop(0,0,orig.width,orig.height) # undo the addborders again
secnd = extract(1,3) .crop(0,0,orig.width,orig.height)
third = extract(2,3) .crop(0,0,orig.width,orig.height)
interleave(first,secnd,third)
return(last)
It works, but performance is a bit strange. Long loading time for the script, and weaveS seems to allocate quite some memory (~128 MB, from Taskmanager). Fps during rendering are fluctuating. Don't ask me, I dunno. It humples, but it works.
niiyan
1st April 2010, 15:18
The multi-line weave was written by kassandro.
WeaveS is Statically linked version of the plugin.
Download link and usage of the plugin is here: http://forum.doom9.org/showthread.php?s=&postid=519251#post519251
pbristow
5th April 2010, 10:32
Here's an idea:
w = width(Clip1)
h = height(Clip1)
Pair1 = Interleave(Clip1, Clip3).Weave
Pair2 = Interleave(Clip2, Clip3).Weave
QuadHeight = Interleave(Pair1, Pair2).Weave # Line sequence is Clip1, Clip2, Clip3, Clip3, repeating.
TripleHeight = PointResize(QuadHeight, w, h*3)
:)
(You might need to adjust the offset to get the right 3 out of every 4 lines coming out of PointResize.)
Gavino
5th April 2010, 11:40
Nice one, pbristow, I think you've cracked it.
You might need to adjust the offset to get the right 3 out of every 4 lines coming out of PointResize.
For RGB, you need an offset of -1 to compensate for it being processed 'upside-down', ie
TripleHeight = PointResize(QuadHeight, w, h*3, 0, -1)
You also need AssumeFieldBased().AssumeTFF() between each Interleave and Weave, eg
Pair1 = Interleave(Clip1, Clip3).AssumeFieldBased().AssumeTFF().Weave
pbristow
6th April 2010, 13:45
You're too kind. :)
The extra "Clip3" above can in fact be any dummy clip, since all its lines are just going to be thrown away at the end. Using something like BlankClip(-whatever-) might help with debugging the script.
The method should be easily generalisable, too: To weave n lines, you just nead to weave pairs in the right sequence up to m = 2^i lines, where m is big enough to accomodate n, by adding as many dummy clips as needed (they can all be the same, of course; The main obstacle is to take care where you put the dummy clips in the sequence, so that when you pointresize the result downwards it throws away the correct clips. (The easiest cases to figure out are those just one below a power of two.)
PitifulInsect
12th March 2011, 16:39
pbristow - very clever, thank you! So clever that I need to also thank Gavino for pointing me at it!
I've used that trick to help with interleaving / de-interleaving 3-channel data over here:
http://forum.doom9.org/showthread.php?p=1403600
For the benefit of others, the following will leave you with Red, Green, and Blue 3-woven together:
RiBiGiA = Interleave(Red, Blue, Green, Alpha)
RBiGA = RiBiGiA.AssumeFieldBased().AssumeTFF().Weave()
RGBA = RBiGA.AssumeFieldBased().AssumeTFF().Weave()
RGB = PointResize(RGBA, RGBA.Width(), RGBA.Height()*3/4)
#RGB holds the 3-woven result.
...and the following will de-weave it again:
#RGB holds a 3-woven clip.
RRGB = PointResize(RGB, RGB.Width(), RGB.Height()*4/3)
RGiRB = RRGB.AssumeFrameBased().AssumeTFF().SeparateFields()
RiGiRiB = RGiRB.AssumeFrameBased().AssumeTFF().SeparateFields()
red = RiGiRiB.SelectEvery(4,0)
green = RiGiRiB.SelectEvery(4,1)
blue = RiGiRiB.SelectEvery(4,3)
For some other numbers of PointResize manipulations, here you go!:
PointResize 2/3 width turns 123 into 12
PointResize 3/4 width turns 1234 into 123
PointResize 2/5 width turns 12345 into 13
PointResize 3/5 width turns 12345 into 124
PointResize 4/5 width turns 12345 into 1234
PointResize 5/6 width turns 123456 into 12345
PointResize 2/7 width turns 1234567 into 14
PointResize 3/7 width turns 1234567 into 135
PointResize 4/7 width turns 1234567 into 1246
PointResize 5/7 width turns 1234567 into 12356
PointResize 6/7 width turns 1234567 into 123456
PointResize 3/2 width turns 12 into 112
PointResize 5/2 width turns 12 into 11122
PointResize 7/2 width turns 12 into 1111222
PointResize 4/3 width turns 123 into 1123
PointResize 5/3 width turns 123 into 11223
PointResize 7/3 width turns 123 into 1112233
PointResize 5/4 width turns 123 into 11234
PointResize 7/4 width turns 123 into 1122334
If anyone wants to experiment themselves, I've attached a simple test script that I made for looking at the results to save you time. Cheers!
Gavino
12th March 2011, 18:02
the following will leave you with Red, Green, and Blue 3-woven together:
RiBiGiA = Interleave(Red, Blue, Green, Alpha)
RBiGA = RiBiGiA.AssumeFieldBased().AssumeTFF().Weave()
RGBA = RBiGA.AssumeFieldBased().AssumeTFF().Weave()
RGB = PointResize(RGBA, RGBA.Width(), RGBA.Height()*3/4)
#RGB holds the 3-woven result.
It's worth noting that this assumes the 4 input clips (Red, Blue, Green and Alpha) are YUV (as they are in your linked thread, where you used ShowRed("YV12"), etc). For RGB inputs, a vertical offset of -1 would be required, as I explained in post#7.
Terka
20th January 2012, 17:49
how go back from
TripleHeight to 3 independent clips?
Gavino
20th January 2012, 18:40
how go back from
TripleHeight to 3 independent clips?
tripleHeight
clip1 = PointResize(width, height/3, 0, 0)
clip2 = PointResize(width, height/3, 0, 1)
clip3 = PointResize(width, height/3, 0, 2)
If dealing with an RGB clip, replace the final 0, 1, 2 by -2, -1, 0 respectively.
Terka
20th January 2012, 22:26
dealing with yv12, but after dividing by 3, it divides by more than 3.
in my clip tripleheight is 960 pixels but
tripleHeight.PointResize(width, height/3, 0, 0) is too small
maybe
tripleHeight.PointResize(width, height/1, 0, 0)
is correct?
Didée
20th January 2012, 22:41
Maybe you should rather write
tripleHeight
PointResize(width, height/3, 0, 0)
since width & height are last.width() & last.height().
In your one-liner, you (probably) had another clip stored in "last", which didn't have triple height.
Or just write it the verbose way
tripleHeight.PointResize(tripleHeight.width(), tripleHeight.height()/3, 0, 0)
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.