From cb42be366556e09060d4d85ed2220f694cd09a48 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Sat, 23 Apr 2022 02:02:12 -0700 Subject: [PATCH] win-dshow: Respect TRC of encoded video Fixes colors for devices that send HDR streams. --- plugins/win-dshow/ffmpeg-decode.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/win-dshow/ffmpeg-decode.c b/plugins/win-dshow/ffmpeg-decode.c index cff6b8c8a..38945472f 100644 --- a/plugins/win-dshow/ffmpeg-decode.c +++ b/plugins/win-dshow/ffmpeg-decode.c @@ -400,6 +400,25 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data, frame->height = decode->frame->height; frame->flip = false; + switch (decode->frame->color_trc) { + case AVCOL_TRC_BT709: + case AVCOL_TRC_GAMMA22: + case AVCOL_TRC_GAMMA28: + case AVCOL_TRC_SMPTE170M: + case AVCOL_TRC_SMPTE240M: + case AVCOL_TRC_IEC61966_2_1: + frame->trc = VIDEO_TRC_SRGB; + break; + case AVCOL_TRC_SMPTE2084: + frame->trc = VIDEO_TRC_PQ; + break; + case AVCOL_TRC_ARIB_STD_B67: + frame->trc = VIDEO_TRC_HLG; + break; + default: + frame->trc = VIDEO_TRC_DEFAULT; + } + if (frame->format == VIDEO_FORMAT_NONE) return false;