From: Zhao Zhili <quinkblack@foxmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Zhao Zhili <zhilizhao@tencent.com> Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/videotoolboxenc: use color parameters conversion from avutil Date: Sun, 16 Jul 2023 17:13:27 +0800 Message-ID: <tencent_6938FD965ECD2CA04C4DEC4FA8D527275B07@qq.com> (raw) From: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/videotoolboxenc.c | 137 ++++------------------------------- 1 file changed, 13 insertions(+), 124 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 6114351392..8e493c4f7a 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -1001,132 +1001,20 @@ pbinfo_nomem: return AVERROR(ENOMEM); } -static int get_cv_color_primaries(AVCodecContext *avctx, - CFStringRef *primaries) -{ - enum AVColorPrimaries pri = avctx->color_primaries; - switch (pri) { - case AVCOL_PRI_UNSPECIFIED: - *primaries = NULL; - break; - - case AVCOL_PRI_BT470BG: - *primaries = kCVImageBufferColorPrimaries_EBU_3213; - break; - - case AVCOL_PRI_SMPTE170M: - *primaries = kCVImageBufferColorPrimaries_SMPTE_C; - break; - - case AVCOL_PRI_BT709: - *primaries = kCVImageBufferColorPrimaries_ITU_R_709_2; - break; - - case AVCOL_PRI_BT2020: - *primaries = compat_keys.kCVImageBufferColorPrimaries_ITU_R_2020; - break; - - default: - av_log(avctx, AV_LOG_ERROR, "Color primaries %s is not supported.\n", av_color_primaries_name(pri)); - *primaries = NULL; - return -1; - } - - return 0; -} - -static int get_cv_transfer_function(AVCodecContext *avctx, - CFStringRef *transfer_fnc, - CFNumberRef *gamma_level) +static int get_cv_gamma(AVCodecContext *avctx, + CFNumberRef *gamma_level) { enum AVColorTransferCharacteristic trc = avctx->color_trc; - Float32 gamma; + Float32 gamma = 0; *gamma_level = NULL; - switch (trc) { - case AVCOL_TRC_UNSPECIFIED: - *transfer_fnc = NULL; - break; - - case AVCOL_TRC_BT709: - *transfer_fnc = kCVImageBufferTransferFunction_ITU_R_709_2; - break; - - case AVCOL_TRC_SMPTE240M: - *transfer_fnc = kCVImageBufferTransferFunction_SMPTE_240M_1995; - break; - -#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ - case AVCOL_TRC_SMPTE2084: - *transfer_fnc = kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; - break; -#endif -#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_LINEAR - case AVCOL_TRC_LINEAR: - *transfer_fnc = kCVImageBufferTransferFunction_Linear; - break; -#endif -#if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG - case AVCOL_TRC_ARIB_STD_B67: - *transfer_fnc = kCVImageBufferTransferFunction_ITU_R_2100_HLG; - break; -#endif - - case AVCOL_TRC_GAMMA22: - gamma = 2.2; - *transfer_fnc = kCVImageBufferTransferFunction_UseGamma; - *gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); - break; - - case AVCOL_TRC_GAMMA28: - gamma = 2.8; - *transfer_fnc = kCVImageBufferTransferFunction_UseGamma; - *gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); - break; - - case AVCOL_TRC_BT2020_10: - case AVCOL_TRC_BT2020_12: - *transfer_fnc = compat_keys.kCVImageBufferTransferFunction_ITU_R_2020; - break; - - default: - *transfer_fnc = NULL; - av_log(avctx, AV_LOG_ERROR, "Transfer function %s is not supported.\n", av_color_transfer_name(trc)); - return -1; - } - - return 0; -} - -static int get_cv_ycbcr_matrix(AVCodecContext *avctx, CFStringRef *matrix) { - switch(avctx->colorspace) { - case AVCOL_SPC_BT709: - *matrix = kCVImageBufferYCbCrMatrix_ITU_R_709_2; - break; - - case AVCOL_SPC_UNSPECIFIED: - case AVCOL_SPC_RGB: - *matrix = NULL; - break; - - case AVCOL_SPC_BT470BG: - case AVCOL_SPC_SMPTE170M: - *matrix = kCVImageBufferYCbCrMatrix_ITU_R_601_4; - break; - - case AVCOL_SPC_SMPTE240M: - *matrix = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; - break; - - case AVCOL_SPC_BT2020_NCL: - *matrix = compat_keys.kCVImageBufferYCbCrMatrix_ITU_R_2020; - break; - - default: - av_log(avctx, AV_LOG_ERROR, "Color space %s is not supported.\n", av_color_space_name(avctx->colorspace)); - return -1; - } + if (trc == AVCOL_TRC_GAMMA22) + gamma = 2.2; + else if (trc == AVCOL_TRC_GAMMA28) + gamma = 2.8; + if (gamma != 0) + *gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); return 0; } @@ -1694,9 +1582,10 @@ static int vtenc_configure_encoder(AVCodecContext *avctx) vtctx->dts_delta = vtctx->has_b_frames ? -1 : 0; - get_cv_transfer_function(avctx, &vtctx->transfer_function, &gamma_level); - get_cv_ycbcr_matrix(avctx, &vtctx->ycbcr_matrix); - get_cv_color_primaries(avctx, &vtctx->color_primaries); + get_cv_gamma(avctx, &gamma_level); + vtctx->transfer_function = av_map_videotoolbox_color_trc_from_av(avctx->color_trc); + vtctx->ycbcr_matrix = av_map_videotoolbox_color_matrix_from_av(avctx->colorspace); + vtctx->color_primaries = av_map_videotoolbox_color_primaries_from_av(avctx->color_primaries); if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2023-07-16 9:14 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_6938FD965ECD2CA04C4DEC4FA8D527275B07@qq.com \ --to=quinkblack@foxmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=zhilizhao@tencent.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git