From patchwork Wed Sep 7 09:41:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sven C. Dack" X-Patchwork-Id: 460 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp212012vsd; Wed, 7 Sep 2016 02:41:59 -0700 (PDT) X-Received: by 10.194.216.7 with SMTP id om7mr39398330wjc.135.1473241319173; Wed, 07 Sep 2016 02:41:59 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y128si3063161wmg.35.2016.09.07.02.41.58; Wed, 07 Sep 2016 02:41:59 -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=@sky.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1623C68A0A4; Wed, 7 Sep 2016 12:41:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nm2-vm7.bullet.mail.ir2.yahoo.com (nm2-vm7.bullet.mail.ir2.yahoo.com [212.82.96.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 94C4368A0A4 for ; Wed, 7 Sep 2016 12:41:40 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sky.com; s=s1024; t=1473241309; bh=PVNoxjxvdLfrwbb57p4mmM7WZFlgG95/AhQENUokmJ4=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=3npHK6oMYYW90lhZBwyHhql/lpFHqPubacNOffq0ZVdC+pbWK430+PVVYbLv+LUTJzwOkluGMKOu1mWycOC6mBiMlOf9uMtq2YneLGIwiNPBxJrrJsPFRc88juNQWbjfmj6Xom8Gr4rs+Gddikl/WLIxyG6tZ4xvHie7YNciUSU= Received: from [212.82.98.63] by nm2.bullet.mail.ir2.yahoo.com with NNFMP; 07 Sep 2016 09:41:49 -0000 Received: from [46.228.39.103] by tm16.bullet.mail.ir2.yahoo.com with NNFMP; 07 Sep 2016 09:41:49 -0000 Received: from [127.0.0.1] by smtp140.mail.ir2.yahoo.com with NNFMP; 07 Sep 2016 09:41:49 -0000 X-Yahoo-Newman-Id: 441278.9057.bm@smtp140.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Jk9zkJ4VM1l9Rm0ImgYwXoXGwSQaRedsgOnkkrwNHz.Ti9o yCrcLk1zIbTkm0SF834R9DmB_yUGcSnAlq4bdg1zI8wNxcZFh3EBNdGy0p9O QvcEGd8ZhBUW.z_snED01SaTToLedipAt0FSIVNfH.TwA2YYPGX3OtCkMj91 dGFv7QbpDLBnEvOOOZN55PteZK_Ykj8JCfh6I2rS7qvOd9U3a8K20BrX3MCq W.8gwiV.UQmbtgOLzaxoJtJhOEnL_LNbGfN5Dk_ZlZWyVmIFcr9GHC7d63BB 1_DPdusa.nWSaN7F3XpQyBEsBshvVFXbqwOQCX2LuCqitXhpAxPNiu0N7IwI MdId1AlaCg4_upaqEUkbCQjJyhK4XgpBGS7SJZn_.vEBxPpa8D9OCeYvvtiN 4BfZqoRw0DR34iPn9rieZio6H9Mx.Ca1IJQEFD0WxF6rL_Hs8YiXFLf3dVKh rxR4chJTfUyVMqmYyrs.eTbCLC8ATSY_qqKz7IzfqkIAIQpMTZ.p9bBdaEwM ETd2UBSLYjGmEf8MrLeYj5G1ET79JOXJholL3yvY- X-Yahoo-SMTP: vPZU.OKswBC.RMkOW9onWi6Zk8BriyC1yj0kMdBuqpLuLjitZVXhzK.Ofd5b To: FFmpeg development discussions and patches References: <67a158c2-8043-50ab-c3f4-3bbf805deedb@sky.com> <06309fa1-a0e9-9a79-5e87-c82a03bd16b5@sky.com> <89d3ee6c-8a30-ade8-4b16-efd06178f6ca@rothenpieler.org> <294eb876-6b24-718e-be41-10e43d03e475@sky.com> From: "Sven C. Dack" Message-ID: <74228f9e-0483-dccd-7f50-b9e22b39dc51@sky.com> Date: Wed, 7 Sep 2016 10:41:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 In-Reply-To: <294eb876-6b24-718e-be41-10e43d03e475@sky.com> Subject: Re: [FFmpeg-devel] adding RGBA and BGRA to nvenc.c 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 07/09/16 10:40, Sven C. Dack wrote: > > It is necessary in order to make it work. The twist here is intentional as I > pointed out earlier. If you do it the other way around as described in the > documentation then you get false and missing colours. > > I'd like to keep in the transparency channel unless you know there is an > actual problem with it. The encoder may not use it, but it is no reason not to > pass it on. Otherwise will RGBA/BGRA have to be converted into RGB0/BGR0 and > you will again get a performance penalty. > > Sven > return AVERROR(EINVAL); @@ -1350,6 +1364,11 @@ static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf, av_image_copy_plane(buf, lockBufferParams->pitch, frame->data[2], frame->linesize[2], avctx->width << 1, avctx->height); + } else if (frame->format == AV_PIX_FMT_RGBA || frame->format == AV_PIX_FMT_RGB0 || + frame->format == AV_PIX_FMT_BGRA || frame->format == AV_PIX_FMT_BGR0) { + av_image_copy_plane(buf, lockBufferParams->pitch, + frame->data[0], frame->linesize[0], + avctx->width << 2, avctx->height); } else { av_log(avctx, AV_LOG_FATAL, "Invalid pixel format!\n"); return AVERROR(EINVAL); --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -81,6 +81,10 @@ const enum AVPixelFormat ff_nvenc_pix_fmts[] = { AV_PIX_FMT_P010, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P16, + AV_PIX_FMT_RGB0, + AV_PIX_FMT_BGR0, + AV_PIX_FMT_RGBA, + AV_PIX_FMT_BGRA, #if CONFIG_CUDA AV_PIX_FMT_CUDA, #endif @@ -1032,6 +1036,16 @@ static av_cold int nvenc_alloc_surface(AVCodecContext *avctx, int idx) ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_YUV444_10BIT; break; + case AV_PIX_FMT_RGB0: + case AV_PIX_FMT_RGBA: + ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ABGR; + break; + + case AV_PIX_FMT_BGR0: + case AV_PIX_FMT_BGRA: + ctx->surfaces[idx].format = NV_ENC_BUFFER_FORMAT_ARGB; + break; + default: av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");