From patchwork Tue Mar 2 15:23:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 26064 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B065744BA36 for ; Tue, 2 Mar 2021 17:50:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 85169689BEC; Tue, 2 Mar 2021 17:50:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18140689735 for ; Tue, 2 Mar 2021 17:50:38 +0200 (EET) Received: by mail-qt1-f178.google.com with SMTP id d11so14340021qtx.9 for ; Tue, 02 Mar 2021 07:50:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=MR5A2BPexZ2TXVBpViq4yhCvAgsQ1GWtuQkn2dgVbuE=; b=dl776+pKtKFtv57V9mosR0QKejsFTt1fxbynq4shDfRGIiRx1B2wgpV0MLztXvs4jF 5ysObQftsTZaU5CsSj7d6RMO7nd7mfCc52tfwqlDsuLi8HW5dVpTVMS+RXmflZRqutQ4 SnU599T976aB2RZRx8iYcEQFkqtDfOoBi6AtbyvapYf4+YCcchx4EG+oxzyDKIeukkay PrUnQm/Kk/5t2ZyYJPTPhwyyxh8XNpkmQuDyNEn7oOkZOJETDCOav7WFfGUf5N3YuO0e KAc/77YuXGUIqKZbhUyvdNrWu4qTG3KxqyUlfsIWGtQ6YV/omuI34Im6gE7mGxO90hx5 BsSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MR5A2BPexZ2TXVBpViq4yhCvAgsQ1GWtuQkn2dgVbuE=; b=fJtJO+431/X4dS/M6TforplDFK9EZG+kGbV+nGLdppjccplEdW0FEkltkBqfhyBMYI 8z6YZZjMmSTCNIVkuT/61CdKaZ3F+rMNBKGaRkxA/MRQ/83gsbZCzUPUfD1uRsmENoyi ijwxQHabcTi6fnT5CQ8CYQzYde+rtQ394hqGJfiPVAqAcJCUtJOdbpX0NYTytiraWc5q oc/vG+ly3ITNoGLceCJdvbADwGM1zpoAdVGnNCIibu04uyu5E35XuoGxcizPCAsYweUK Tvnv09aCgIsF/sXlzyRHX24sKqYqh9kL/Pr2JEB19x5BZiLX69uczd9gLmdbMxjOgbDu gHGA== X-Gm-Message-State: AOAM531ZjwIc6l21HYwJN8HNTS5xFKy9QmFH9GUYFGZDhOWqoj8eOkjx 0GcdNR0cVvO3zHTFk6WADZJEAT2eye7D1g== X-Google-Smtp-Source: ABdhPJz8bWBS2LC1uEtd5TqIqVGdZ6SZpS8b3bVgzCBTmf3S/m3s8RLOYPyMtB2dPty0eAioP4dPSw== X-Received: by 2002:ac8:68b:: with SMTP id f11mr18023240qth.373.1614698587708; Tue, 02 Mar 2021 07:23:07 -0800 (PST) Received: from localhost.localdomain (2603-7000-3c3e-ec9c-8d54-ffb5-9e89-283a.res6.spectrum.com. [2603:7000:3c3e:ec9c:8d54:ffb5:9e89:283a]) by smtp.gmail.com with ESMTPSA id e190sm15282156qkd.122.2021.03.02.07.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 07:23:07 -0800 (PST) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Mar 2021 10:23:04 -0500 Message-Id: <1614698584-36861-1-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 Subject: [FFmpeg-devel] [PATCH] ivfenc: write duration for frame_cnt=1. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/ivfenc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c index 0951f56..e22625b 100644 --- a/libavformat/ivfenc.c +++ b/libavformat/ivfenc.c @@ -23,7 +23,7 @@ typedef struct IVFEncContext { unsigned frame_cnt; - uint64_t last_pts, sum_delta_pts; + uint64_t last_pts, sum_delta_pts, first_duration; } IVFEncContext; static int ivf_init(AVFormatContext *s) @@ -86,6 +86,8 @@ static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt) avio_write(pb, pkt->data, pkt->size); if (ctx->frame_cnt) ctx->sum_delta_pts += pkt->pts - ctx->last_pts; + else + ctx->first_duration = pkt->duration; ctx->frame_cnt++; ctx->last_pts = pkt->pts; @@ -97,12 +99,15 @@ static int ivf_write_trailer(AVFormatContext *s) AVIOContext *pb = s->pb; IVFEncContext *ctx = s->priv_data; - if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && ctx->frame_cnt > 1) { + if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && + (ctx->frame_cnt > 1 || (ctx->frame_cnt == 1 && ctx->first_duration))) { int64_t end = avio_tell(pb); avio_seek(pb, 24, SEEK_SET); // overwrite the "length" field (duration) - avio_wl32(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1)); + avio_wl32(pb, ctx->frame_cnt > 1 ? + ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1) : + ctx->first_duration); avio_wl32(pb, 0); // zero out unused bytes avio_seek(pb, end, SEEK_SET); }