From patchwork Wed May 31 14:54:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41919 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328244pzb; Wed, 31 May 2023 07:57:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cnY3VrR7zVa1XuW5q+l0bLPODfKJQGtw1zuv75iVz0UJrZjbLmRGnVkRBTKawpZH9iNSq X-Received: by 2002:a17:907:c09:b0:96a:649b:3972 with SMTP id ga9-20020a1709070c0900b0096a649b3972mr5887107ejc.0.1685545027925; Wed, 31 May 2023 07:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545027; cv=none; d=google.com; s=arc-20160816; b=gpWuzrkivUlV27pHYwXuOsVeFyUc8FyMMPSl6/Q0pOAuTE38DR5TK0JP7BVpg1mS2+ jaWXn+ITLJXew5OaFJ6ccr5M9IKuFzlVsXyu4rSXUxP69gQUWdIe7ad13/0ANEqfBS5U l1zRR8I9flK+6nBB0qXAmEgMkxWsWvejUyk49wiwt75RpCWWPgIYBuJbL6zWY3gnx+jH KA58lOfLm4GLF7+opkmZ/gPLY3yesLyPcmWi7CY/Q8T6ZP0/8MJqyjl4WphAM9I8msFr wWhyuBR6oU5AnrjJlmX0TGkCuYjAYtK+xj4jAfcHv1iRQByMePkS7m++RGf7bXMORlPN LXwA== 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=FS47k671esm9sOid63hXFJ8+RtMsFqW26botnh9RXWc=; b=hFs8QYPAyMjV9+PBz8Nf6RWW/IWZjO4aqA6YGb8NniQk0J8u4JARlNxsgNs30pkWJJ IN15xuIdkF0FHWNa4b409uJ9ffUCQ0yBnnDkijZZbs0pUiIocrGlVrR6WuS3XNe23ASH nHnV6i6BGtVuJosUtBr52ftAXBCqCrpinfgZi3+/2faDKWEZmuquhxz14Q2w/7f2aZxU eSkRL5An0pr8QnKUtRVFtoI4IiT5zsHjhL5p1fcvOGO4mpFPXQRCSoo3r0nskCKRdl7x 30BfqUVwBJGzcwWusN/YLwdI9S4KWNHANJudAG4LQ+5BG7J9lYA6lrq+mt7Zyl4RT8NZ V9ig== 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 i12-20020a170906264c00b00965cab180bbsi7140976ejc.520.2023.05.31.07.57.07; Wed, 31 May 2023 07:57:07 -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 41D0768C288; Wed, 31 May 2023 17:55:26 +0300 (EEST) 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 67EA068C25A for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F24B32406CF for ; Wed, 31 May 2023 16:55:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ecUD2DeJO8Bc for ; Wed, 31 May 2023 16:55:11 +0200 (CEST) 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 288AC2404EC for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D5A0F3A03F3 for ; Wed, 31 May 2023 16:54:59 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:32 +0200 Message-Id: <20230531145453.20994-2-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known 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: tFKgRb3J2kNB Stop assuming the encoder knows the muxing timebase, which does not always have to hold (e.g. due to bitstream filters). --- fftools/ffmpeg_enc.c | 4 ---- fftools/ffmpeg_mux.c | 5 +++++ fftools/ffmpeg_mux.h | 3 +++ fftools/ffmpeg_mux_init.c | 10 ++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f3e291a9e4..fab71ca0c0 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -445,10 +445,6 @@ int enc_open(OutputStream *ost, AVFrame *frame) if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); - // copy estimated duration as a hint to the muxer - if (ost->st->duration <= 0 && ist && ist->st->duration > 0) - ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - ost->mux_timebase = enc_ctx->time_base; ret = of_stream_init(of, ost); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index feb014ca31..121796a55a 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -666,6 +666,11 @@ int of_stream_init(OutputFile *of, OutputStream *ost) if (ret < 0) return ret; + if (ms->stream_duration) { + ost->st->duration = av_rescale_q(ms->stream_duration, ms->stream_duration_tb, + ost->st->time_base); + } + ost->initialized = 1; return mux_check_init(mux); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 7e0454dfba..bee7addd6a 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -69,6 +69,9 @@ typedef struct MuxStream { * used for making up missing dts values */ int64_t last_mux_dts; + int64_t stream_duration; + AVRational stream_duration_tb; + // audio streamcopy - state for av_rescale_delta() int64_t ts_rescale_delta_last; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 4fc6f0fb46..33c93e40f2 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -914,10 +914,6 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); } - // copy estimated duration as a hint to the muxer - if (ost->st->duration <= 0 && ist->st->duration > 0) - ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - if (!ms->copy_prior_start) { ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? 0 : mux->of.start_time; @@ -1283,6 +1279,12 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, exit_program(1); } + // copy estimated duration as a hint to the muxer + if (ost->ist && ost->ist->st->duration > 0) { + ms->stream_duration = ist->st->duration; + ms->stream_duration_tb = ist->st->time_base; + } + return ost; }