From patchwork Fri Aug 6 09:16:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 29308 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp344067ioh; Fri, 6 Aug 2021 02:17:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztSxtETjPBXPhP/cS0n+6YdKf7d4Q0xsydAbvuJJ/uak2c88NrE3biBTjxYLWot5IUzLn7 X-Received: by 2002:a17:906:ecf7:: with SMTP id qt23mr8894138ejb.64.1628241424752; Fri, 06 Aug 2021 02:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628241424; cv=none; d=google.com; s=arc-20160816; b=Lx3CVspOcLcP+L83UDo+UwrcOM/Ef8CrQ6hNbcHEsRirWaO7/H/lgVhR2RKKmlN0Qm biylEMZz/VK1L04W2AIlCtVZxLlIoXXd0PFoxFgybVVG+zcZ4dZUF7pWS3c1oyvwjvHd I7rUUco6sPhhNBJKbP2RAgVejVU4x1Sq0CNU1riC33olDLGmFzTMf5ApHq2lyISnwFW4 E6f6ewpObcPZ2cCLj+P95REaALHlULY4ymjGCARC/eU2rsibZX9JfcE9wwNQf97zvLrC /4v/phKsEo4Cpw+ro9WM5yfdtHqgAWdVMgFX9wECn/FAgtVhlWjdcjNSlPxYZBWD9byE n18w== 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:message-id:date:to:from :delivered-to; bh=ovyaCIefdsFi7yyg2NNgoVJYpzhVCiwNqLR7cXeDrN8=; b=qarAAlz9oKXhT5rW+TRBQ1yAmIYLtqfvcaYcfitEO6ilEGtBc9ea/KHvOqPJc51/jl HTp735ld2yvkmP7lIMjS/o/4BhUK5oy0UoNvb2v35d4X77671dA8AjE8bTyeS9m/y/j2 0JbhQg5k8M8SeAsYRzXQCsG85wJXKAQyjICxtxu3Nn3LodIYSg4+Qgaklqu/FdcBO9rx U6M7EITq8yVSkMCusdlPhol+TN3vs38dtUHtAbVQ6f+q53pRtCyIflEQljlIfGxl5mtk ndypwLBJBZg/m9mwdG5IPElwpzdZQD926dmAfqYXwOfXui79b8OJNAIEwbIvfLHXSfyK o5tw== 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 a9si9015612eda.118.2021.08.06.02.17.03; Fri, 06 Aug 2021 02:17:04 -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 2EA63680CEB; Fri, 6 Aug 2021 12:16:59 +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 9B0FE680CEB for ; Fri, 6 Aug 2021 12:16:51 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:46432 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 1mBvyB-000Cit-Iw; Fri, 06 Aug 2021 19:16:47 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Aug 2021 19:16:33 +1000 Message-Id: <20210806091633.2083-1-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 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] libavcodec/libx264: add 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: +CSV66pWPe0S MISB ST 0604 and ST 2101 require user data unregistered SEI messages (precision timestamps and sensor identifiers) to be included. That currently isn't supported for libx264. This patch adds support for user data unregistered SEI messages in accordance with ISO/IEC 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics). This code is based on a similar change for libx265 (commit 1f58503013720700a5adfd72c708e6275aefc165). --- libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 9afaf19547..e9bbe8d494 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -32,6 +32,7 @@ #include "internal.h" #include "packet_internal.h" #include "atsc_a53.h" +#include "sei.h" #if defined(_MSC_VER) #define X264_API_IMPORTS 1 @@ -114,6 +115,9 @@ typedef struct X264Context { * encounter a frame with ROI side data. */ int roi_warned; + + void *sei_data; + int sei_data_size; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -317,6 +321,9 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt); if (frame) { + x264_sei_t *sei = &x4->pic.extra_sei; + sei->num_payloads = 0; + 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]; @@ -439,6 +446,27 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, } } } + + for (int j = 0; j < frame->nb_side_data; j++) { + AVFrameSideData *side_data = frame->side_data[j]; + void *tmp; + x264_sei_payload_t *sei_payload; + if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED) + continue; + tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload)); + if (!tmp) { + av_freep(&x4->pic.extra_sei.payloads); + av_freep(&x4->pic.prop.quant_offsets); + return AVERROR(ENOMEM); + } + x4->sei_data = tmp; + sei->payloads = x4->sei_data; + sei_payload = &sei->payloads[sei->num_payloads]; + sei_payload->payload = side_data->data; + sei_payload->payload_size = side_data->size; + sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED; + sei->num_payloads++; + } } do { @@ -505,6 +533,8 @@ static av_cold int X264_close(AVCodecContext *avctx) x264_param_cleanup(&x4->params); #endif + av_freep(&x4->sei_data); + if (x4->enc) { x264_encoder_close(x4->enc); x4->enc = NULL;