From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2DBEC41D4D for ; Sun, 19 Jun 2022 17:48:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8937768B41F; Sun, 19 Jun 2022 20:48:53 +0300 (EEST) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B1C1C68B2D8 for ; Sun, 19 Jun 2022 20:48:46 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id a13so4082033lfr.10 for ; Sun, 19 Jun 2022 10:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=SFzdnZm+wxcorMH+3lAGObJdU7Xx34vixjbWknof1bE=; b=JwEcFCZBIqm9GxWA3+9tDCi30vERsK41s3qhTwLlIRz7ORXkdWRCPoU/DZAlxnxjfG ThjCwxMkCe6HJxRG+0/To1ck+YeKW741LuKqYLfmEyT0KAQxLScnhOVXOo9um4TafRVR 1Ekced/gojyPBa8bt7cfKhnfR3G1b/lC7cmiw3Rjkr9mjrDvSTRoLJyZ+rKfdWJHz6Ga cA4UQSt+eGsyxUVdMsSwg9Wy6YZW9+dT1PxJJVcEnpkPQbqlOgUYDGBopt5vQprOmuwM iI2mH3cqRpoTPgy8+L099wmMgm4UNOyUIVWPBcp29dWlbGFIzxMEWX98D5rChhwqhKGA g/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=SFzdnZm+wxcorMH+3lAGObJdU7Xx34vixjbWknof1bE=; b=0VHJ5vbEra+e1N3pmbIolpvCaNf2/1PmXA8UyPZ5z+Q3vnEUsoD61H7IQY7EuqQSCM Q1x1+JZhXHRzPFVqEsy8B3Ip0ApSv7QDGj/7CZP+SgGkFkpUs7W5Te7TSyOKW5BybUgR 5SLrrGknBTFtqHgOjSdZPE1gZPOWKMWXtyDRpBSy3MJZlQMixv6e6bADrLdCsX4w52gk Ke4Gha8mnCoOl3kMvpxiACD8OiPF5GkcUDxrgrQSh78owwX0z9M+MIN4bibJmegnJo2h nzm9sSJWU5Rlmn9dyvbv15Nsf5oJA9w0s0ybjzzS0pgAp7oTu/7v2hrnJqwgeTASVLzZ 5GuA== X-Gm-Message-State: AJIora+T3nplJwKT1vI1/q30ujgmSPLmZVVVZj8xdv3MG3QsUnCow6lN r0qRFwyBVdw636wcTrXcYS2YVs9IZGY= X-Google-Smtp-Source: AGRyM1tJIoP/K/MBIQZ0UGOYvbJPOQb3bYfpFR2MmKkEnHTqQK3spaQXpmvs70y4JiNO4K93IC+JIw== X-Received: by 2002:a05:6512:2511:b0:479:1723:a743 with SMTP id be17-20020a056512251100b004791723a743mr10909537lfb.433.1655660925481; Sun, 19 Jun 2022 10:48:45 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id g2-20020a2eb0c2000000b002555d6ca497sm1361624ljl.115.2022.06.19.10.48.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 10:48:44 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 20:48:39 +0300 Message-Id: <20220619174839.7669-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/libx265: make X265 CSP selection pixel format independent X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Currently the format listing misses the J formats completely, yet they are marked as supported in the encoder. Thus to make the logic support them while not explicitly listing them, make the logic utilize chroma subsampling information in both width and height available through the pixel format descriptor. --- libavcodec/libx265.c | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 4dcdcd7a77..e00cb6fd8c 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -240,39 +240,40 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) } } - switch (avctx->pix_fmt) { - case AV_PIX_FMT_YUV420P: - case AV_PIX_FMT_YUV420P10: - case AV_PIX_FMT_YUV420P12: - ctx->params->internalCsp = X265_CSP_I420; - break; - case AV_PIX_FMT_YUV422P: - case AV_PIX_FMT_YUV422P10: - case AV_PIX_FMT_YUV422P12: - ctx->params->internalCsp = X265_CSP_I422; - break; - case AV_PIX_FMT_GBRP: - case AV_PIX_FMT_GBRP10: - case AV_PIX_FMT_GBRP12: - ctx->params->vui.matrixCoeffs = AVCOL_SPC_RGB; - ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1; - ctx->params->vui.bEnableColorDescriptionPresentFlag = 1; - case AV_PIX_FMT_YUV444P: - case AV_PIX_FMT_YUV444P10: - case AV_PIX_FMT_YUV444P12: + switch (desc->log2_chroma_w) { + // 4:4:4, RGB. gray + case 0: + // gray + if (desc->nb_components == 1) { + if (ctx->api->api_build_number < 85) { + av_log(avctx, AV_LOG_ERROR, + "libx265 version is %d, must be at least 85 for gray encoding.\n", + ctx->api->api_build_number); + return AVERROR_INVALIDDATA; + } + ctx->params->internalCsp = X265_CSP_I400; + break; + } + + // set RGB identity matrix for RGB + if (desc->flags & AV_PIX_FMT_FLAG_RGB) { + ctx->params->vui.matrixCoeffs = AVCOL_SPC_RGB; + ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1; + ctx->params->vui.bEnableColorDescriptionPresentFlag = 1; + } + ctx->params->internalCsp = X265_CSP_I444; break; - case AV_PIX_FMT_GRAY8: - case AV_PIX_FMT_GRAY10: - case AV_PIX_FMT_GRAY12: - if (ctx->api->api_build_number < 85) { - av_log(avctx, AV_LOG_ERROR, - "libx265 version is %d, must be at least 85 for gray encoding.\n", - ctx->api->api_build_number); - return AVERROR_INVALIDDATA; - } - ctx->params->internalCsp = X265_CSP_I400; + // 4:2:0, 4:2:2 + case 1: + ctx->params->internalCsp = desc->log2_chroma_h == 1 ? + X265_CSP_I420 : X265_CSP_I422; break; + default: + av_log(avctx, AV_LOG_ERROR, + "Pixel format '%s' cannot be mapped to a libx265 CSP!\n", + desc->name); + return AVERROR_BUG; } if (ctx->crf >= 0) { -- 2.36.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".