From patchwork Sun Dec 6 04:31:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 24365 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 28D3344B63C for ; Sun, 6 Dec 2020 06:31:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3AD968A56C; Sun, 6 Dec 2020 06:31:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.overt.org (mail.overt.org [157.230.92.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F1D76891CE for ; Sun, 6 Dec 2020 06:31:23 +0200 (EET) Received: from authenticated-user (mail.overt.org [157.230.92.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id D40D9430FD; Sat, 5 Dec 2020 22:31:20 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1607229081; bh=a/JrqptCe81iSjKQ9RjqNRYmu+WHy/lq3aH+N8FCfY4=; h=From:To:Cc:Subject:Date:From; b=HF58Lkl4cIVNC8/6Q6vko9rGadG+HTy04YHPi8nH+IMevpcL6NO3evzJnY3ZSN3AU urcv+nqN1oXVph+ovLG7hlvIqc0RCmOSySpASzB80WogVltjcjU/8WfhvJAy3WhYFC 0IljOEicc9CfgmrKY9U3yDm2vGer46+RnQVsxrtLf4AtPSEqRLS6pmqhbZpJ1+YKHt V/Q5YHTexxy+hp3/GoeWHevYXswPEEMSSJXR8sCl5evrdUAnpEUKFKcm/AHkOnjB79 Qx3BUWzl6qaM6ZlvbvT2rXs5IU2CYBTzl2M0hg5dG0YhSRURgjbBjdX/ro+781ISWs cgujEjXy0MXmA== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Dec 2020 20:31:12 -0800 Message-Id: <20201206043112.83610-1-philipl@overt.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/nvdec: Add support for decoding monochrome av1 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Philip Langdale Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The nvidia hardware explicitly supports decoding monochrome content, presumably for the AVIF alpha channel. Supporting this requires an adjustment in av1dec and explicit monochrome detection in nvdec. I'm not sure why the monochrome path in av1dec did what it did - it seems non-functional - YUV440P doesn't seem a logical pix_fmt for monochrome and conditioning on chroma sub-sampling doesn't make sense. So I changed it. I've tested 8bit content, but I haven't found a way to create a 10bit sample, so that path is untested for now. Signed-off-by: Philip Langdale --- libavcodec/av1dec.c | 23 ++++++++++++++++++----- libavcodec/nvdec.c | 3 +++ libavcodec/version.h | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index d7b2ac9d46..f973d93edc 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -387,11 +387,14 @@ static int get_pixel_format(AVCodecContext *avctx) av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); } } else { - if (seq->color_config.subsampling_x == 1 && - seq->color_config.subsampling_y == 1) - pix_fmt = AV_PIX_FMT_YUV440P; - else - av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); + if (bit_depth == 8) + pix_fmt = AV_PIX_FMT_GRAY8; + else if (bit_depth == 10) + pix_fmt = AV_PIX_FMT_GRAY10; + else if (bit_depth == 12) + pix_fmt = AV_PIX_FMT_GRAY12; + else + av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n"); } av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n", @@ -430,6 +433,16 @@ static int get_pixel_format(AVCodecContext *avctx) #endif #if CONFIG_AV1_VAAPI_HWACCEL *fmtp++ = AV_PIX_FMT_VAAPI; +#endif + break; + case AV_PIX_FMT_GRAY8: +#if CONFIG_AV1_NVDEC_HWACCEL + *fmtp++ = AV_PIX_FMT_CUDA; +#endif + break; + case AV_PIX_FMT_GRAY10: +#if CONFIG_AV1_NVDEC_HWACCEL + *fmtp++ = AV_PIX_FMT_CUDA; #endif break; } diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index dd7dcccafa..d45804994f 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -84,6 +84,9 @@ static int map_chroma_format(enum AVPixelFormat pix_fmt) { int shift_h = 0, shift_v = 0; + if (av_pix_fmt_count_planes(pix_fmt) == 1) + return cudaVideoChromaFormat_Monochrome; + av_pix_fmt_get_chroma_sub_sample(pix_fmt, &shift_h, &shift_v); if (shift_h == 1 && shift_v == 1) diff --git a/libavcodec/version.h b/libavcodec/version.h index e4b81da7cb..d1f6fb440a 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 114 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \