[FFmpeg-devel] [PATCH] avcodec/libkvazaar: Respect codec context color settings.
John Mather
johnmather at sidefx.com
Tue Sep 12 20:40:29 EEST 2023
This patch makes the libkvazaar encoder respect color settings that are
present on the codec context, including color range, primaries, transfer
function and colorspace.
---
libavcodec/libkvazaar.c | 55 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 2ef34dd82e..cd87a9106d 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -56,6 +56,10 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
const kvz_api *const api = ctx->api = kvz_api_get(8);
kvz_config *cfg = NULL;
kvz_encoder *enc = NULL;
+ int8_t kvz_fullrange = -1;
+ int8_t kvz_colorprim = -1;
+ int8_t kvz_transfer = -1;
+ int8_t kvz_colormatrix = -1;
/* Kvazaar requires width and height to be multiples of eight. */
if (avctx->width % 8 || avctx->height % 8) {
@@ -101,6 +105,57 @@ FF_ENABLE_DEPRECATION_WARNINGS
cfg->rc_algorithm = KVZ_LAMBDA;
}
+ switch (avctx->color_range) {
+ case AVCOL_RANGE_JPEG: kvz_fullrange = 1; break;
+ case AVCOL_RANGE_MPEG: kvz_fullrange = 0; break;
+ default: kvz_fullrange = 0;
+ }
+ cfg->vui.fullrange = kvz_fullrange;
+
+ switch (avctx->color_primaries) {
+ case AVCOL_PRI_BT709: kvz_colorprim = 1; break;
+ case AVCOL_PRI_BT470M: kvz_colorprim = 4; break;
+ case AVCOL_PRI_BT470BG: kvz_colorprim = 5; break;
+ case AVCOL_PRI_SMPTE170M: kvz_colorprim = 6; break;
+ case AVCOL_PRI_SMPTE240M: kvz_colorprim = 7; break;
+ case AVCOL_PRI_FILM: kvz_colorprim = 8; break;
+ case AVCOL_PRI_BT2020: kvz_colorprim = 9; break;
+ default: kvz_colorprim = 2; // undef
+ }
+ cfg->vui.colorprim = kvz_colorprim;
+
+ switch (avctx->color_trc) {
+ case AVCOL_TRC_BT709: kvz_transfer = 1; break;
+ case AVCOL_TRC_GAMMA22: kvz_transfer = 4; break; // bt470m
+ case AVCOL_TRC_GAMMA28: kvz_transfer = 5; break; // bt470bg
+ case AVCOL_TRC_SMPTE170M: kvz_transfer = 6; break;
+ case AVCOL_TRC_SMPTE240M: kvz_transfer = 7; break;
+ case AVCOL_TRC_LINEAR: kvz_transfer = 8; break;
+ case AVCOL_TRC_LOG: kvz_transfer = 9; break; // log100
+ case AVCOL_TRC_LOG_SQRT: kvz_transfer = 10; break; // log316
+ case AVCOL_TRC_IEC61966_2_4: kvz_transfer = 11; break;
+ case AVCOL_TRC_BT1361_ECG: kvz_transfer = 12; break; // bt1361e
+ case AVCOL_TRC_IEC61966_2_1: kvz_transfer = 13; break;
+ case AVCOL_TRC_BT2020_10: kvz_transfer = 14; break;
+ case AVCOL_TRC_BT2020_12: kvz_transfer = 15; break;
+ default: kvz_transfer = 2; // undef
+ }
+ cfg->vui.transfer = kvz_transfer;
+
+ switch (avctx->colorspace) {
+ case AVCOL_SPC_RGB: kvz_colormatrix = 0; break; // gbr
+ case AVCOL_SPC_BT709: kvz_colormatrix = 1; break;
+ case AVCOL_SPC_FCC: kvz_colormatrix = 5; break;
+ case AVCOL_SPC_BT470BG: kvz_colormatrix = 6; break;
+ case AVCOL_SPC_SMPTE170M: kvz_colormatrix = 7; break;
+ case AVCOL_SPC_SMPTE240M: kvz_colormatrix = 8; break;
+ case AVCOL_SPC_YCGCO: kvz_colormatrix = 9; break;
+ case AVCOL_SPC_BT2020_NCL: kvz_colormatrix = 10; break; // bt2020nc
+ case AVCOL_SPC_BT2020_CL: kvz_colormatrix = 11; break; // bt2020c
+ default: kvz_colormatrix = 2; // undef
+ }
+ cfg->vui.colormatrix = kvz_colormatrix;
+
if (ctx->kvz_params) {
AVDictionary *dict = NULL;
if (!av_dict_parse_string(&dict, ctx->kvz_params, "=", ",", 0)) {
--
2.39.3
More information about the ffmpeg-devel
mailing list