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 8th October 2013, 04:35   #1  |  Link
pancserzso
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.
pancserzso is offline   Reply With Quote
Old 8th October 2013, 05:46   #2  |  Link
poisondeathray
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)
poisondeathray is offline   Reply With Quote
Old 8th October 2013, 06:20   #3  |  Link
IanB
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)
IanB is offline   Reply With Quote
Old 8th October 2013, 08:16   #4  |  Link
Yellow_
Registered User
 
Join Date: Sep 2009
Posts: 378
Dither Tools is another option for RGB as 'fake' YCC if a 16bit route is considered useful.
Yellow_ is offline   Reply With Quote
Old 9th October 2013, 05:33   #5  |  Link
Forensic
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.
Forensic is offline   Reply With Quote
Old 15th October 2013, 01:05   #6  |  Link
pancserzso
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?
pancserzso is offline   Reply With Quote
Old 15th October 2013, 01:15   #7  |  Link
poisondeathray
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.
poisondeathray is offline   Reply With Quote
Old 15th October 2013, 01:18   #8  |  Link
pancserzso
Registered User
 
Join Date: Oct 2004
Posts: 131
Quote:
Originally Posted by poisondeathray View Post
(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.
pancserzso is offline   Reply With Quote
Old 15th October 2013, 01:30   #9  |  Link
poisondeathray
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)
poisondeathray is offline   Reply With Quote
Old 15th October 2013, 01:53   #10  |  Link
pancserzso
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
pancserzso is offline   Reply With Quote
Old 15th October 2013, 02:06   #11  |  Link
pancserzso
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")
Update: just validated, the two files are binary same!

Last edited by pancserzso; 15th October 2013 at 02:16.
pancserzso 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 09:32.


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