From patchwork Sat May 1 02:23:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27546 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp64347pxt; Fri, 30 Apr 2021 19:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+ZhBMjqnmymKHc95Z7z2yQb5OutEDAZIzedYTgWEbAH+fh7jnGdC+0T0LbkDnr/cf/9jv X-Received: by 2002:aa7:cb0a:: with SMTP id s10mr9295463edt.36.1619835832306; Fri, 30 Apr 2021 19:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619835832; cv=none; d=google.com; s=arc-20160816; b=vXxYtNwCO+bI4f6EIoEtH6zbvooxk6/XEKnmwLkSfOGZ2pPsp/7woHsDene4yqmsAe OB0KsfORgBDI8EpuPubkdRfWYkVg60WsX1M6kj2jr8qHAGyqMsCenBWr8zHZQSxi6cBl O5wKcg02tgJttvdkBGmh+eq4OvLENTDUkbJAbBXpxH8JXCccveEHP/BcUYsD9Pm53xNH Z12xmg7KsQ8cKpjqvPL5zqk22T5Bdi3ZaEf9qo1If+Nl1SwMyPL6X1VfAuGs9Hsn26Tv yXHm/Fnm1GCd3b/cVi9M4yAPMMV+XyHBJ5HydhSYc4mBaWqGo2ALNdzJM3a83Bv/Plsu 75AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=YOMmoAZrlaK+H+0Ayay5UR5YMrvb/+H3m3uqzaR1GjY=; b=oBXxooAfJNmIy+8gCIAP1pZQMAywvHvSZ+hNq71WG3CJTfa252cRlgzOWV8Nxldg3d aT82cwprZqqu3+zgJRsAbxXOosIYC3TOpZHLDGh8pBDEy/jGhKmozhb5o3w10pyyhUCd n19QwnFBveUxG3SWQUVvh4deByvDB9q8Ow8eQbzagV3nkjGvDHJSjAtivnN36rHajgRS I+Aflf+FUhZy+yvD7jaDiMxZPgB4a7spDO+Xzyjs9cO0InXXTx/xt5ZJE6pWVRomOnFk jQVpRf81fUzmbhN2oK/ynYvK1qlHCBAUMa68j0OkP2I0qhafDBiuXeO/yBv4uELBlvlS yr1g== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t4si4628272ejs.517.2021.04.30.19.23.52; Fri, 30 Apr 2021 19:23:52 -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; 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 2926768807C; Sat, 1 May 2021 05:23:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from cp1.nerdvana.net.au (cp1-new.nerdvana.net.au [113.212.99.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 644E56806A2 for ; Sat, 1 May 2021 05:23:17 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:41406 helo=audax.fritz.box) by cp1.nerdvana.net.au with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lcfHm-0008W8-HN; Sat, 01 May 2021 12:23:14 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 May 2021 12:23:03 +1000 Message-Id: <20210501022304.301425-4-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210501022304.301425-1-bradh@frogmouth.net> References: <20210501022304.301425-1-bradh@frogmouth.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cp1.nerdvana.net.au X-AntiAbuse: Original Domain - ffmpeg.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - frogmouth.net X-Get-Message-Sender-Via: cp1.nerdvana.net.au: authenticated_id: bradh@frogmouth.net X-Authenticated-Sender: cp1.nerdvana.net.au: bradh@frogmouth.net X-Source: X-Source-Args: X-Source-Dir: Subject: [FFmpeg-devel] [PATCH v2 3/4] libavcodec: write out user data unregistered SEI for nvenc 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 Cc: Brad Hards Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: q9q8KqoHhV+G Signed-off-by: Brad Hards --- libavcodec/nvenc.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0dcd93a99c..c7659975b9 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -2170,9 +2170,10 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) NVENCSTATUS nv_status; NvencSurface *tmp_out_surf, *in_surf; int res, res2; - NV_ENC_SEI_PAYLOAD sei_data[8]; + NV_ENC_SEI_PAYLOAD *sei_data = 0; int sei_count = 0; int i; + int total_unregistered_sei = 0; NvencContext *ctx = avctx->priv_data; NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; @@ -2238,6 +2239,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } if (a53_data) { + sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD)); sei_data[sei_count].payloadSize = (uint32_t)a53_size; sei_data[sei_count].payloadType = 4; sei_data[sei_count].payload = (uint8_t*)a53_data; @@ -2254,6 +2256,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } if (tc_data) { + sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD)); sei_data[sei_count].payloadSize = (uint32_t)tc_size; sei_data[sei_count].payloadType = SEI_TYPE_TIME_CODE; sei_data[sei_count].payload = (uint8_t*)tc_data; @@ -2261,6 +2264,25 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } } + for (int j = 0; j < frame->nb_side_data; j++) { + if (frame->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) + total_unregistered_sei++; + } + if (total_unregistered_sei > 0) { + sei_data = av_realloc_array(sei_data, + sei_count + total_unregistered_sei, + sizeof(NV_ENC_SEI_PAYLOAD)); + for (int j = 0; j < frame->nb_side_data; j++) { + AVFrameSideData *side_data = frame->side_data[j]; + if (side_data->type == AV_FRAME_DATA_SEI_UNREGISTERED) { + sei_data[sei_count].payloadSize = side_data->size; + sei_data[sei_count].payloadType = SEI_TYPE_USER_DATA_UNREGISTERED; + sei_data[sei_count].payload = av_memdup(side_data->data, side_data->size); + sei_count ++; + } + } + } + nvenc_codec_specific_pic_params(avctx, &pic_params, sei_data, sei_count); } else { pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS; @@ -2274,6 +2296,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) for ( i = 0; i < sei_count; i++) av_freep(&sei_data[i].payload); + av_free(sei_data); res = nvenc_pop_context(avctx); if (res < 0)