View Full Version : How to process RGBA source with YV12 only filters?
pancserzso
8th October 2013, 04:35
I have a computer generated RGBA image sequence. I would like to process this with filters (for eg. removegrain), which only support planar color spaces.
Is there any way for Avisynth to process an RGBA source as 4 separate channels? I mean I'm thinking about either 4 x Y8 channels or 4 x YUV channels with UV being empty. Is it possible to make Avisynth process like this?
How is this normally solved?
poisondeathray
8th October 2013, 05:46
A hackish way might be to showred,showgreen, showblue and converttoyv12 (pc matrix), then filter, converttorgb (pc matrix), then mergeargb() .
Or you can use RGB filters , or maybe some other programs that have RGB filters
e.g
main=WhateverSource()
main
showred()
converttoyv12(matrix="pc.601")
##Your FILTERS HERE
converttorgb(matrix="pc.601")
r=last
main
showblue()
converttoyv12(matrix="pc.601")
##Your FILTERS HERE
converttorgb(matrix="pc.601")
b=last
main
showgreen()
converttoyv12(matrix="pc.601")
##Your FILTERS HERE
converttorgb(matrix="pc.601")
g=last
main
showalpha()
a=last
mergeargb(a,r,g,b)
IanB
8th October 2013, 06:20
The ShowRed (http://avisynth.nl/index.php/ShowRed), Green, Blue and Alpha filters accept an optional output pixel type argument. For YV12 the respective colour channels byte value is copied into the Luma channel (so are PC levels), the chroma channels are set to grey, 128. The merge filter accepts any input pixel type and steers the appropriate data to the output frame.
main=WhateverSource()
main.showred("YV12")
##Your FILTERS HERE
r=last
main.showblue("YV12")
##Your FILTERS HERE
b=last
main.showgreen("YV12")
##Your FILTERS HERE
g=last
main.showalpha("Y8")
a=last
mergeargb(a,r,g,b)
Yellow_
8th October 2013, 08:16
Dither Tools is another option for RGB as 'fake' YCC if a 16bit route is considered useful.
Forensic
9th October 2013, 05:33
IanB & poisondeathray, What a clever idea. My AvsPmod master script is well over 100k of code, and certain filter configurations force RGB -> YV12 -> RGB -> YV12.... conversion chains. Implementing your idea will help to eliminate most of my conversion losses. I never cease to be amazed by the combined brain power of the Avisynth community.
pancserzso
15th October 2013, 01:05
Thanks a lot!
I was able to modify my script which didn't work on RGB before using this workflow. BTW, is it possible to split and merge to YV24 in the same way? Some filters are really buggy on YV24.
Also, IanB, why is it Y8 for alpha while it's YV12 for other channels? Shouldn't all of them be Y8 if that mode is supported?
poisondeathray
15th October 2013, 01:15
Probably because the filters that you are using that require YV12, won't work in Y8. (And presumably you're not filtering the alpha channel)
You can probably split YV24 using UtoY, VtoY then back using YtoUV
http://avisynth.nl/index.php/Swap
pancserzso
15th October 2013, 01:18
(And presumably you're not filtering the alpha channel)
OK, I see, that was the idea behind it. Actually the filtering of alpha really depends on the workflow.
poisondeathray
15th October 2013, 01:30
maybe something like this
# yv24 source, or converttoyv24(matrix=...)
main=last
main
greyscale
#converttoyv12(matrix=..) if you need YV12 filters
#Y filters here
y=last
main
utoy
#converttoyv12(matrix=..) if you need YV12 filters
#U filters here
u=last
main
vtoy
#converttoyv12(matrix=..) if you need YV12 filters
#V filters here
v=last
ytouv(u,v)
mergeluma(y)
pancserzso
15th October 2013, 01:53
Thanks a lot. Just for the reference, I've posted my final script and RGB -> R,G,B -> PNG sequence workflow in this post:
http://forum.doom9.org/showthread.php?p=1647915#post1647915
pancserzso
15th October 2013, 02:06
An interesting point, can this be done losslessly? I would think that a simple split and merge should be lossless.
The only troubling point I can think about is the 16-235 conversion, but it can be avoided by using 0-255 if it's not using that by default. Please correct me if I'm wrong, but I really think this is lossless:
... script
ImageWriter(file="a",type="png")
main=last
main.showred("YV12")
r=last
main.showblue("YV12")
b=last
main.showgreen("YV12")
g=last
mergergb(r,g,b, "RGB24")
ImageWriter(file="b",type="png")
Update: just validated, the two files are binary same!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.