From patchwork Wed Jan 25 16:55:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40118 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp547142pzj; Wed, 25 Jan 2023 08:58:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXuLKURywBcLuMeCH5z8SkOJIWNYKJd01S3T2VbOMGT1agjYWOdReKthv0JYElWM67NPMcC0 X-Received: by 2002:a50:fe87:0:b0:49b:7416:e3f9 with SMTP id d7-20020a50fe87000000b0049b7416e3f9mr35418497edt.35.1674665899326; Wed, 25 Jan 2023 08:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665899; cv=none; d=google.com; s=arc-20160816; b=ePUBCTehlQyZO8jDdf1115vh4Jxy6b82ehf83UUsho6v2P6jdtiPSW/qUuidp2e0q0 QYhR/hB/6yMYgWCZ0pQ3my6zfUG71JlaYYl/tjNiOcvAdR5nzGhsAcYcSUe5p3/RcS/t 5rY+M5vAmw8oYlM7UzVPmoWNbvzLVG6ZOUXEbXt8rQUNVGRbEXEc84YLDjId/4DnTH7e Q1i6n5GVwAZsH7WSB2E1EzADSIowBe54IH931SsOLOikanTMCojrEChV57xI5WWBoVH5 fhN17cej5HEMoQKTz1Lr13sS4ZBseeBxngjqfw/9xUUvvAzYKTXoXXa6SajQDyH5pYDy D5HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=N6ak7J3LRZt0OpwHg7nD7XkEMzRYMI1prM75oLvRa20=; b=p/tTv2//6A3UN7iC7u10ePoWvMcyAPhVXmjtLuqamjelk5oLT99aupnrkXSyb8ZQT5 Wn5fgAeIFPH7X55BFRDWHnb0WOoEt/r4At3Jtt+bHx/2lVjFpOXiIlXrZjzZ0Yna+BKG SM9h0hiJvV1zB6ESGvOnvGM5UsSYDJaY3JzWB20ebiDdI3F0YxhQjAoslPgTQQw0iJPM NcTjKLN0EQjyCpq3rBcy7rJ1nPXGaX+Mt79Rd2C40JrGNGRUBjf3NGMciXenPdhSh13F 2cqXDJmUEJW7G9IuuJukkoIGad3rulNtWLucHZPV/TVMd+GVMDEys2XeQfxXVyEovTek dIhw== 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 m11-20020a50ef0b000000b0049b5322126dsi6842177eds.425.2023.01.25.08.57.55; Wed, 25 Jan 2023 08:58:19 -0800 (PST) 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 5F3C468BDF0; Wed, 25 Jan 2023 18:56:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 878C268BAEB for ; Wed, 25 Jan 2023 18:56:22 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3DBD1240178 for ; Wed, 25 Jan 2023 17:56:22 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id E2j1LCUOLwFh for ; Wed, 25 Jan 2023 17:56:20 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 54FAD240D0E for ; Wed, 25 Jan 2023 17:56:05 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 630903A0528 for ; Wed, 25 Jan 2023 17:55:59 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Jan 2023 17:55:37 +0100 Message-Id: <20230125165537.5371-19-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230125165537.5371-1-anton@khirnov.net> References: <20230125165537.5371-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/19] lavc/libaomenc: pass through frame durations to encoded packets 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Q6VAP9wKSJ89 --- libavcodec/libaomenc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index bd576fdd3a..0b88102c77 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -23,6 +23,8 @@ * AV1 encoder support via libaom */ +#include + #define AOM_DISABLE_CTRL_TYPECHECKS 1 #include #include @@ -1094,6 +1096,7 @@ static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, } memcpy(pkt->data, cx_frame->buf, pkt->size); pkt->pts = pkt->dts = cx_frame->pts; + pkt->duration = cx_frame->duration; if (!!(cx_frame->flags & AOM_FRAME_IS_KEY)) { pkt->flags |= AV_PKT_FLAG_KEY; @@ -1275,6 +1278,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, AOMContext *ctx = avctx->priv_data; struct aom_image *rawimg = NULL; int64_t timestamp = 0; + unsigned long duration = 0; int res, coded_size; aom_enc_frame_flags_t flags = 0; @@ -1287,6 +1291,13 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, rawimg->stride[AOM_PLANE_U] = frame->linesize[1]; rawimg->stride[AOM_PLANE_V] = frame->linesize[2]; timestamp = frame->pts; + + if (frame->duration > ULONG_MAX) { + av_log(avctx, AV_LOG_WARNING, + "Frame duration too large: %"PRId64"\n", frame->duration); + } else + duration = frame->duration ? frame->duration : avctx->ticks_per_frame; + switch (frame->color_range) { case AVCOL_RANGE_MPEG: rawimg->range = AOM_CR_STUDIO_RANGE; @@ -1300,8 +1311,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, flags |= AOM_EFLAG_FORCE_KF; } - res = aom_codec_encode(&ctx->encoder, rawimg, timestamp, - avctx->ticks_per_frame, flags); + res = aom_codec_encode(&ctx->encoder, rawimg, timestamp, duration, flags); if (res != AOM_CODEC_OK) { log_encoder_error(avctx, "Error encoding frame"); return AVERROR_INVALIDDATA;