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. |
![]() |
#1 | Link |
Registered User
Join Date: Oct 2008
Location: Chennai India
Posts: 31
|
RGB Compression using x264
Does x264 convert RGB/BGR to YUV420? or is there an error in my command line?
c:\bin>x264 -h x264 core:120 r2120 0c7dab9 ... c:\bin>x264 rgb.avs -q 0 -o rgg.264 avs [info]: 352x288p 0:0 @ 25/1 fps (cfr) resize [warning]: converting from bgr24 to yuv420p [swscaler @ 01b9e280] full chroma interpolation for destination format 'yuv420p' not yet implemented x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle Cache64 x264 [info]: profile High 4:4:4 Predictive, level 1.3, 4:2:0 8-bit ... Thanks Ramprasad |
![]() |
![]() |
![]() |
#2 | Link |
Software Developer
![]() Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,244
|
As far as I know, H.264 uses the YCbCr color model. Thus RGB data unavoidably has to be converted to YCbCr. You can convert it back to RGB after decoding.
Note that the color-space conversion itself is lossless (except for rounding errors), but the '4:2:0' color sub-sampling means a certain loss, compared to the original RGB source. H.264 also supports a '4:4:4' mode (i.e. no color sub-sampling at all), but I don't think x264 does support this yet. Most H.264 decoders probably wouldn't either...
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 18th December 2011 at 21:39. |
![]() |
![]() |
![]() |
#3 | Link | |||
Registered User
Join Date: Jul 2007
Posts: 548
|
Quote:
Quote:
Quote:
ramprasad85 You need to use --output-csp rgb because default is i420 (lossless or lossy encoding you do indifferent) |
|||
![]() |
![]() |
![]() |
#4 | Link | |||
Software Developer
![]() Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,244
|
Quote:
If we have 3 three channels with full resolution in '4:4:4' mode anyway, we can "simply" use those to store RGB values rather than YCrCb values. It just needs a way to signal the decoder that we use RGB (GBR). And, as you say, the VUI can do that. Quote:
![]() Quote:
![]()
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 18th December 2011 at 23:25. |
|||
![]() |
![]() |
![]() |
#5 | Link | ||
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,373
|
Quote:
![]() But Microsoft agrees with you: Quote:
|
||
![]() |
![]() |
![]() |
#6 | Link | ||
Registered User
Join Date: Sep 2007
Posts: 5,162
|
Quote:
http://forum.doom9.org/showthread.php?t=154731 http://software.intel.com/sites/prod...or_models.html see "RGB Colors Cube in the YUV Color Space" diagram |
||
![]() |
![]() |
![]() |
#7 | Link | ||
Software Developer
![]() Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,244
|
Quote:
![]() In reality there will be some loss due to the limited precision (rounding errors), but whether these will be visible is a different question. Also dithering could be used to minimize the problem... Quote:
And, as these values originate from RGB values, they should map to the part of the YUV space that represents valid RGB values and thus can be converted back to RGB. After all, this RGB -> YUV -> RGB transform should be lossless - except for the rounding errors, of course. I see, however, that squeezing the whole RGB space into a small subset of the YUV space causes more rounding errors than using the whole range would (at fixed bpp).
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 19th December 2011 at 18:24. |
||
![]() |
![]() |
![]() |
#9 | Link |
Registered User
Join Date: Oct 2008
Location: Chennai India
Posts: 31
|
Thanks to x264, FFmpeg and especially to you all
ffmpeg -i rgb.avs -frames 1 src.bmp x264 rgb.avs -q 0 -o rgb.264 --output-csp rgb ffmpeg -i rgb.264 -frames 1 decoded.bmp fc /b src.bmp decoded.bmp Comparing files src.bmp and DECODED.BMP FC: no differences encountered |
![]() |
![]() |
![]() |
#10 | Link |
契約者
Join Date: Jun 2008
Posts: 1,577
|
ramprasad85
Thanks for sharing that info. What about compression ratio of the rgb encode, нow it is in terms of file size compared to YUV 4:4:4 and 4:2:0 encodes (yes I know it won't be lossless anymore but real visual quality difference unnoticeable so interesting to know that anyway)? Anyone did any tests? |
![]() |
![]() |
![]() |
#11 | Link |
VR, 3D & HDR UHD fan
Join Date: Mar 2006
Location: Sofia, Bulgaria
Posts: 53
|
Hi, I was wondering the same thing, and I did some tests two months ago for my own satisfaction
![]() The sources were 720p RGB video-game clips. Unfortunately, I don't remember all the details (like if I did the colorspace conversion in avisynth or directly through x264, and if I retained the full-range or converted it to TV levels), but anyways, I used the same conditions for 444/420/RGB and the results were the same with all my source clips. I used the same CRF value for the encodes (I think it was 20 or 21), but probably the value scales are different for these three cases, so take the results with a pinch of salt as they say ![]() |
![]() |
![]() |
![]() |
#12 | Link |
Moderator
![]() Join Date: Jan 2006
Location: Portland, OR
Posts: 4,434
|
...assuming uncompressed, that is.
A main point of using Y'CbCr is that the HSV doesn't percieve chroma frequency nearly as precisely as it does luma frequency, so in the real world Cb and Cr can be compressed a whole lot more without visual impact, and generally have a lot less entropy in the source channels. That's also why we can generally get away with throwing away 75% of chroma samples with 4:2:0. And why 10-bit encoding only gives 10-bit to the Y' channel. Y'CbCr is a more efficient color space for natural images. . Where RGB is interesting in when trying to record synthetic images that use the full RGB gamut (there are colors that exist in RGB but not in Y'CbCr, the same way that Y'CbCr can have a highly saturated white, which isn't possible in RGB). |
![]() |
![]() |
![]() |
#15 | Link | |
Moderator
![]() Join Date: Jan 2006
Location: Portland, OR
Posts: 4,434
|
Quote:
Hmm. I wonder where x264 would get >8-bit chroma channels from for natural images. Probably RED or something like that. |
|
![]() |
![]() |
![]() |
#16 | Link | |
x264 developer
Join Date: Sep 2005
Posts: 8,667
|
Quote:
Code:
for (i = 0; i < 8; i++) { ctx->dsp.clear_block(ctx->blocks[i]); ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale); } Code:
dct_y_offset = dct_linesize_luma << 3; dct_x_offset = 8 << shift1; ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]); ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]); ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[4]); ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[5]); if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) { dct_y_offset = dct_linesize_chroma << 3; ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]); ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]); ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[6]); ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[7]); } |
|
![]() |
![]() |
![]() |
#17 | Link | |
Moderator
![]() Join Date: Jan 2006
Location: Portland, OR
Posts: 4,434
|
Quote:
![]() All my video books are still boxed up from my move, but I'll double check as soon as I get down to that strata of cardboard. |
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|