VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. 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)
    Quote Quote  
  2. 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
    Quote Quote  
  3. 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
    Quote Quote  
  4. 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.
    Quote Quote  
  5. Transfer characteristics : xvYCC
    Probably a sony camera

    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_Space
    Last edited by poisondeathray; 24th Sep 2018 at 18:15.
    Quote Quote  
  6. It's very common for camcorders to produce YCbCr values that are out of range.
    They're 8-bit samples so they can't be over 255.

    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.
    That's exactly what was happening. The results of some of the calculations were over 255 and wreaking havoc. I should have thought of that in the first place. This line of code fixed it:

    Code:
    If rf > 255: rf = 255:EndIf: If gf > 255: gf = 255:EndIf: If bf > 255: bf = 255:EndIf
    It works perfectly now, thank you.
    Quote Quote  
  7. 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
    I have to assume a "normal" display. Actually they won't look oversaturated; they just clip and look psychedelic.
    Quote Quote  
  8. Originally Posted by chris319 View Post
    It's very common for camcorders to produce YCbCr values that are out of range.
    They're 8-bit samples so they can't be over 255.
    With regular rec.709 limited range video only Y values from 16 to 235 and U/V values from 16 to 240 are valid. Values outside that range lead to illegal RGB values (RGB components less than 0, greater than 255). I'm not sure how xvycc deals with that.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!