View Full Version : lossless YV12-RGB48-YV12 conversion?
Marin85
18th May 2014, 21:03
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:
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.
Reel.Deel
18th May 2014, 22:08
Hi Marin85,
Are you referring to this thread (http://forum.doom9.org/showthread.php?t=164737), specifically this post (http://forum.doom9.org/showpost.php?p=1571388&postcount=19)?
Marin85
18th May 2014, 22:17
Hi Marin85,
Are you referring to this thread (http://forum.doom9.org/showthread.php?t=164737), specifically this post (http://forum.doom9.org/showpost.php?p=1571388&postcount=19)?
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).
Reel.Deel
18th May 2014, 22:26
Regarding the script you posted, shouldn't this be a bit more correct? (I'm not completely sure either):
# 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
Marin85
18th May 2014, 23:06
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).
Reel.Deel
19th May 2014, 00:22
Good to know it's working. Out of curiosity how are you viewing the difference?
Marin85
19th May 2014, 00:28
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.
feisty2
19th May 2014, 11:14
obviously, "mode=0" is not lossless
u may give "mode=-1" (rounding) a try
Reel.Deel
19th May 2014, 13:07
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?
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.
-------------
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.
feisty2
19th May 2014, 13:24
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
StainlessS
19th May 2014, 15:24
This is what I use to show clip difference, 8 bit ony but could probably be easily modded for 16 bit.
# 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.
cretindesalpes
20th May 2014, 15:53
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.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.