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. |
2nd October 2015, 05:50 | #1 | Link |
Registered User
Join Date: Apr 2008
Posts: 19
|
Enconding in 444 YV24 from RGB source Avisynth.
I color graded a m2ts episode from a BD I own on Premiere CS6. Only truly lossless export Option I had was mov with animation codec (RLE).
Now, I wanted to convert to a lossless x264 file (qp0 preset slow) with 4:4:4 subsampling. I'm truly lost as how to effectively generate a qp0 x264 file with the less possible loss in color acurancy. I understand that a 100% lossless RGB->YV24 conversion isn't possible, but all the attempts I made so far seem to give me a file that was converted to 4:2:0 at some point. Initially I tried inputing the file directly on x264.exe CLI, but I didn't figure out how to make the mov file acceptable by x264 (and even if it is). --input-fmt uses lav filter, right? Should it be configured as default spliter on windows for this parameter to work? My default filter is ffdshow. Then I heard Avisynt version 2.60 now accepts YV24 output format, but I'm not sure, the regular version do or just some beta build? Anyway, I just added ConvertToYV24 on avs script and encoded with megui with the following settings: program --preset slower --qp 0 --b-pyramid none --no-weightb --qpmax 51 --merange 24 --psy-rd 0.00:0 --no-dct-decimate --no-fast-pskip --output-csp i444 --output "output" "input" I manually added the output-csp i444 line. This generated me a true 444 output file but the colors seems just like 420. I suspect avisynth is indeed outputting 420. I further tought about exporting a TIF image sequence from Premiere and trying to feed it into x264.exe directly but I have no idea how to do that. After a lot of reading around Doom's9 and other websites, I also saw people saying that I should specify the input color space for encoding on x264. Original m2ts was Rec.709 limited range, the RGB conversion on Premiere seemed to be fully lossless as the output mov files looks identical to the original 4:2:0 m2ts file. So should I just specify Rec 709 anyway? I'm not even sure this should be in the avisynth section or x264 section. Thanks a lot. Last edited by sephirotic; 2nd October 2015 at 05:59. |
2nd October 2015, 07:23 | #3 | Link | |
Registered User
Join Date: Apr 2008
Posts: 19
|
Quote:
I discovered why Avisynth wasn't converting properly, even tough the input was RGB, I still should have specified the matrix: ConvertToYV24 (matrix="rec709") By just adding the parameter I managed to get 100% lossless result. Thanks for the quick reply, tough. |
|
2nd October 2015, 08:41 | #5 | Link | |
/人 ◕ ‿‿ ◕ 人\
Join Date: May 2011
Location: Russia
Posts: 643
|
sephirotic,
Color being different is a different issue. For RGB->YCbCr conversion x264 uses BT.601 matrix, which is wrong for HD video. By default avisynth's ConvertTo uses it too, but it can and should be specified ("Rec709" is the correct one if you want tv-range video). Do you really need 4:4:4 YCbCr? x264 supports RGB encoding which is a bit less effective but way more convenient (and is actually lossless). Quote:
Of course it's lossless, under higher but still finite precision. |
|
2nd October 2015, 09:54 | #6 | Link | ||
Registered User
Join Date: Jul 2015
Posts: 768
|
Quote:
Then you added effects and wanted to make the movie lossless at x264. Quote:
Chroma sampling 4:4:4 (YUV i444) will be converted to 8bit sRGB monitor. ): BT2020 is for depth 10bit files and currently isn't recognized by most programs only TV. sRGB isn't recognized by most programs. Last edited by Jamaika; 2nd October 2015 at 10:03. |
||
2nd October 2015, 10:49 | #7 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
there's something called "Infinite decimal", which is a mathematic concept even known to kids from elementary school. and iirc, floats can do "finite decimals", not fractions edit: typo Last edited by feisty2; 2nd October 2015 at 10:54. |
2nd October 2015, 12:36 | #8 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
Yet but it's lossless like, as float precision is enough to get same values for 8bit RGB -> (16bit RGB) -> >9bit YUV -> (16bit RGB) -> 8bit RGB.
as IIRC you need about 9.6bit YUV to have all 8bit RGB values, ergo 10 or more bit.
__________________
powered by Google Translator |
2nd October 2015, 12:49 | #9 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
and YCgCo is free from all this at the mathematic level, no infinite decimal will be produced long as the input is not infinite decimal, and that's "mathematically" lossless |
|
2nd October 2015, 14:22 | #10 | Link | ||
/人 ◕ ‿‿ ◕ 人\
Join Date: May 2011
Location: Russia
Posts: 643
|
Quote:
Quote:
Code:
void RGBtoYCbCr (unsigned char* RGB, unsigned short* YCbCr) { YCbCr[0] = (unsigned short)(( 16.0 + 0.257 * RGB[0] + 0.504 * RGB[1] + 0.098 * RGB[2]) * 257.0 + 0.5); YCbCr[1] = (unsigned short)((128.0 - 0.148 * RGB[0] - 0.291 * RGB[1] + 0.439 * RGB[2]) * 257.0 + 0.5); YCbCr[2] = (unsigned short)((128.0 + 0.439 * RGB[0] - 0.368 * RGB[1] - 0.071 * RGB[2]) * 257.0 + 0.5); } void YCbCrToRGB (unsigned short* _YCbCr, unsigned char* RGB) { double YCbCr[3] = {_YCbCr[0] / 257.0 - 16.0, _YCbCr[1] / 257.0 - 128.0, _YCbCr[2] / 257.0 - 128.0}; RGB[0] = (unsigned char)(1.164 * YCbCr[0] + 0.000 * YCbCr[1] + 1.596 * YCbCr[2] + 0.5); RGB[1] = (unsigned char)(1.164 * YCbCr[0] - 0.392 * YCbCr[1] - 0.813 * YCbCr[2] + 0.5); RGB[2] = (unsigned char)(1.164 * YCbCr[0] + 2.017 * YCbCr[1] + 0.000 * YCbCr[2] + 0.5); } int _tmain(int argc, _TCHAR* argv[]) { for (int R = 0; R < 256; R++) for (int G = 0; G < 256; G++) for (int B = 0; B < 256; B++) { unsigned char RGB[3] = {R, G, B}; unsigned char newRGB[3]; unsigned short YCbCr[3]; RGBtoYCbCr (RGB, YCbCr); YCbCrToRGB (YCbCr, newRGB); if (newRGB[0] != RGB[0] || newRGB[1] != RGB[1] || newRGB[2] != RGB[2]) { printf ("%i %i %i %i %i %i\n", newRGB[0], RGB[0], newRGB[1], RGB[1], newRGB[2], RGB[2]); } } return 0; } |
||
2nd October 2015, 15:27 | #11 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
yeah, yeah
something is only lossless when you manually clip the extra imprecise "lsb" part (aka. error part) off, right, 0.123456 = 0.123000 when you zero the "456" lsb out and that is just mathematically lossless?? back to the point, it's lossless cuz you were rounding a short to a char, which almost never ever happens in the wild, cuz you know what? people will dither a short to a char, and boom, the lossless magic is gone with dithering, so you gonna tell everyone, just rounding 16bits YUV to 8bits RGB, don't dither? and I highly doubt if anyone will ever follow that advice and YCgCo is ALWAYS lossless, dithering or truncating or rounding, cuz you know what, it's mathematically lossless (it has no lsb (no error), so nothing to dither) Last edited by feisty2; 2nd October 2015 at 15:41. |
3rd October 2015, 03:08 | #13 | Link | ||||
Registered User
Join Date: Apr 2008
Posts: 19
|
Quote:
Quote:
Quote:
Quote:
Thanks for all the help, I was able to attain virtually imperceivable loss in color information just by using ConverTToYV24 (matrix="rec709") Here a sample to anyone curious. http://diff.pics/ssFVuuBc4Agi/1 Lossless in this case is qp0 veryslow no bframes x264 yv24 encode, but I'm in the middle of doing a RGB x264 encode right now as a V2. Last edited by sephirotic; 3rd October 2015 at 03:23. Reason: Missed quote mark |
||||
4th October 2015, 02:25 | #14 | Link | |
/人 ◕ ‿‿ ◕ 人\
Join Date: May 2011
Location: Russia
Posts: 643
|
Quote:
Second, you should really learn something about precision. 0.123 and 0.123000 have different meaning - second implies much greater precision. What original "0.123" actually means is that value lies in the +- 0.0005 range. And this is how you're supposed to compare numbers. But can't you encode from your x264 rgb master? |
|
4th October 2015, 03:21 | #15 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
I don't wanna waste my time on this pointless argument no more
Code:
colorbars (pixel_type="rgb32") ycgco = dither_convert_rgb_to_yuv (output="yv24",lsb=true,matrix="ycgco",tv_range=false) ycbcr = dither_convert_rgb_to_yuv (output="yv24",lsb=true,matrix="601",tv_range=false) rgb48ycgco = dither_convert_yuv_to_rgb (ycgco, output="rgb48y",matrix="ycgco",tv_range=false,lsb_in=true) rgb48ycbcr = dither_convert_yuv_to_rgb (ycbcr, output="rgb48y",matrix="601",tv_range=false,lsb_in=true) rgb48cgco = mergergb (rgb48ycgco.selectevery (3,0), rgb48ycgco.selectevery (3,1), rgb48ycgco.selectevery (3,2)).subtitle ("ycgco") rgb48cbcr = mergergb (rgb48ycbcr.selectevery (3,0), rgb48ycbcr.selectevery (3,1), rgb48ycbcr.selectevery (3,2)).subtitle ("ycbcr") StackHorizontal(rgb48cgco,rgb48cbcr) just stare at the LSB part of "ycgco" and "ycbcr" real carefully and tell me what's the difference, which one is "lossless" |
4th October 2015, 12:14 | #17 | Link |
Registered User
Join Date: Mar 2014
Posts: 308
|
It's vaguely ironic to see feisty2 post about "mathematical precision" and using Dither tools to illustrate that, when Dither tools has off-by-one errors scattered throughout the full-range colour conversion functions.
Also, good job missing vivan's point. How surprising it is that you find the argument "pointless" when you just ignore what everyone else says.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! |
4th October 2015, 14:04 | #18 | Link | ||
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
Quote:
suppose: 1. there was infinite precision for computers 2. all rgb-yuv444-rgb stuff was done correctly under infinite precision 3. the input value was 0.123 the output value of both "ycgco" and "ycbcr" should be 0.123000000... or 0.1229999999... both are mathematically equal to 0.123, the input value perfect, end of the story now the reality is, there's no infinite precision, only higher but still finite precision say, the higher precision here is "6 significant figures" the output of ycgco would be like, 0.123000, still mathematically equals to 0.123, cuz there're only things like /2 and /4 inside ycgco stuff, and they won't produce infinite decimals long as the input is not infinite precision the ycbcr output might be like 0.123456, which != 0.123, cuz obviously ycbcr requires infinite precision for intermediate values to stay the zero error status, some intermediate value gets truncated to 6 significant figures and that leads to the error presented in the output value the disagreement starts right from here you and vivan think 0.123456 will become 0.123 if rounded down to 3-significant-figure precision and will =0.123 again so it's lossless and I think it's cheating, the mathematically lossless method should have an output like ycgco, lossless without rounding Last edited by feisty2; 4th October 2015 at 14:18. |
||
4th October 2015, 15:26 | #19 | Link |
Registered User
Join Date: Mar 2003
Posts: 481
|
Well, I'd define lossless like this in this case:
I have an image in space A. I have a transformation f from space A to space B. I have a transformation g from space B to space A. If for every pixel x in A: x = g(f(x)) is true then the transformation is lossless. It does not matter if there is rounding or definite presicion involved as long as every starting pixel has the same value as a transformed and back tranformed pixel. With this you see that the Dither color space tranformations are not lossless (because of dithering they can be off by +-1). But indeed you can do a lossless RGB8 to YCbCr10 to RGB8 transformation as vivan has shown. Last edited by Rumbah; 4th October 2015 at 15:29. |
4th October 2015, 15:43 | #20 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
will you ever "round" or "truncate" a 16bits YUV vid to <= 14bits RGB? guess not and the losslessness of ycgco will survive thru rounding or truncating or error diffusing, long as no random noise is applied, ycgco takes its crown by being mathematically lossless at finite precision |
|
Tags |
444, avisynth, color subsampling, x264, yv24 |
Thread Tools | Search this Thread |
Display Modes | |
|
|