I'm trying to convert 4:2:0 YUV to RGB. The .mp4 file looks fine when played on VLC.
The code below is almost right but there are still some artifacts and the colors look undersaturated compared to VLC.
See and problems with this code?
Thank you.
Code:#Kr = 0.2126: #Kg = 0.7152: #Kb = 0.0722 R = lum + (v-128)*(1-#Kr) G = lum - (u-128)*(1-#Kb)*#Kb/#Kg - 1*(v-128)*(1-#Kr)*#Kr/#Kg B = lum + (u-128)*(1-#Kb)
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 8 of 8
Thread
-
-
YUV from most sources is limited range (Y ranges from 16 to 235, U and V from 16 to 240), technically YCbCr, not YUV. You're using full range equations (Y, U, and V from 0 to 255). You also need to know if your video is rec.601 (SD usually) or rec.709 (HD usually). You're using the rec.709 matrix.
https://en.wikipedia.org/wiki/YCbCr -
The video is from a camcorder. I'm seeing lum. samples from 6 - 255.
Media info confirms the 709:
Code:Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.2 Format settings : CABAC / 2 Ref Frames Format settings, CABAC : Yes Format settings, RefFrames : 2 frames Format settings, GOP : M=1, N=15 Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 5 min 3 s Bit rate mode : Variable Bit rate : 49.8 Mb/s Maximum bit rate : 60.0 Mb/s Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 59.940 (60000/1001) FPS Standard : NTSC Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.401 Stream size : 1.76 GiB (96%) Encoded date : UTC 2018-09-23 20:59:24 Tagged date : UTC 2018-09-23 20:59:24 Color range : Limited Color primaries : BT.709 Transfer characteristics : xvYCC Matrix coefficients : BT.709 Codec configuration box : avcC
-
MediaInfo is saying the video is rec.709 (aka BT.709) and limited range. It's very common for camcorders to produce YCbCr values that are out of range. You should also clamp the output RGB values to make sure non fall outside the 0 to 255 range. An output value of 256 might be interpreted as a zero when converted to an unsigned 8 bit value and give a very different color than expected.
-
Transfer characteristics : xvYCC
xvycc is IEC 61966-2-4 . The equations should be in the document
It's also known as "extended" or wide gamut. Values that would have resulted in negative RGB values can now be used. It should be backwards compatible, but if you have a full xvycc display chain including wide gamut display - you should be able to see more colors . On a "normal" display, it will look oversaturated
The matrix used is the same, but there is a color component transfer function modification for the extended range
The actual IEC document isn't free, but there is a description of xvycc and the equations in this pdf
https://pdfs.semanticscholar.org/0992/9989e4ffa929f7f10465f68d21f5655933c5.pdf
and another reference
https://www.researchgate.net/publication/250999893_192_xvYCC_A_New_Standard_for_Video_...CC_Color_SpaceLast edited by poisondeathray; 24th Sep 2018 at 18:15.
-
It's very common for camcorders to produce YCbCr values that are out of range.
You should also clamp the output RGB values to make sure none fall outside the 0 to 255 range. An output value of 256 might be interpreted as a zero when converted to an unsigned 8 bit value and give a very different color than expected.
Code:If rf > 255: rf = 255:EndIf: If gf > 255: gf = 255:EndIf: If bf > 255: bf = 255:EndIf
-
Yes, it's a Sony AX53. Interesting little camera but the zoom control is for sh*t.
if you have a full xvycc display chain including wide gamut display - you should be able to see more colors . On a "normal" display, it will look oversaturated -
Similar Threads
-
RGB to YUV to RGB
By chris319 in forum ProgrammingReplies: 70Last Post: 20th Feb 2017, 17:49 -
ffmpeg/x264 RGB to YUV
By SameSelf in forum Video ConversionReplies: 40Last Post: 14th Nov 2016, 19:40 -
Converting Between 10-bit RGB and YUV and Back
By chris319 in forum Video ConversionReplies: 22Last Post: 9th Jul 2016, 00:53 -
YUV/ RGB problem in Avisynth
By spiritt in forum Newbie / General discussionsReplies: 9Last Post: 6th Sep 2015, 05:31 -
is this YUV or RGB?
By marcorocchini in forum Newbie / General discussionsReplies: 2Last Post: 20th Apr 2014, 11:21