From patchwork Sat Apr 4 09:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryo Hirafuji X-Patchwork-Id: 18630 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 1D85F44B0CE for ; Sat, 4 Apr 2020 12:53:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE01468B1E0; Sat, 4 Apr 2020 12:53:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36BF068AD2F for ; Sat, 4 Apr 2020 12:53:49 +0300 (EEST) Received: by mail-pl1-f177.google.com with SMTP id w3so3831142plz.5 for ; Sat, 04 Apr 2020 02:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aXQXgk04V0BjMAha/y+NdaWEPCV54Zfh3fKvH3f7rXU=; b=cZqMv2E55RZP2ZTAQRPbfNEAx716clR35JDVYpXD9gG3bptztjFg8WMzyfpA2rQfic yesNJbp7NmlEzf4+cxUlDv2jKoWl/3GgJMPKVYSQRhVspXmujMLBvQ38ehwB6WagG4vd 9SZw9fp7ObRqOQjuQ0WHH4T70vWVTUUUUWrTw6vCfVy9DuAlryoSoTYXBik+5dvmzNn8 s5vqDf2W1utCFPPLoOEjTQ+2U0FLTCiUK1/v8kPIgqlwETjasuNndELwT2aXPlw5L11A lJvZFJw7CNCt8N7IE1PRn45xZxOZAORv2ChhF/Es4xUnE61ApB4ZQ7+ZUSH/fZ11862k l+3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aXQXgk04V0BjMAha/y+NdaWEPCV54Zfh3fKvH3f7rXU=; b=LaTo86jbYXuDglzgAYhV41f/V1WWnYBeurBpbZgRIYQxxKynP6pGM/tkoqHWQmlHGO zWvK3Uj267vML1pFC9WgUM34dspFWU2Qci7GwqYttJYybRlWI/Jl5cLC5TqkUswe1wqL S6ceRq9CPzivVnuKgAZIR7YLE1tT6w0eIJBzBKnZPbfN1JvQGvEqrzZiOXcuLEn+TC07 /yqOf9oz8rXtlv5Jc1Jyy265ZiVyGqkFOCukOK2EOXsZjVqzTotR1eTy6SK7Oh/Bn3Wh tOIg2ACPO/JmM/fhvhWV5sCFCROGE1J2dUtHIr2/WTRLw53Fi8D5saFa/UqQcLlk4kI1 Tg9w== X-Gm-Message-State: AGi0PuatQrYiro4dhOyxPcIQi4lu11qtkJwT/p96hig76m/QEz7iHoPD dIegc/3Ix5YL6MkbVfW+JOQSRaxrxvk= X-Google-Smtp-Source: APiQypK/hK8GyUu7COZpd4wFdCHxRIuI+R8QmX7Lx77cO47OLwVWYNKZOl4pZxnTwho/vdIihRa0QQ== X-Received: by 2002:a17:90a:c20b:: with SMTP id e11mr14775905pjt.57.1585994027040; Sat, 04 Apr 2020 02:53:47 -0700 (PDT) Received: from localhost.localdomain (p2228151-ipngn9902souka.saitama.ocn.ne.jp. [153.162.21.151]) by smtp.gmail.com with ESMTPSA id x27sm7467098pfj.74.2020.04.04.02.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 02:53:46 -0700 (PDT) From: Ryo Hirafuji To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Apr 2020 18:53:40 +0900 Message-Id: <20200404095341.128020-1-ryo.hirafuji@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] libavcodec/libaomenc.c: Support gray input 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: Ryo Hirafuji Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" AV1 decoders, libaomdec and libdav1d, both support grayscale image. However, libaomenc does not support it yet. In this patch, I add a grayscale image support also to libaomenc. --- libavcodec/libaomenc.c | 48 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 096aadbe1c..fb61ce82e2 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -276,6 +276,25 @@ static int set_pix_fmt(AVCodecContext *avctx, aom_codec_caps_t codec_caps, AOMContext av_unused *ctx = avctx->priv_data; enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8; switch (avctx->pix_fmt) { + case AV_PIX_FMT_GRAY8: + enccfg->monochrome = 1u; + enccfg->g_profile = FF_PROFILE_AV1_MAIN; + *img_fmt = AOM_IMG_FMT_I420; + return 0; + case AV_PIX_FMT_GRAY10: + case AV_PIX_FMT_GRAY12: + if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) { + enccfg->monochrome = 1u; + enccfg->g_profile = + avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? FF_PROFILE_AV1_MAIN + : FF_PROFILE_AV1_PROFESSIONAL; + enccfg->g_bit_depth = enccfg->g_input_bit_depth = + avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12; + *img_fmt = AOM_IMG_FMT_I420; + *flags |= AOM_CODEC_USE_HIGHBITDEPTH; + return 0; + } + break; case AV_PIX_FMT_YUV420P: enccfg->g_profile = FF_PROFILE_AV1_MAIN; *img_fmt = AOM_IMG_FMT_I420; @@ -979,12 +998,25 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, if (frame) { rawimg = &ctx->rawimg; - rawimg->planes[AOM_PLANE_Y] = frame->data[0]; - rawimg->planes[AOM_PLANE_U] = frame->data[1]; - rawimg->planes[AOM_PLANE_V] = frame->data[2]; - rawimg->stride[AOM_PLANE_Y] = frame->linesize[0]; - rawimg->stride[AOM_PLANE_U] = frame->linesize[1]; - rawimg->stride[AOM_PLANE_V] = frame->linesize[2]; + if (frame->format == AV_PIX_FMT_GRAY8 || + frame->format == AV_PIX_FMT_GRAY10 || + frame->format == AV_PIX_FMT_GRAY12) { + rawimg->monochrome = 1; + rawimg->planes[AOM_PLANE_Y] = frame->data[0]; + rawimg->planes[AOM_PLANE_U] = frame->data[0]; + rawimg->planes[AOM_PLANE_V] = frame->data[0]; + rawimg->stride[AOM_PLANE_Y] = frame->linesize[0]; + rawimg->stride[AOM_PLANE_U] = frame->linesize[0]; + rawimg->stride[AOM_PLANE_V] = frame->linesize[0]; + } else { + rawimg->monochrome = 0; + rawimg->planes[AOM_PLANE_Y] = frame->data[0]; + rawimg->planes[AOM_PLANE_U] = frame->data[1]; + rawimg->planes[AOM_PLANE_V] = frame->data[2]; + rawimg->stride[AOM_PLANE_Y] = frame->linesize[0]; + rawimg->stride[AOM_PLANE_U] = frame->linesize[1]; + rawimg->stride[AOM_PLANE_V] = frame->linesize[2]; + } timestamp = frame->pts; switch (frame->color_range) { case AVCOL_RANGE_MPEG: @@ -1025,6 +1057,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, } static const enum AVPixelFormat av1_pix_fmts[] = { + AV_PIX_FMT_GRAY8, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, @@ -1032,6 +1065,9 @@ static const enum AVPixelFormat av1_pix_fmts[] = { }; static const enum AVPixelFormat av1_pix_fmts_highbd[] = { + AV_PIX_FMT_GRAY8, + AV_PIX_FMT_GRAY10, + AV_PIX_FMT_GRAY12, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,