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 18th May 2014, 21:03   #1  |  Link
Marin85
Registered User
 
Join Date: Oct 2010
Posts: 100
lossless YV12-RGB48-YV12 conversion?

Hi,

I read a while ago a vague comment somewhere that it's possible to have lossless YV12-to-RGB48-back-to-YV12 conversion in Avisynth since RGB48 supposedly gives enough precision for this. Does one use dithertools (because of RGB48) or something else? I have tried following script:
Code:
dss2("HD_clip.mkv")
Dither_convert_yuv_to_rgb (output="rgb48y")
r = SelectEvery (3, 0)
g = SelectEvery (3, 1)
b = SelectEvery (3, 2)
Dither_convert_rgb_to_yuv (r, g, b, lsb=false, mode=0)
However direct pixel comparison still reveals some (minor) differences to the source.
Marin85 is offline   Reply With Quote
Old 18th May 2014, 22:08   #2  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Hi Marin85,

Are you referring to this thread, specifically this post?
Reel.Deel is offline   Reply With Quote
Old 18th May 2014, 22:17   #3  |  Link
Marin85
Registered User
 
Join Date: Oct 2010
Posts: 100
Quote:
Originally Posted by Reel.Deel View Post
Hi Marin85,

Are you referring to this thread, specifically this post?
Hi Reel.Deel,

no, that is definitely not it, and I am pretty sure it was mentioning RGB48 specifically. Sadly, I don't remember the link anymore (I am not even sure it was on doom9).
Marin85 is offline   Reply With Quote
Old 18th May 2014, 22:26   #4  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Regarding the script you posted, shouldn't this be a bit more correct? (I'm not completely sure either):

Code:
# Source (YV12 with MPEG2 chroma placement)

ConvertToYV24(chromaresample="point")
MergeChroma(PointResize(width, height, src_left=0, src_top=1))

Dither_convert_yuv_to_rgb (matrix="709", tv_range=true, output="rgb48y") # matrix and tv_range are of course source dependent. 

r = SelectEvery (3, 0)
g = SelectEvery (3, 1)
b = SelectEvery (3, 2)

Dither_convert_rgb_to_yuv (r, g, b, matrix="709", tv_range=true, cplace="MPEG2", chromak="point", lsb=false, mode=0, output="YV12") # Output is 8-bit YV12

Last edited by Reel.Deel; 18th May 2014 at 22:41.
Reel.Deel is offline   Reply With Quote
Old 18th May 2014, 23:06   #5  |  Link
Marin85
Registered User
 
Join Date: Oct 2010
Posts: 100
Thanks for your comment! Reading dither tools docu, I noticed the option about the chroma placement, but I did not know which configuration my H.264 encoded YV12 input file uses, so I left that out. The matrix and tv range setting default to the correct ones, though. I will give your script a try.

EDIT: I gave Gavino's script from the link and your script above a try, both give much better results than before. I was able to find a difference only in the dark red range, where your script with dither tools also seems to get the edge over Gavino's (at least statistically).

Last edited by Marin85; 18th May 2014 at 23:27.
Marin85 is offline   Reply With Quote
Old 19th May 2014, 00:22   #6  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Good to know it's working. Out of curiosity how are you viewing the difference?
Reel.Deel is offline   Reply With Quote
Old 19th May 2014, 00:28   #7  |  Link
Marin85
Registered User
 
Join Date: Oct 2010
Posts: 100
Quote:
Originally Posted by Reel.Deel View Post
Out of curiosity how are you viewing the difference?
Nothing fancy, just comparing lots of randomly picked pixels to see if the color values match or not :-)

I am still wondering though if there is in fact a way to have a completely lossless conversion back and forth between YV12 and RGB.
Marin85 is offline   Reply With Quote
Old 19th May 2014, 11:14   #8  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
obviously, "mode=0" is not lossless
u may give "mode=-1" (rounding) a try
feisty2 is offline   Reply With Quote
Old 19th May 2014, 13:07   #9  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
Quote:
Originally Posted by Marin85 View Post
Nothing fancy, just comparing lots of randomly picked pixels to see if the color values match or not :-)
Yeah I use Subtract(a,b).Levels(122,1,132,0,255) <-- pretty primitive I know . I wonder if there's a more accurate way to check the difference?

Quote:
I am still wondering though if there is in fact a way to have a completely lossless conversion back and forth between YV12 and RGB.
Would be nice to have a conclusive answer.
IIRC I read somewhere that YUV<-->RGB conversion needs at least 10-bits to be lossless.

-------------
Quote:
Originally Posted by feisty2 View Post
obviously, "mode=0" is not lossless
u may give "mode=-1" (rounding) a try
Technically, any mode used is not lossless. Dithering back to 8-bits will always add something to the original, hence not lossless.
Reel.Deel is offline   Reply With Quote
Old 19th May 2014, 13:24   #10  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by Reel.Deel View Post
Technically, any mode used is not lossless. Dithering back to 8-bits will always add something to the original, hence not lossless.
u can have a try on "mode=-1", and see the result urself, converting yv12 to rgb24 then back to yv12 with "pointresize" + "rounding" is totally lossless
rounding is not dithering, so sometimes it can be lossless
as for "at least 10bits" stuff, it's only true if your source is rgb24, here we talk about yv12-rgb-yv12 conversion, not rgb-yuv conversion

Last edited by feisty2; 19th May 2014 at 14:06.
feisty2 is offline   Reply With Quote
Old 19th May 2014, 15:24   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
This is what I use to show clip difference, 8 bit ony but could probably be easily modded for 16 bit.
Code:
# Return Clip Difference of input clips (amp==true = Amplified, show==true = show background)
Function ClipDelta(clip clip1,clip clip2,bool "amp",bool "show") {
	amp=Default(amp,false)
	show=Default(show,false)
	c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
	c1=clip1.subtract(clip2)
	c1=(amp)?c1.levels(127,1.0,129,0,255):c1
	return (show)?c1.Merge(c2):c1
}
AMP, Amplified, self explanatory.
Show, shows a dimmed representaion of the frame, (best used with AMP) so you can see exactly where the differences are.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 19th May 2014 at 15:28.
StainlessS is offline   Reply With Quote
Old 20th May 2014, 15:53   #12  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
YV12 <-> RGB conversions are not lossless whatever the bitdepth, unless you’re resampling the chroma planes with a specific kernel in order to make YV12 -> RGB -> YV12 lossess, but this may reduce the overall quality of each conversion.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes 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 10:24.


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