From patchwork Sat May 15 05:43:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27783 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp1067914iof; Fri, 14 May 2021 22:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUPsuO4E38nzKPPVwq5mnEBKmE4q79D7vfOfXsMNki7HMos3xgQLGheXdnmSdd2UNANv8Z X-Received: by 2002:a17:906:1984:: with SMTP id g4mr50449323ejd.525.1621057445656; Fri, 14 May 2021 22:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621057445; cv=none; d=google.com; s=arc-20160816; b=orCXqYgbK4Sy82OHUZODntYU8/91vyhx/lbBMnNiQc/29nV2Y0u9ITr+auANXpCiO7 JnTewm6dr99cWLI1m6c003hfSK4wyNjTnRTB6GuLxrewzaM7syDU53OnCMl+P6cnqTCw 6N5b/1dYMWe7RLu1IcKSJ0d8MvWGdmtDL6fd5Ha7sUMllfrsaGWKPvJomH7MgHhGdOPn XShxzJTonoEhefESw8qlApQtlSF1GZJnMF3RDvKRukAQ+hd0X2WBoyvaKzJotYpxUX4o tC3WdAdnLgDF2ZNtSLb6CV3E7KGKYgmN6LjCgf/Cv4LRp22I5Y5bBXwO8L+fUidFM5JW nH2Q== 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=iZDvfnN4vGSEnfhxEL+81Ef+77ANx9AU+NlKU7gCkEI=; b=n8aAZojqWdNmSmfaC3C7X6oj4neRsKnG0lD/YN79/MpiImN9Az5MeeS6WfRQ5U9SaM KYLHN+qYEXVcb6SyhsJR397Yj1Io7JirmX4EsJjO9ayEj0p5WR/o4XHU7U53rBPqbov4 nUf+CSlwRqTnX1vScazBY1kNSSPCKZ5lsHAuLhsHd2PLSojHz5/qeE2+KlfLjdykZzoM swiIftWykWcU2A1n1/rtT1zxtCUtK6Zth2ochmwwVM764DbxzMvrSljMA7qj/8Qncx2q JAcWlAq5fX2dgEDjOujfggkRZ9MXGpTPpGIh4nTuhUqncx6rBdW9AZvkQECiMvYx85mi bPfg== 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 b14si7670559edx.131.2021.05.14.22.44.05; Fri, 14 May 2021 22:44:05 -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 1DC43688128; Sat, 15 May 2021 08:43:48 +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 67E9F68094F for ; Sat, 15 May 2021 08:43:39 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:60460 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 1lhn5N-0009gp-62; Sat, 15 May 2021 15:43:37 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 May 2021 15:43:15 +1000 Message-Id: <20210515054317.30414-2-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210515054317.30414-1-bradh@frogmouth.net> References: <20210515054317.30414-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 v3 1/3] 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: iTSUSjuTZOSZ 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..feee8f8ee6 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_log(ctx, AV_LOG_ERROR, "Not enough memory for unregistered SEI, skipping\n"); + av_free(sei_data_a53_cc); + sei->num_payloads = 0; + } 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 Sat May 15 05:43:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27781 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp1067995iof; Fri, 14 May 2021 22:44:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgZTGbFyzSlIpc8fXGBlmwta+nGuCBnyInS4hY25JBfMKQEPYpO+hCkkpuPbL8dDW2ZiiW X-Received: by 2002:a50:cdd1:: with SMTP id h17mr59348140edj.178.1621057455974; Fri, 14 May 2021 22:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621057455; cv=none; d=google.com; s=arc-20160816; b=V8PZZwEGW9Ny0tTpXsgGEOp8Y4EsEAbb2pwtiP+Xq8kXJ1QsKZe2ga9fCkdkBI9yfO U25fQvxrXvw1pLhG8jt9bOsTY5oAOMvcIwNbRBQbk+Ked5PMU6DkAzoHZTdH68uMuCzE TqaJDJZly8b8NW4wVzu4MNjdbqXdC4mOb6HvVTUKAnenKvgHhOrQ8jU4nvTGJ/Y6tPGR iISMMpK6mKxn+rJTa+5asJ4Dt+a0dlN33Z6pSZ2in9u+AkuDJNradt25kR+WY8T2UNI9 R5ApN27bcjJrvKSM86xczxxpbT4CqgUXq2yzhis3nE5mPMLdGr+05B1KeI5+hZE7pjt4 av2w== 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=pxINYXVcuqGr7zhiEAMRr6Q4tOiKVbv2Y+YzfOnjCWw=; b=IwyjaAyp6dF432tdJI+zXSkQ1HNa5CsswizxGI2vTGuHHLabBwE3opuROKidJQDzWG yP4y8WFTMFK4Rm0L54WLYusBRhmqfuFHy+OldM+BCcwcw8nfGWqWYl9tS3JQFCVR6IGk aecJxCdF6/LFa2If5UpvaT61SqqYe73zCVHaDhX37QhrjsZxG9/nrXQiLjiXFGCt5ADx +QFkknXKZI8fT08ZhHk91j4elsOEqBO9D6/O6eNpcnWuQFcLahKlbC/A2BohwzPsitgc k0e088zvgg7r1Ue+pNiXRRWK+BTOVRxTx0b+E23+htMVEl6i+K4w2m/obe58sDovV3jP xQ8A== 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 gg35si7246626ejc.460.2021.05.14.22.44.15; Fri, 14 May 2021 22:44: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 342E168813A; Sat, 15 May 2021 08:43:49 +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 7EE6D680C04 for ; Sat, 15 May 2021 08:43:39 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:60460 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 1lhn5N-0009gp-9E; Sat, 15 May 2021 15:43:37 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 May 2021 15:43:16 +1000 Message-Id: <20210515054317.30414-3-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210515054317.30414-1-bradh@frogmouth.net> References: <20210515054317.30414-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 v3 2/3] 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: Js6ktneJaPGa 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..e21eb8828d 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) { + av_log(ctx, AV_LOG_ERROR, "Not enough memory for unregistered SEI, skipping\n"); + sei->numPayloads = 0; + } 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 Sat May 15 05:43:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27782 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp1068090iof; Fri, 14 May 2021 22:44:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtqjE1o+tsrSfvetbrwR0Hj8UrC/MpWiU0gABXZfgtE3+PJFDmScKjHSbESJRK+ex9UUu7 X-Received: by 2002:a17:907:7747:: with SMTP id kx7mr35268626ejc.400.1621057466460; Fri, 14 May 2021 22:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621057466; cv=none; d=google.com; s=arc-20160816; b=fIOLzrI0RycHVH/Ts9s1SK7ROryI5//X/KFlwIiMTj7L/Aapl5ixSrAW9L4T8CntP8 1iwcWm8j2f3nkhMEdBCgvqZ5Gk/hW0kqYxQhvnYxzpCKueZBRj1Sl6NVqskIESuNjQTP EYbJtJgRFBsaMb6rx8KviGUSPCqPiQEHbXmFOFx82FArcuvxg+YqrZIaqPcaIdNHYUbA 4s8jKjyRtZN3JIYhVG41VNrNS2XIr51/PUoszQiFPz52qoJd3wrk6QKIcRCpfmWjNwY8 ZtWrRPt0S0+jctCfuFZGM01MP78IHi7zkmzvM9keHesKFlRYd/7YTloaSwfYJSNzrTvg VexA== 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=ZcX9wr4PcSQqXPXKXYFNp+WJjj9wGYVf2aW2NqYCXas=; b=tVdwbW1kjtCVnn14wQyrtk7gWxVDwcOTSv09QfXbJMjbnMpAjjnFAvO/hkXR1PNhXF 0+DXYxuYcL2vXG7FIEHM1k9/WoKdPJB8yoa+5kFMxqj1qzoVJg6MnPU2Qmvz57hF6dJA RBQozRnCp+UWg3Tx1JCWz7fpJuTf+hjvoSbwkVyGUXlmgSmImyugOlNLndFPulExUf47 hmgZxX9WEn9u7nS51CNP7zenht7pJHuOt2Af+ZBttbRkcj/WUozdhY6JIk64eUxRIckB +rUxgC2x0XfupO1FpBWys+gVEuVr0DIzyrj18S1m2+73mEwI0YtMW8Olof2jEpFaWw6m sBZQ== 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 f17si8189728edx.76.2021.05.14.22.44.26; Fri, 14 May 2021 22:44:26 -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 37F6A688178; Sat, 15 May 2021 08:43:50 +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 9C868687F43 for ; Sat, 15 May 2021 08:43:39 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:60460 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 1lhn5N-0009gp-CQ; Sat, 15 May 2021 15:43:37 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 May 2021 15:43:17 +1000 Message-Id: <20210515054317.30414-4-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210515054317.30414-1-bradh@frogmouth.net> References: <20210515054317.30414-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 v3 3/3] 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: tmw7B3HZQkmW 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..9bf2728cba 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_log(ctx, AV_LOG_ERROR, "Not enough memory for closed captions SEI, skipping\n"); + av_free(a53_data); + sei_count = 0; + } 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_log(ctx, AV_LOG_ERROR, "Not enough memory for timecode SEI, skipping\n"); + av_free(a53_data); + av_free(tc_data); + sei_count = 0; + } 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_log(ctx, AV_LOG_ERROR, "Not enough memory for unregistered SEI, skipping\n"); + av_free(a53_data); + av_free(tc_data); + sei_count = 0; + } 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)