From patchwork Sun Jun 19 17:48:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 36341 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1253211pzb; Sun, 19 Jun 2022 10:48:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t4TOp6SM6sAe5ENC/LIehlM1xfuU3fzKySX/PwL30oh2DLfW332gTQ2Bk3CGVfkhkJM3qY X-Received: by 2002:a17:906:ce:b0:718:bff8:58c3 with SMTP id 14-20020a17090600ce00b00718bff858c3mr17696335eji.512.1655660938814; Sun, 19 Jun 2022 10:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655660938; cv=none; d=google.com; s=arc-20160816; b=ObvQDqH0yAWqKuggGDwF9Stz9c5AnsAxHDeUO/NSjkLR8+P0MIsBbkdkCHpGv0i1qi 79KYcZ95WdSR1SLRTkfhdFv0Zg2JzqMtAAdrvwe3YP01g6gUcbULWmbh1t7kIRk5zJhh mnuwO3atyf6RilylSAf7xd2n3P6ZzU+LUieTlEepA7WFkmsAWW2mK0P9BhtyqqSjAFur Yf6wp6fq94gc2eOBjykwlXlzC9G1zI82wLqNkPuC7hqsogKB0DySV+e8hI0i+MqBdbPH ijJC05O3J0iiXiYViaJ3o8RJKCB8ukcMdrPi2m/Typ8Q2xD/ZhO3BjE1PTm1Zyvq8paA ZVLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=YYaLWwKnWj2vc4pfyHdsVueIDyykoKEyN2JQn3BkdXM=; b=fyzEdhxYK2oCAzYlzBa4pcknnZF4CEj1Ng5wvOsZxcpdEE974MBnH+tzQIz8/ZcNl5 V3pWn/2c9HLpVtOi40TTqzjHOsGscGiaazikOs6aAqE898hEpe4vNNVlgnFCAE44xuVI KeHG++R4IXdeKt/LqiZwih3ori9B6VAXd2Gk5BIkV5hZR1mu47r8lF/CE7QVEPu9VLBT uBlguhAHGfIppJzpv0o2mTkVr+NEMfHB3/myerxMvtB62LnP7IscNfE6hJ4byjPxd4rt phuOngdm1lWQ0kPOflvOdRauQChh5TmM8tdVDmc6tJUlHQTHJSDlgM2ia5llJ9YU7/4T RMCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=JwEcFCZB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd10-20020a1709069b8a00b006feb974badcsi12289233ejc.674.2022.06.19.10.48.57; Sun, 19 Jun 2022 10:48:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=JwEcFCZB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C643B68041B; Sun, 19 Jun 2022 20:48:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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_Ekstr=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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5sNt658XNF/U 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) {