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. |
8th October 2013, 04:35 | #1 | Link |
Registered User
Join Date: Oct 2004
Posts: 131
|
How to process RGBA source with YV12 only filters?
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? Last edited by pancserzso; 8th October 2013 at 04:38. |
8th October 2013, 05:46 | #2 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
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 Code:
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) |
8th October 2013, 06:20 | #3 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
The 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.
Code:
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) |
9th October 2013, 05:33 | #5 | Link |
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
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.
|
15th October 2013, 01:05 | #6 | Link |
Registered User
Join Date: Oct 2004
Posts: 131
|
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? |
15th October 2013, 01:15 | #7 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
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 Last edited by poisondeathray; 15th October 2013 at 01:19. |
15th October 2013, 01:30 | #9 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
maybe something like this
Code:
# 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) |
15th October 2013, 01:53 | #10 | Link |
Registered User
Join Date: Oct 2004
Posts: 131
|
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.ph...15#post1647915 |
15th October 2013, 02:06 | #11 | Link |
Registered User
Join Date: Oct 2004
Posts: 131
|
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: Code:
... 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") Last edited by pancserzso; 15th October 2013 at 02:16. |
|
|