From patchwork Mon May 17 08:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27823 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2638780iof; Mon, 17 May 2021 01:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbGrULhIultdjlMFQwFodxaU8eCRdWluVcAdsO4ov7bXPk3/lTH+hfGnwZqso+oFy//Rb2 X-Received: by 2002:aa7:c787:: with SMTP id n7mr35451593eds.309.1621239615572; Mon, 17 May 2021 01:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621239615; cv=none; d=google.com; s=arc-20160816; b=0dzrqus5Draat2wITcKfSg8/Wu3dxktwBHEeR7/D7Lz75XZb48kx66cF2z/nRaAaEz 4nqwU80jrHLSMNa1i+NfNJAqkOD9KzV9P8yvVB5Wk2ljEBvsy5LEmjy/6uVvibWkZ3jm tnsi8i2tDI8wLWGm4UsZwniJy6kZb7U3DjyAO9fqkiNzPalIpfITQvff8duKG4jCDfdC cbNA2YHDpjq/iZ/GyxGTfl6IagSY7/MxqDy3PKNtqNjobMYqr0zRSs2Sz4B/i4rPkcjg E39lGcvUwxmdi4FaAUfLi10S2szOAtqsu4/kKRUH3BtoSibQIJk1CDchJIvgsoCq66wb TMGQ== 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=WPaLHbHeaExQBG7qBsVJL9QXHNih+44ZxheJolVf7Hg=; b=zv3c2Tz6vGphPwMr9ztYps9TouZ+74psIeWRUYkNKB8pPgRYXfjl6CH/WXGOXgyVaC OarwtwwJ+wJo5mvj3uKO8Avy2McmfDqGFna6GuoxAbeIQlPAhi+g43BVw9I/LbR+2oSo j8aG6U6f5XI43MGBoU3sFo4YFboovzSMDIyo9e2QlmOjB+j2rpb8WBBTd/FB6WX/RjfJ br5gcBY3sPooYBpe+rUrIKJWtQfoKGSR1ey5U0fKrNks68Ia8P94ohoM555mOIG3h1FY unknki+19EBvscPZjcZM2wHwygbsy35ZNniCvUIrlARfK2QqkiqUeQhIP58kviwe4DLY os1g== 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 g8si14932114eds.14.2021.05.17.01.20.15; Mon, 17 May 2021 01:20:15 -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 727A96882EE; Mon, 17 May 2021 11:20:03 +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 5A451688103 for ; Mon, 17 May 2021 11:19:55 +0300 (EEST) Received: from [1.129.163.84] (port=50590 helo=localhost.localdomain) by cp1.nerdvana.net.au with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1liYTg-0000JJ-Vr; Mon, 17 May 2021 18:19:53 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 May 2021 18:19:42 +1000 Message-Id: <20210517081944.35238-2-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210517081944.35238-1-bradh@frogmouth.net> References: <20210517081944.35238-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 v5 1/3] libavcodec/libx264: write out user data unregistered SEI 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: /Uzw/pS3VRA9 Signed-off-by: Brad Hards --- libavcodec/libx264.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 1c27f7b441..1fac141ec6 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; @@ -316,6 +318,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt); if (frame) { + void *sei_data_a53_cc; for (i = 0; i < x4->pic.img.i_plane; i++) { x4->pic.img.plane[i] = frame->data[i]; x4->pic.img.i_stride[i] = frame->linesize[i]; @@ -349,28 +352,50 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, reconfig_encoder(ctx, frame); if (x4->a53_cc) { - void *sei_data; size_t sei_size; - ret = ff_alloc_a53_sei(frame, 0, &sei_data, &sei_size); + ret = ff_alloc_a53_sei(frame, 0, &sei_data_a53_cc, &sei_size); if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n"); - } else if (sei_data) { + } else if (sei_data_a53_cc) { x4->pic.extra_sei.payloads = av_mallocz(sizeof(x4->pic.extra_sei.payloads[0])); if (x4->pic.extra_sei.payloads == NULL) { av_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions, skipping\n"); - av_free(sei_data); + av_free(sei_data_a53_cc); } else { x4->pic.extra_sei.sei_free = av_free; x4->pic.extra_sei.payloads[0].payload_size = sei_size; - x4->pic.extra_sei.payloads[0].payload = sei_data; + x4->pic.extra_sei.payloads[0].payload = sei_data_a53_cc; x4->pic.extra_sei.num_payloads = 1; x4->pic.extra_sei.payloads[0].payload_type = 4; } } } + 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)); + if (!sei->payloads) { + av_free(sei_data_a53_cc); + sei->num_payloads = 0; + return AVERROR(ENOMEM); + } else + 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++; + } + } + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST); if (sd) { if (x4->params.rc.i_aq_mode == X264_AQ_NONE) { From patchwork Mon May 17 08:19:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27824 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2638899iof; Mon, 17 May 2021 01:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXf217/AsVJfeukoAuJUXJxBZBpdY2/FR5cW11R0Is82wC52UMAa2N729NWi8i9A2m6U6J X-Received: by 2002:a17:906:e0d5:: with SMTP id gl21mr3078898ejb.93.1621239625580; Mon, 17 May 2021 01:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621239625; cv=none; d=google.com; s=arc-20160816; b=zeu9KyFrc20JCKWv0/l2aeSiPde6XWY30frzQ595nhoVdTcKEjx95AdXti3zGobWo3 5mea8bhQSprPGBdMaadC5olIIODsXoK7O6O+/ZOPM5J1HUa3sPjc1VNjPquiLJKlIiOB 6wCenJHrBJDgocKtRDYWRibDocQKhOyIdxh/6UEwEO6UROmw5qmE8Yzcl3K/sP7KTa00 KtlETpklzZGmYNuxzbltIjT+7w7kGPhKX1ZY9XWNM7airQIaYJ93bFYUpW/4Ut9bruax 1ug7vOCZEj27H28j19OL4ZsqswYRKbW/1ms3YaviTkaSf4wGxvldU2qd4q546n9JN71G 4iiw== 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=OFFqQZB2PBhVL9MnvYizG+Mzc+CJeIkFZF8i2Whi7xM=; b=WWqEKIKqGj+e3z+5a79OzNHqaEyhB55OAvnLlxu4+EY7Q68IrRw+kQ03O05BYqg+b4 S8M2tjmXW0IYYAPs/W21YifPGIA+5i98kSuqaSagIoxD1sWqP4PQytZ7OfP6UzjeYrno hbRUXM/ksHBxWjy7SrGuRzqrJu9O7srUs98FcAx9Tw3zL30lG6Ok0MhlUUjMNlS7nt3t TbNMh7yXBUt6buTgrH8hKgratUSV8tCuOb9njFIZ0E1VdW/x9i9DXDjCihu3/DR+TTkj E6rdd1cELqE7bX7qubH3Yh/zOoo5TVbR9b0yHYN+rEVaDaT7iAgcuk6JE4GFKNRknQSl erZQ== 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 5si13924010ejw.423.2021.05.17.01.20.25; Mon, 17 May 2021 01:20:25 -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 785AC6898FC; Mon, 17 May 2021 11:20:04 +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 87DDA68818D for ; Mon, 17 May 2021 11:19:55 +0300 (EEST) Received: from [1.129.163.84] (port=50590 helo=localhost.localdomain) by cp1.nerdvana.net.au with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1liYTh-0000JJ-7L; Mon, 17 May 2021 18:19:53 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 May 2021 18:19:43 +1000 Message-Id: <20210517081944.35238-3-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210517081944.35238-1-bradh@frogmouth.net> References: <20210517081944.35238-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 v5 2/3] libavcodec/libx265: write out user data unregistered SEI 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: GG+J5xOkP1BE Signed-off-by: Brad Hards --- libavcodec/libx265.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index a1bd205201..d66506dda9 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,27 @@ 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)); + if (!sei->payloads) { + sei->numPayloads = 0; + return AVERROR(ENOMEM); + } else + 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 Mon May 17 08:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27825 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2639026iof; Mon, 17 May 2021 01:20:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiE7saqbSRESZwBxBcM6lMWrdVdiF14RkwN3A1PgaVB2S+3aDxt7fHZdL4d8RqZqGPlKS4 X-Received: by 2002:a17:906:454b:: with SMTP id s11mr17613098ejq.3.1621239635826; Mon, 17 May 2021 01:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621239635; cv=none; d=google.com; s=arc-20160816; b=V5jbRtT+oDP4THRBamzpyZx3K9VgELvalRcvqYy1Yi+9B0VSuSfto018/GGr4Bgfue LlAj/idRdr4fOZ9QAfF4sltDBbFpNBhOSt4vmzi7TkKEKmy5ZmLjwnf3QM4yM3nOmpBF F0n1R2RoxN7kZFzn4RbUbXldUc7q8f7z4qgN7FYbvaW+HyIu5QQYD6xG0S2crEXlZtyy 8SJQ9kh0/VLt+PE1wGuKyiXBsBf/q3AV2DgkH/ElVKNHJQGIZB9RzSRuJOVSm9QnuJwB wwS9euaEle2N2timomZGtzUCvsyNGCn53UcMnZrh01G90KmoAXok9s0exbfA7C9f2TPT VI3A== 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=jlVO10fw98SH2Su9zUl6s5XSDwEjlDZShXVykRLHg5A=; b=dvsLhpSJMitDrG7ZarxP6fxkyYd6X5KwgOq99gesNrcw/Os2/v9puh4TJrX1I3ZJCs UtZCmhAo4V+bByyBH3XTK7luqxqeHK4I1j1no3WYmIcEB19vFOB0HUw0SaI4nVdPd5Ir M3EDUMR1LRJarU+qpKJWNpawUdYueB9KCx56fUMeIICX+9mjGsLQQwzezPxtI8QQFt3t k1R8XLGUTX5a+GL7ZayRlxpVYB6oNKK+cGSEb5zaxnWOMa5sFencdujgcr6ng0hwZU02 weKg0BI0ahjt9PQsoIskVnTvFWKKk0CSHIkS3bd3onhgDK/2ZodXa/BsDFfCOj29whKl T/zw== 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 x18si16231826ejd.75.2021.05.17.01.20.35; Mon, 17 May 2021 01:20:35 -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 841B8680307; Mon, 17 May 2021 11:20:05 +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 B542B6882EE for ; Mon, 17 May 2021 11:19:55 +0300 (EEST) Received: from [1.129.163.84] (port=50590 helo=localhost.localdomain) by cp1.nerdvana.net.au with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1liYTh-0000JJ-F5; Mon, 17 May 2021 18:19:53 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 May 2021 18:19:44 +1000 Message-Id: <20210517081944.35238-4-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210517081944.35238-1-bradh@frogmouth.net> References: <20210517081944.35238-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 v5 3/3] avcodec/nvenc: write out user data unregistered SEI 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: SZfT9RgYPNr/ Signed-off-by: Brad Hards --- libavcodec/nvenc.c | 64 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0dcd93a99c..e22fdfb5a8 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; @@ -2185,6 +2186,8 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) return AVERROR(EINVAL); if (frame && frame->buf[0]) { + void *a53_data = NULL; + void *tc_data = NULL; in_surf = get_free_frame(ctx); if (!in_surf) return AVERROR(EAGAIN); @@ -2230,7 +2233,6 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) pic_params.inputTimeStamp = frame->pts; if (ctx->a53_cc && av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC)) { - void *a53_data = NULL; size_t a53_size = 0; if (ff_alloc_a53_sei(frame, 0, (void**)&a53_data, &a53_size) < 0) { @@ -2238,15 +2240,21 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } if (a53_data) { - sei_data[sei_count].payloadSize = (uint32_t)a53_size; - sei_data[sei_count].payloadType = 4; - sei_data[sei_count].payload = (uint8_t*)a53_data; - sei_count ++; + sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD)); + if (!sei_data) { + av_free(a53_data); + sei_count = 0; + return AVERROR(ENOMEM); + } else { + sei_data[sei_count].payloadSize = (uint32_t)a53_size; + sei_data[sei_count].payloadType = 4; + sei_data[sei_count].payload = (uint8_t*)a53_data; + sei_count ++; + } } } if (ctx->s12m_tc && av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE)) { - void *tc_data = NULL; size_t tc_size = 0; if (ff_alloc_timecode_sei(frame, avctx->framerate, 0, (void**)&tc_data, &tc_size) < 0) { @@ -2254,13 +2262,46 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) } if (tc_data) { - 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; - sei_count ++; + sei_data = av_realloc_array(sei_data, sei_count + 1, sizeof(NV_ENC_SEI_PAYLOAD)); + if (!sei_data) { + av_free(a53_data); + av_free(tc_data); + sei_count = 0; + return AVERROR(ENOMEM); + } else { + 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; + sei_count ++; + } } } + 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)); + if (!sei_data) { + av_free(a53_data); + av_free(tc_data); + sei_count = 0; + return AVERROR(ENOMEM); + } else + 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); + if (sei_data[sei_count].payload) + 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 +2315,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)