View Full Version : adaptation YV12 input plugin for YUY2 source
yup
12th February 2013, 10:50
Hi all!
I frequently use NLMeansCL plugin for my VHS capture source, but this plugin do not support YUY2 colorspace. I write simple script for adaptation, but sure that new colorspace from 2.6 can make this better
SetMemoryMax(2048)
SetmtMode(3,8)
AVISource("tape1.avi").Trim(0,83195)# interlaced
AssumeTFF()
SetmtMode(2,8)
Separatefields()
U=UToY().ConvertToYV12()
V=VToY().ConvertToYV12()
Y=ConvertToYV12()
SetmtMode(5,8)
Yf=Y.NLMeansCL(h=3, plane=0)
Uf=U.NLMeansCL(h=5, plane=0)
Vf=V.NLMeansCL(h=5, plane=0)
SetmtMode(2,8)
YToUV (ConvertToYUY2(Uf),ConvertToYUY2(Vf),ConvertToYUY2(Yf))
Weave()
Please advice.
yup.
jmac698
12th February 2013, 19:00
# Replacement code for YUY2<->YV12 conversions in v2.58
function YV12ToYUY2(clip c, bool "interlaced") {
interlaced = Default(interlaced, false)
interlaced ? c.YV12ToYUY2i() : c.YV12ToYUY2p()
}
function YUY2ToYV12(clip c, bool "interlaced") {
interlaced = Default(interlaced, false)
interlaced ? c.YUY2ToYV12i() : c.YUY2ToYV12p()
}
# ------- Support functions --------
function YV12ToYUY2p(clip c) {
U = c.UToY().BilinearResize(c.width/2, c.height).ConvertToYUY2()
V = c.VToY().BilinearResize(c.width/2, c.height).ConvertToYUY2()
YToUV(U, V, c.ConvertToYUY2()) #crashes on v2.60
}
function YV12ToYUY2i(clip c) {
f = c.AssumeTFF().SeparateFields()
top = f.SelectEven()
bot = f.SelectOdd()
topU = top.UToY().BilinearResize(c.width/2, c.height/2, 0, 0.125)
botU = bot.UToY().BilinearResize(c.width/2, c.height/2, 0, -0.125)
U = Interleave(topU, botU).ConvertToYUY2()
topV = top.VToY().BilinearResize(c.width/2, c.height/2, 0, 0.125)
botV = bot.VToY().BilinearResize(c.width/2, c.height/2, 0, -0.125)
V = Interleave(topV, botV).ConvertToYUY2()
YToUV(U, V, f.ConvertToYUY2()).Weave() #crashes on v2.60
}
function YUY2ToYV12p(clip c) {
U = c.UToY().BilinearResize(c.width/2, c.height/2).ConvertToYV12()
V = c.VToY().BilinearResize(c.width/2, c.height/2).ConvertToYV12()
YToUV(U, V, c.ConvertToYV12())
}
function YUY2ToYV12i(clip c) {
f = c.AssumeTFF().SeparateFields()
top = f.SelectEven()
bot = f.SelectOdd()
topU = top.UToY().BilinearResize(c.width/2, c.height/4, 0, -0.25)
botU = bot.UToY().BilinearResize(c.width/2, c.height/4, 0, 0.25)
U = Interleave(topU, botU).ConvertToYV12()
topV = top.VToY().BilinearResize(c.width/2, c.height/4, 0, -0.25)
botV = bot.VToY().BilinearResize(c.width/2, c.height/4, 0, 0.25)
V = Interleave(topV, botV).ConvertToYV12()
YToUV(U, V, f.ConvertToYV12()).Weave()
}
ref
http://forum.doom9.org/archive/index.php/t-147629.html
I don't know why someone took this off the wiki, it's very useful.
IanB
12th February 2013, 22:10
Main savings are in the *ToY8() zero cost plane snatches. YUY2 to/from YV16 is very fast MMX same as a blit. Pity you need YV12 for the 2.5 NLMeanCL's, costs Luma Blits plus Chroma Fills, a 2.6 Y8 aware version would avoid these. YtoUV and Weave still cost a Blit. And there are no 3 by YV12 to YUY2 converts.AVISource("tape1.avi").Trim(0,83195)# interlaced
AssumeTFF() # Zero cost
Separatefields() # Zero cost
ConvertToYV16() # Fast Shuffle cost
U=UToY8().ConvertToYV12() # Zero + Luma Blit + Chroma Fill cost
V=VToY8().ConvertToYV12() # Zero + Luma Blit + Chroma Fill cost
Y=ConvertToY8().ConvertToYV12() # Zero + Luma Blit + Chroma Fill cost
Yf=Y.NLMeansCL(h=3, plane=0)
Uf=U.NLMeansCL(h=5, plane=0)
Vf=V.NLMeansCL(h=5, plane=0)
YToUV (Uf, Vf, Yf) # YV16 Blit cost
Weave() # YV16 Blit cost
ConvertToYUY2() # Fast Shuffle cost
06_taro
13th February 2013, 02:23
Then a version for both avs 2.5 & 2.6 (still does not consider YUY2<->YV12 CUE/ICP):
interlaced = True
interlaced ? AssumeTFF().Separatefields() : NOP()
Try {
ConvertToYV16()
U = UToY8()
V = VToY8()
Y = ConvertToY8()
} Catch(e) {
}
U = U.ConvertToYV12()
V = V.ConvertToYV12()
Y = Y.ConvertToYV12()
Yf = Y.YPlaneFilter()
Uf = U.YPlaneFilter()
Vf = V.YPlaneFilter()
YToUV(Uf, Vf, Yf)
interlaced ? Weave() : NOP()
ConvertToYUY2()
yup
14th February 2013, 17:33
06_taro & IanB :thanks: for suggestion!
Work faster than my script especially for fast settings NLMeansCL.
yup.
kolak
19th February 2013, 02:23
Hmm- can this be used with interframe, which works only in YV12?
Typical scenario for me is deinterlacing with yadifmod (so this can stay in YUY2) and than output from this goes to interframe.
To complicated for me- thanks in advance.
yup
19th February 2013, 04:32
kolak!
IMO no. I am use NLMEansCL like 2D static filter. Because interframe make motion estimation and compensation. If You will make separate on luma and chroma plane and after merge result will be wrong, but may be impressive.
yup.
kolak
19th February 2013, 12:42
That's what I was thinking- thanks.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.