Skip to content

wrong color-space metadata after encode from RGB #281

@MartinPulec

Description

@MartinPulec

this refers to CESNET/UltraGrid#341

hi, when QSV is compressing from a RGB format (BGRA for now; but applies also to X2RGB), it converts unconditionally to limited-range YUV BT.601, but sets stream metadata according to AVCodecContext::color_primaries and AVCodecContext::color_range. If those are not set explicitly, it sets full-range to metadata, anyways.

Please see following test case:

  1. input
    ffmpeg -y -f lavfi -i color=#ff0000 -t 1 -pix_fmt bgra [params] -c:v hevc_qsv out.h265

  2. output evaluation

    mediainfo --Language=raw --Full --Inform='Video;%matrix_coefficients%,%colour_range%' out.h265 &&
     ffmpeg -y -loglevel quiet -i out.h265 -strict -1 -frames 1 out.y4m; sed '1,2d' < out.y4m | od -t x1 
    

input RGB=[0xff,0x00,0x00] corresponds¹ to full-range YCbCr BT.601 [76,85,255]=[0x4c,0x55,0xff], limited range [65,91,237]=[0x51,0x5b,0xed] ²

¹ computed using this coefficient; Cb,Cr coefficients are offset by 128
² or Y=67=0x53 if using Y range 16-240, which I think is correct

evaluation:

  1. no params for 1. above - [0x51,0x5b,0xef], mediainfo: ",Full"
  2. -colorspace bt709 - [0x51,0x5b,0xef], mediainfo: "BT.709,Full"
  3. -colorspace bt709 -color_range tv- (ditto), mediainfo: "BT.709,Limited"
  4. -color_range tv - (ditto), mediainfo: ",Limited"
  5. -colorspace smpte170m -color_range tv - (ditto), mediainfo: "BT.601,Limited"

So, in all cases, the output is in limitted-range YCbCr 601, but metadata are correct only in case 5 (and also 4, assuming that implicit value is OK).

PS: -vf lavfi -i color=#ff0000 -t 1 -pix_fmt bgra seems to convert to [0x00,0x00,0xfd,0xff] - the swscale conversion is not entirely accurate but I don't know how to produce single-color RGB directly, without conversion from YUV (-vf lavfi -i color produces YUV)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions