From patchwork Sat May 1 02:23:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27547 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp64158pxt; Fri, 30 Apr 2021 19:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPJXvb/kJcvzp7gSs8hIr6CIXLh6GcSVewH0Zk7fESqIOE7NgdTrqbhHBbzTtaSE5NBfo5 X-Received: by 2002:a17:906:7e51:: with SMTP id z17mr7453720ejr.92.1619835811323; Fri, 30 Apr 2021 19:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619835811; cv=none; d=google.com; s=arc-20160816; b=N7koWxLA8M4XgvBDeMN3WJl88DDAwkEvmUeqI6cw+nRQbD+K2wXbzKJjQiOsLl+V5E BBzlZWw8wKjyskd3TcdykH3aHtsnE4AhJZMQkkAWuLUP8lZf1xnQ5qnFM2sx4h6WTdCE rPGQS5un1EaebLrAUFUoIXHIWPQ70HDyfYbzEnyKKy7KawPKZSlMXJQoY+5ee0FZinXo GYgq/WKldRfeNMUaPdMuHPoPGJC+GdObzEiLmP3p4Xx1DhSLgBI40f4dBZtDzIg5GvUU TxMmjtFpkwWrIag4ZYvkFPSlH/IvQ8aBILVTaqH2/ZPuPZGJGket2nQpGUO6ja8LVYjw IsJQ== 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=L6oat8AJl3xcq5tn67KhhMp1YUPjEyrNBNFU58oPUZY=; b=XJCQp8eGvxGFkR5cuhMflm1iK5NtWGSo9ljZDXZFufvKriWtSYbD2WdMLutwJWeKq8 f4eSJSKZeAUPVdFk1VSq6FzczmCTFVSUxaLg/zcUU0P9WBIgJ8do4d7xYVbI9bSJ6iY8 bf3FKkD4qEyvBrmyymlHIqJyQzoNwo1sgiF3rbmcPjRaYMwWUt83HsWsuADXeqeOcfU0 YO33lrHPEJ0kJMPd60bOUoAp2oWvaC+9V7EURPt/ZrL0xLjVPXuyyUNSdbLerZEl03ec asDxgWRvgKtR4FNqSLPLE1oIW2kQAHXvL2+HWcpkqTtarSHxsoIdbrfPswKZ98D5E5A3 azWQ== 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 m16si3282731eds.603.2021.04.30.19.23.30; Fri, 30 Apr 2021 19:23:31 -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 F2CBF6806A2; Sat, 1 May 2021 05:23:24 +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 6265B680581 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-Cb; Sat, 01 May 2021 12:23:14 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 May 2021 12:23:01 +1000 Message-Id: <20210501022304.301425-2-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 1/4] libavcodec: write out user data unregistered SEI for x264 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: H3bHHJ3NLjgl Signed-off-by: Brad Hards --- libavcodec/libx264.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 22c91d8df7..c19a9b2804 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -31,6 +31,7 @@ #include "internal.h" #include "packet_internal.h" #include "atsc_a53.h" +#include "sei.h" #if defined(_MSC_VER) #define X264_API_IMPORTS 1 @@ -303,6 +304,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int64_t wallclock = 0; X264Opaque *out_opaque; AVFrameSideData *sd; + int total_unreg_sei = 0; x264_picture_init( &x4->pic ); x4->pic.img.i_csp = x4->params.i_csp; @@ -438,6 +440,25 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, 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_unreg_sei++; + } + if (total_unreg_sei > 0) { + x264_sei_t *sei = &(x4->pic.extra_sei); + sei->payloads = av_realloc_array(sei->payloads, + sei->num_payloads + total_unreg_sei, + sizeof(x264_sei_payload_t)); + for (int j = 0; j < frame->nb_side_data; j++) { + if (frame->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) { + x264_sei_payload_t *payload = &(sei->payloads[sei->num_payloads]); + payload->payload = frame->side_data[j]->data; + payload->payload_size = frame->side_data[j]->size; + payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED; + sei->num_payloads++; + } + } + } } do { From patchwork Sat May 1 02:23:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27549 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp64516pxt; Fri, 30 Apr 2021 19:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZtHpSdfktUjf7AJoINfxqP8yZWqy89V0BJdWznlh/J8C+yROmOHZhse78iR4Djurv2zIa X-Received: by 2002:a05:6402:6cf:: with SMTP id n15mr9116843edy.51.1619835850232; Fri, 30 Apr 2021 19:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619835850; cv=none; d=google.com; s=arc-20160816; b=HXHjgynKaBwGmQ8zTZy112phXwuFLFgToWWpDTdPI/yNceaAe8U1nfoywIPh5j7JHG eE42IYZA701t1Fn7lwecAR0fW8IthFOaESjKrO/lEMOvKfUXYuFSiev3af14ak/6v0rg gvjNcDtaIULrZYjXeKOICpoBPUBpWuEC+URgFn5XVoFK+xdcUOk3Qs6eJPQEHENvAfGS PLeQQFnisRvOEuZbckpvRewpSfmd3bHKm5+dCCjFlP4rent+szS4wDIqk+uDS8pwW9HE ZV5gq8sUcmi9jjuT++7/VyppEnZTtomlNXA3a0Xn8OyDGUGY6Ip5c33gHOAsNTpVRbOc Z+eA== 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=UkGLlNnDRC+SgMhq4oLuIsNAd0kYwQGdmwwt1gbRQFw=; b=Gf5t3yrhTxsjfR5FlXZ+JxEKCW79XZsagHpo6BcF0x6GXSDylSqRLuLvo8TQHk2dY7 KmQ9fpaboCTIIGck5frOy2JlkmKAjKHp1hsU7P+BUwwGfIHADuVU6CsCu2Z/ZoxLCQkP GAg6Vl0+P+TLt/NqCxqF7nJ6uHm01HVsIFcLLLbuswxLbw6YgpL3tiJctJIVVUSha6Ux vzEnvnLc9IhX4Nn3MnfTz7xXN630gtYzZF0B893QOmX00srozjr4Gi5G34zAvQ+I05aJ 5D10MlhOY8p0FPXgvKl0/k7zXx+vQl4IudT6ijmseVN1Z2Y9JXwnP7+Z9SjROnMcGyVU ct6A== 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 b6si5842938ejb.254.2021.04.30.19.24.09; Fri, 30 Apr 2021 19:24:10 -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 2B6E26880E6; Sat, 1 May 2021 05:23:30 +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 68A7B6808E6 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-F4; Sat, 01 May 2021 12:23:14 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 May 2021 12:23:02 +1000 Message-Id: <20210501022304.301425-3-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 2/4] libavcodec: write out user data unregistered SEI for x265 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: T8G4KEU/A5eg Signed-off-by: Brad Hards --- libavcodec/libx265.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index a1bd205201..013a991e52 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -484,6 +484,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int nnal; int ret; int i; + int total_unregistered_sei; ctx->api->picture_init(ctx->params, &x265pic); @@ -515,6 +516,25 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, memcpy(x265pic.userData, &pic->reordered_opaque, sizeof(pic->reordered_opaque)); } + for (int j = 0; j < pic->nb_side_data; j++) { + if (pic->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) + total_unregistered_sei++; + } + if (total_unregistered_sei > 0) { + x265_sei *sei = &(x265pic.userSEI); + sei->payloads = av_realloc_array(sei->payloads, + sei->numPayloads + total_unregistered_sei, + sizeof(x265_sei_payload)); + for (int j = 0; j < pic->nb_side_data; j++) { + if (pic->side_data[j]->type == AV_FRAME_DATA_SEI_UNREGISTERED) { + x265_sei_payload *payload = &(sei->payloads[sei->numPayloads]); + payload->payload = pic->side_data[j]->data; + payload->payloadSize = pic->side_data[j]->size; + payload->payloadType = USER_DATA_UNREGISTERED; + sei->numPayloads++; + } + } + } } ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal, 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) From patchwork Sat May 1 02:23:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27548 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp64243pxt; Fri, 30 Apr 2021 19:23:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmoWsOuf2PylS1klSlidT8dXkzwJmOqF4N6G83qtpNCtlPhcnAhLf0Uodgk6iX1Ka7V0et X-Received: by 2002:a05:6402:27d3:: with SMTP id c19mr9474502ede.129.1619835822183; Fri, 30 Apr 2021 19:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619835822; cv=none; d=google.com; s=arc-20160816; b=FQvOqC5KMJtkRl792F0ZGuMOiT+gD91OmEoyAj5smAqvf4twSJsQxyCYSJ1MWjNsxq BJ4HZJEGP/FB/ID9R8GKGZDq51WHl+ms0WKX79ww91ReLx4z0JhMTu//+o/O11UBQfKw oQr8xcYxDZNpGI22UWgvWBQ2JPgMZSi1LAjZOWcGz5l2xbwajXTgXWId9L0Ny8q1cA8z civlM1rHAaSLF/47OWeCMNyPV61AeVf0g7P8RytNiUmDLhUWrzuK8VQNKFYwXL1LQKeS OS9TjuQcKbFLk6qjPL+Cc0DXhUV3ghkPm97+Zl/KMcWDQ2VS6+aNb/3/rR8fpno1fiLH Mi5w== 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=NxsuuojewFPdzkup8c7icD8StTdcsOCp3/digFqAf9I=; b=lGu6C+bsYmOTfm1sEedryOjlIFqNp2Ju9A/DhwRruWGkJ1p4sfV4SdFt7y5Kx9x8X6 TMPs7Q6pzhjwJ1AgUcu50CHMIMm6NiYmbKI4IJ4/tm9oBfTf5ZTHIU7Nroknak74/ZL+ wc8YMvPMpDWSl1oAfwSZPNbn/wsxNH43g/lzLPXvL234ld8znFqmtuBmWYu72Y4q3int 1+CS9E0AFJH9gPqBj6lHq1TQUZADdyTd5RQc/tiEqnveYi7KJ1PCCt9qif4wbuxppZbk DU99RhVcssKpBonT/cf+U7daIr2meT5Zgz7Q9QAo92CN9Acr6ocJ1bGY1tQgNuhVdRc0 l4dg== 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 s27si3426721edw.377.2021.04.30.19.23.41; Fri, 30 Apr 2021 19:23:42 -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 274AB6808E6; Sat, 1 May 2021 05:23:26 +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 6B81C680911 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-K1; Sat, 01 May 2021 12:23:14 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 May 2021 12:23:04 +1000 Message-Id: <20210501022304.301425-5-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 4/4] doc: add example for user data unregistered SEI encoding 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: PdWnwDpkkFn5 Signed-off-by: Brad Hards --- configure | 2 + doc/examples/.gitignore | 1 + doc/examples/Makefile | 1 + doc/examples/Makefile.example | 1 + doc/examples/encode_unregistered.c | 205 +++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 doc/examples/encode_unregistered.c diff --git a/configure b/configure index 6580859ef2..1fad5b29ca 100755 --- a/configure +++ b/configure @@ -1708,6 +1708,7 @@ EXAMPLE_LIST=" demuxing_decoding_example encode_audio_example encode_video_example + encode_unregistered_example extract_mvs_example filter_audio_example filtering_audio_example @@ -3708,6 +3709,7 @@ decode_video_example_deps="avcodec avutil" demuxing_decoding_example_deps="avcodec avformat avutil" encode_audio_example_deps="avcodec avutil" encode_video_example_deps="avcodec avutil" +encode_unregistered_example_deps="avcodec avutil" extract_mvs_example_deps="avcodec avformat avutil" filter_audio_example_deps="avfilter avutil" filtering_audio_example_deps="avfilter avcodec avformat avutil" diff --git a/doc/examples/.gitignore b/doc/examples/.gitignore index 44960e1de7..d3f7739e68 100644 --- a/doc/examples/.gitignore +++ b/doc/examples/.gitignore @@ -4,6 +4,7 @@ /decode_video /demuxing_decoding /encode_audio +/encode_unregistered /encode_video /extract_mvs /filter_audio diff --git a/doc/examples/Makefile b/doc/examples/Makefile index 81bfd34d5d..00ef609c7b 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -5,6 +5,7 @@ EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video +EXAMPLES-$(CONFIG_ENCODE_UNREGISTERED_EXAMPLE) += encode_unregistered EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE) += filter_audio EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE) += filtering_audio diff --git a/doc/examples/Makefile.example b/doc/examples/Makefile.example index a232d97f98..f26a6597f8 100644 --- a/doc/examples/Makefile.example +++ b/doc/examples/Makefile.example @@ -18,6 +18,7 @@ EXAMPLES= avio_list_dir \ demuxing_decoding \ encode_audio \ encode_video \ + encode_unregistered \ extract_mvs \ filtering_video \ filtering_audio \ diff --git a/doc/examples/encode_unregistered.c b/doc/examples/encode_unregistered.c new file mode 100644 index 0000000000..e9309460c0 --- /dev/null +++ b/doc/examples/encode_unregistered.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2001 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @file + * video encoding with SEI (user unregistered) API example + * + * @example encode_unregistered.c + */ + +#include +#include +#include + +#include + +#include +#include + +static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, + FILE *outfile) +{ + int ret; + + /* send the frame to the encoder */ + if (frame) + printf("Send frame %3" PRId64 "\n", frame->pts); + + ret = avcodec_send_frame(enc_ctx, frame); + if (ret < 0) + { + fprintf(stderr, "Error sending a frame for encoding\n"); + exit(1); + } + + while (ret >= 0) + { + ret = avcodec_receive_packet(enc_ctx, pkt); + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + return; + else if (ret < 0) + { + fprintf(stderr, "Error during encoding\n"); + exit(1); + } + + printf("Write packet %3" PRId64 " (size=%5d)\n", pkt->pts, pkt->size); + fwrite(pkt->data, 1, pkt->size, outfile); + av_packet_unref(pkt); + } +} + +int main(int argc, char **argv) +{ + const char *filename, *codec_name; + const AVCodec *codec; + AVCodecContext *c = NULL; + int i, ret, x, y; + FILE *f; + AVFrame *frame; + AVPacket *pkt; + AVFrameSideData *side_data; + // This is from MISB ST 2101 + char sei_message[] = {0xa5, 0x50, 0x52, 0xaf, 0x52, 0x16, 0x5f, 0x45, + 0xa3, 0x18, 0x1c, 0xfc, 0x7a, 0xbb, 0xc2, 0x67, + 0x01, 0x70, 0xF5, 0x92, 0xF0, 0x23, 0x73, 0x36, + 0x4A, 0xF8, 0xAA, 0x91, 0x62, 0xC0, 0x0F, 0x2E, + 0xB2, 0xDA, 0x16, 0xB7, 0x43, 0x41, 0x00, 0x08, + 0x41, 0xA0, 0xBE, 0x36, 0x5B, 0x5A, 0xB9, 0x6A, + 0x36, 0x45}; + + if (argc <= 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(0); + } + filename = argv[1]; + codec_name = argv[2]; + + codec = avcodec_find_encoder_by_name(codec_name); + if (!codec) { + fprintf(stderr, "Codec '%s' not found\n", codec_name); + exit(1); + } + + c = avcodec_alloc_context3(codec); + if (!c) + { + fprintf(stderr, "Could not allocate video codec context\n"); + exit(1); + } + + pkt = av_packet_alloc(); + if (!pkt) + exit(1); + + c->bit_rate = 400000; + c->width = 352; + c->height = 288; + /* frames per second */ + c->time_base = (AVRational){1, 25}; + c->framerate = (AVRational){25, 1}; + c->gop_size = 10; + c->max_b_frames = 0; + c->pix_fmt = AV_PIX_FMT_YUV420P; + if (codec->id == AV_CODEC_ID_H264) + av_opt_set(c->priv_data, "preset", "medium", 0); + + /* open it */ + ret = avcodec_open2(c, codec, NULL); + if (ret < 0) + { + fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret)); + exit(1); + } + + f = fopen(filename, "wb"); + if (!f) + { + fprintf(stderr, "Could not open %s\n", filename); + exit(1); + } + + frame = av_frame_alloc(); + if (!frame) + { + fprintf(stderr, "Could not allocate video frame\n"); + exit(1); + } + frame->format = c->pix_fmt; + frame->width = c->width; + frame->height = c->height; + side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_SEI_UNREGISTERED, sizeof(sei_message)); + if (!side_data) + { + fprintf(stderr, "Could not allocate the video frame side data\n"); + exit(1); + } + memcpy(side_data->data, sei_message, side_data->size); + + ret = av_frame_get_buffer(frame, 0); + if (ret < 0) + { + fprintf(stderr, "Could not allocate the video frame data\n"); + exit(1); + } + + /* encode 1 second of video */ + for (i = 0; i < 25; i++) + { + fflush(stdout); + + /* make sure the frame data is writable */ + ret = av_frame_make_writable(frame); + if (ret < 0) + exit(1); + + /* prepare a dummy image */ + /* Y */ + for (y = 0; y < c->height; y++) { + for (x = 0; x < c->width; x++) { + frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3; + } + } + + /* Cb and Cr */ + for (y = 0; y < c->height/2; y++) { + for (x = 0; x < c->width/2; x++) { + frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2; + frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5; + } + } + + frame->pts = i; + encode(c, frame, pkt, f); + } + + /* flush the encoder */ + encode(c, NULL, pkt, f); + fclose(f); + + avcodec_free_context(&c); + av_frame_free(&frame); + av_packet_free(&pkt); + + return 0; +}