VideoHelp Forum

Try DVDFab and download streaming video, copy, convert or make Blu-rays,DVDs! Download free trial !
+ Reply to Thread
Results 1 to 19 of 19
Thread
  1. I've read a little about color space and matrix but I am unsure what to do at encoding time. For example I have a source that is reported by MediaInfo as YUV 4:2:0 with "Format settings, Matrix" as "Default". What even is default? Considering the source is NTSC DVD, should I treat it as BT.601? If I do not specify anything during encoding, the resulting video will hold not information pertaining to the color matrix, and the color will be displayed exactly like the source. If I enforce BT.709 then the colors are slightly altered, but I am not entirely sure which is the correct one. I am wondering considering that a software like Handbrake will default to BT.709.

    I would suppose that SD sources should be BT.601 and HD sources should be BT.709 but then again, it's just a guess at this point.
    Quote Quote  
  2. Originally Posted by ZetaStax View Post
    Format settings, Matrix" as "Default". What even is default?
    This has to do with the MPEG2 quantization matrix, not the color matrix

    Considering the source is NTSC DVD, should I treat it as BT.601?
    yes

    If I do not specify anything during encoding, the resulting video will hold not information pertaining to the color matrix, and the color will be displayed exactly like the source.
    You can do nothing (in terms of converting the actual colors), just flag it as BT.601 so other hardware/software that look for flags can see it. This won't hurt and can only potentially help


    I would suppose that SD sources should be BT.601 and HD sources should be BT.709
    Yes
    Quote Quote  
  3. Thank you for clearing that up poisondeathray. Looking up ffmpeg documentation I have found a few different options related to color coding. color_primaries, color_trc and colorspace all seem to be simple flags, but the description says that the default value is 'auto' (Keep the same colorspace property) which makes me doubt what it actually does. There is also the filter out_color_matrix although it sounds more of a conversion pipeline than anything.

    Also when I set these flags MediaInfo also reports 'color range' as 'limited' should it be set to full?
    Quote Quote  
  4. Originally Posted by ZetaStax View Post
    Thank you for clearing that up poisondeathray. Looking up ffmpeg documentation I have found a few different options related to color coding. color_primaries, color_trc and colorspace all seem to be simple flags, but the description says that the default value is 'auto' (Keep the same colorspace property) which makes me doubt what it actually does. There is also the filter out_color_matrix although it sounds more of a conversion pipeline than anything.
    In the past, those flags actually converted stuff (not just flags) . I think the current behaviour is flagging only, not entirely sure

    out_color_matrix as part of -vf scale argument is for YUV<=>RGB conversions . That definitely converts




    Also when I set these flags MediaInfo also reports 'color range' as 'limited' should it be set to full?
    No . And DVD is never "full" range , at least not retail ones


    What are you feeding into FFMpeg directly ? Is it a script or MPEG2/VOB?

    Is DVD telecined, or interlaced ?

    What is the aspect ratio ?

    What is the desired output format ? / How is it going to be played ?

    If using something like x264/x265, I prefer to explicitly specify the flags in the encoder options
    Quote Quote  
  5. I'm feeding ffmpeg with an AviSynth+ script, where the source is loaded using DGSource. I'm using x264 and as far as compatibility goes I want this to play on the computer as well as on the TV through Kodi. Everything I've encoded so far is working properly so I don't think it's too much of a concern, but if I can flag the colorspace correctly, that's all the better. Fun fact, those flags do not have an option for BT.601
    Quote Quote  
  6. Originally Posted by ZetaStax View Post
    If I do not specify anything during encoding, the resulting video will hold not information pertaining to the color matrix, and the color will be displayed exactly like the source.
    Maybe with your current setup. But it may be different if you use a different media player or graphics card. Some media players always use one matrix or the other. Some will use rec.601 for SD material, rec.709 for HD material. Some will follow the flagged matrix, some not.

    The color matrix controls how YUV video becomes RGB for display on the monitor/TV (and how RGB video became YUV in the first place). The general rule is you should use rec.601 for standard definition video, rec.709 for high definition video. If you upscale SD video to HD convert the color matrix from rec.601 to rec.709. And flag the color matrix correctly in your encoding. That way you will have the best chance of having your video displayed correctly.

    Note that if you recompress a YUV source (like DVD) to YUV output without any intermediate conversion to RGB then the it remains with the original colorspace. Ie, rec.601 remains rec.601, rec.709 remains rec.709. You should still flag the matrix.

    Originally Posted by ZetaStax View Post
    Fun fact, those flags do not have an option for BT.601
    Use smpte170m.
    Quote Quote  
  7. Alright, things are clearer now. I've also confirmed that the three flags colorspace color_primaries and color_trc can all be set without reencoding, so there isn't any colorspace conversion. I'm still unsure whether all three should be set or not, it seems only colorspace has an impact on the resulting video.
    Quote Quote  
  8. ColorSpace is a different thing, to be fussy about terminology.

    "Transfer" = gamma. Rec.709 and Rec.601 are the same, but for DVDs you can use bt470bg for PAL and smpte170m for NTSC.
    "Primaries" specifies the color primaries. HD, NTSC and PAL use slightly different primaries.
    The chances of a player paying any attention to either of those is probably incredibly low.

    "Matrix" is the important one. I set all three options for Rec.709, but for SD I only set Color Matrix. If memory serves me correctly, when encoding DVDs, Handbrake sets Rec.709 for the first two and either bt470bg or smpte170m for the Matrix.

    I suspect Handbrake uses Rec.709 for the primaries because HD displays are generally calibrated for Rec.709 primaries, and in some respect Rec.709 was a compromise between the NTSC and PAL primaries. They're not much different anyway. It's using the wrong matrix for converting to RGB on playback that can make a noticeable difference to the colors.

    As a side note, I found myself learning a little more on this topic recently while adding color conversion to a script. I only mention it here as I wrote a mini essay explaining how color conversion is done, or at least should be done, and why the script works the way it does. It's under "ColorCorrect" in the help file if you'd care to read it.
    Last edited by hello_hello; 11th Oct 2019 at 16:07.
    Quote Quote  
  9. Two things worthy of note here.

    First, there are no bt470bg option for color_trc, but there is for color_primaries and colorspace. What whould you use?

    Second, I've tried a few videos with Handbrake. With HD it sets all three to bt709. For SD it sets primaries as bt407bg/smpte170m depending on the source for both color_primaries and colorspace, however it sets color_trc as bt709?
    Quote Quote  
  10. Originally Posted by ZetaStax View Post
    Two things worthy of note here.

    First, there are no bt470bg option for color_trc, but there is for color_primaries and colorspace. What would you use?
    x264 does. I know nothing about x265, or how they're set when encoding with ffmpeg.

    For x264:
    --colorprim bt470bg --transfer bt470bg --colormatrix bt470bg

    Otherwise as I mentioned in my previous post, don't bother specifying the Primaries or Transfer for SD, or as Handbrake does, use Rec.709 for Primaries & Transfer instead.
    Quote Quote  
  11. For ffmpeg , libx264 it's -x264opts or -x264params . Same with libx265 -x265opts or -x265params .

    e.g.
    Code:
    -x264opts colorprim=bt470bg:transfer=bt470bg:colormatrix=bt470bg
    In handbrake GUI, there is a commandline options section, the syntax might be slightly different IIRC , you don't use -x264opts, but just the key=value
    Quote Quote  
  12. Great, thanks.
    Quote Quote  
  13. Hate to reopen older threads, but I've done a bit of work on the subject of colorspace and there's still one question on my mind.

    When encoding a PAL DVD based on an NTSC show or movie, which colorspace should I define? The DVD is PAL, but does it necessarily means that it was converted for PAL release? One thing that does not help is that I'm not getting any difference whatsoever. Here's what I use

    For NTSC
    Code:
    -colorspace smpte170m -color_primaries smpte170m -color_trc smpte170m
    For PAL
    Code:
    -colorspace bt470bg -color_primaries bt470bg -color_trc gamma28
    (Note: ffmpeg does not have a bt470bg flag for transfer, gamma28 seems to be the correct one).
    Quote Quote  
  14. You don't know what has been done with the DVD, unless you have some reference like color bars. It's entirely possible other mistakes were made along the way

    Metadata shouldn't change the actual color. Most software/hardware do their own thing anyways .

    The only important one for the SD/HD case is matrix. In terms of actual values - bt470bg (pal), smpte170m (ntsc) are the same, 709 different . (ie. whether or not you use smpte170m or bt470bg, the actual values are the same in the calculation if the hardware/software is using it or looks at flags)

    Transfer is actually the same value between HD / SD/ PAL /NTSC, even if the label might be different (ie. Transfer for bt470bg, smpte170m, and 709 have the same actual value)

    Primaries are different for all of them. But usually not adjusted for - they are just ignored . If you actually adjust for them, (beyond flags) and the software/hardware is one of the few cases that actually uses that value, you often get the wrong colors.
    Quote Quote  
  15. ffmpeg does not have a bt470bg flag for transfer, gamma28 seems to be the correct one)
    Are you sure? According to the documentation from http://www.ffmpeg.org/ffmpeg-filters.html#setparams-1 'color_trc' does support bt470bg :
    color_trc
    Set the color transfer. Available values are:

    ‘auto’
    Keep the same color trc property (default).
    ‘bt709’
    ‘unknown’
    ‘bt470m’
    ‘bt470bg’
    ‘smpte170m’
    ‘smpte240m’
    ‘linear’
    ‘log100’
    ‘log316’
    ‘iec61966-2-4’
    ‘bt1361e’
    ‘iec61966-2-1’
    ‘bt2020-10’
    ‘bt2020-12’
    ‘smpte2084’
    ‘smpte428’
    ‘arib-std-b67’
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  16. You are right ffmpeg does have a flag, but it's not compatible with h.264 it seems, sorry for the misunderstanding

    Code:
    [libx264 @ 0000012cedf055c0] [Eval @ 00000021419fe240] Undefined constant or missing '(' in 'bt470bg'
    [libx264 @ 0000012cedf055c0] Unable to parse option value "bt470bg"
    [libx264 @ 0000012cedf055c0] Error setting option color_trc to value bt470bg.
    Quote Quote  
  17. Ah, okay. Thanks for clarifying.
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  18. For ffmpeg libx264, use -x264opts. See post 11
    Quote Quote  
  19. Originally Posted by poisondeathray View Post
    For ffmpeg libx264, use -x264opts. See post 11
    I believe it's interchangeable unless I'm missing something. Both "-colorspace bt470bg -color_primaries bt470bg -color_trc gamma28" and "-x264opts colorprim=bt470bg:transfer=bt470bg:colormatrix=bt4 70bg" will result in the following (MediaInfo)

    Color primaries : BT.601 PAL
    Transfer characteristics : BT.470 System B/G
    Matrix coefficients : BT.470 System B/G
    Quote Quote  



Similar Threads