diff --git a/src/modules/avformat/common.c b/src/modules/avformat/common.c index 774eec8ba..e33765167 100644 --- a/src/modules/avformat/common.c +++ b/src/modules/avformat/common.c @@ -253,6 +253,14 @@ int mlt_set_luma_transfer(struct SwsContext *context, int src_range = src_full_range ? 1 : 0; int dst_range = dst_full_range ? 1 : 0; + sws_getColorspaceDetails(context, + (int **) &src_coefficients, + &src_range, + (int **) &dst_coefficients, + &dst_range, + &brightness, + &contrast, + &saturation); switch (src_colorspace) { case 170: case 470: diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 79c31daa4..f48d6475a 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -348,6 +348,9 @@ static void color_trc_from_colorspace(mlt_properties properties) case 170: mlt_properties_set_int(properties, "color_trc", AVCOL_TRC_SMPTE170M); break; + case 2020: + mlt_properties_set_int(properties, "color_trc", AVCOL_TRC_BT2020_10); + break; default: break; } @@ -377,6 +380,39 @@ static void color_primaries_from_colorspace(mlt_properties properties) case 170: mlt_properties_set_int(properties, "color_primaries", AVCOL_PRI_SMPTE170M); break; + case 2020: + mlt_properties_set_int(properties, "color_primaries", AVCOL_PRI_BT2020); + break; + default: + break; + } +} + +static void av_colorspace_from_colorspace(mlt_properties properties, int colorspace) +{ + // Default color_space from colorspace. + switch (colorspace) { + case 0: // sRGB + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_RGB); + break; + case 601: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_BT470BG); + break; + case 709: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_BT709); + break; + case 240: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_SMPTE240M); + break; + case 170: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_SMPTE170M); + break; + case 2020: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_BT2020_NCL); + break; + case 2021: + mlt_properties_set_int(properties, "colorspace", AVCOL_SPC_BT2020_CL); + break; default: break; } @@ -928,6 +964,7 @@ static AVStream *add_video_stream(mlt_consumer consumer, } int colorspace = mlt_properties_get_int(properties, "colorspace"); mlt_properties_set(properties, "colorspace", NULL); + av_colorspace_from_colorspace(properties, colorspace); apply_properties(c, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); mlt_properties_set_int(properties, "colorspace", colorspace); @@ -1858,6 +1895,12 @@ static void *consumer_thread(void *arg) } else if (strstr(pix_fmt_name, "rgb") || strstr(pix_fmt_name, "bgr")) { mlt_properties_set(properties, "mlt_image_format", "rgb"); img_fmt = mlt_image_rgb; + } else if (strstr(pix_fmt_name, "yuv420p10le")) { + mlt_properties_set(properties, "mlt_image_format", "yuv420p10"); + img_fmt = mlt_image_yuv420p10; + } else if (strstr(pix_fmt_name, "yuv444p10le")) { + mlt_properties_set(properties, "mlt_image_format", "yuv444p10"); + img_fmt = mlt_image_yuv444p10; } } } diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 301ee7472..c08e6768d 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -2867,6 +2867,12 @@ static int video_codec_init(producer_avformat self, int index, mlt_properties pr case AVCOL_SPC_BT709: self->yuv_colorspace = 709; break; + case AVCOL_SPC_BT2020_NCL: + self->yuv_colorspace = 2020; + break; + case AVCOL_SPC_BT2020_CL: + self->yuv_colorspace = 2021; + break; default: // This is a heuristic Charles Poynton suggests in "Digital Video and HDTV" self->yuv_colorspace = self->video_codec->width * self->video_codec->height > 750000 @@ -2893,6 +2899,9 @@ static int video_codec_init(producer_avformat self, int index, mlt_properties pr case AVCOL_PRI_SMPTE240M: self->color_primaries = 601525; break; + case AVCOL_PRI_BT2020: + self->color_primaries = 2020; + break; case AVCOL_PRI_BT709: case AVCOL_PRI_UNSPECIFIED: default: diff --git a/src/modules/movit/filter_movit_convert.cpp b/src/modules/movit/filter_movit_convert.cpp index 73619d447..b7b468cd8 100644 --- a/src/modules/movit/filter_movit_convert.cpp +++ b/src/modules/movit/filter_movit_convert.cpp @@ -97,6 +97,11 @@ enum AVColorTransferCharacteristic { AVCOL_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC) AVCOL_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10 bit system AVCOL_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12 bit system + AVCOL_TRC_SMPTE2084 = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems + AVCOL_TRC_SMPTEST2084 = AVCOL_TRC_SMPTE2084, + AVCOL_TRC_SMPTE428 = 17, ///< SMPTE ST 428-1 + AVCOL_TRC_SMPTEST428_1 = AVCOL_TRC_SMPTE428, + AVCOL_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma" AVCOL_TRC_NB, ///< Not part of ABI }; @@ -151,10 +156,10 @@ static GammaCurve getGammaCurve(mlt_properties properties) } else if (!strcmp(color_trc, "linear")) { mlt_properties_set_int(properties, "color_trc", AVCOL_TRC_LINEAR); return GAMMA_LINEAR; - } else if (!strcmp(color_trc, "bt2020_10bit")) { + } else if (!strcmp(color_trc, "bt2020-10")) { mlt_properties_set_int(properties, "color_trc", AVCOL_TRC_BT2020_10); return GAMMA_REC_2020_10_BIT; - } else if (!strcmp(color_trc, "bt2020_12bit")) { + } else if (!strcmp(color_trc, "bt2020-12")) { mlt_properties_set_int(properties, "color_trc", AVCOL_TRC_BT2020_12); return GAMMA_REC_2020_12_BIT; } @@ -172,6 +177,8 @@ static void get_format_from_properties(mlt_properties properties, case 601: ycbcr_format->luma_coefficients = YCBCR_REC_601; break; + case 2020: + ycbcr_format->luma_coefficients = YCBCR_REC_2020; case 709: default: ycbcr_format->luma_coefficients = YCBCR_REC_709; @@ -186,6 +193,9 @@ static void get_format_from_properties(mlt_properties properties, case 601525: image_format->color_space = COLORSPACE_REC_601_525; break; + case 2020: + image_format->color_space = COLORSPACE_REC_2020; + break; case 709: default: image_format->color_space = COLORSPACE_REC_709;