From patchwork Mon Apr 5 11:09:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 26763 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 5E2C244B387 for ; Mon, 5 Apr 2021 14:14:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2756B68A995; Mon, 5 Apr 2021 14:12:05 +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 62E7668A6B5 for ; Mon, 5 Apr 2021 14:11:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7A928240477 for ; Mon, 5 Apr 2021 13:11:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id TqtmE63uXaFm for ; Mon, 5 Apr 2021 13:11:44 +0200 (CEST) Received: from libav.khirnov.net (unknown [IPv6:2a00:c500:561:201:b6e1:23d0:924a:11c0]) (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 37FF9240693 for ; Mon, 5 Apr 2021 13:11:42 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 8A9623A0796; Mon, 5 Apr 2021 13:11:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 13:09:45 +0200 Message-Id: <20210405110952.17679-9-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210405110952.17679-1-anton@khirnov.net> References: <20210405110952.17679-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/17] fftools/ffmpeg: when framerate is set, prefer its inverse as output timebase 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Codec timebase is not well-defined for streamcopy, so it should only be used as the last resort. --- fftools/ffmpeg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 46bb014de8..8e6206647f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3151,8 +3151,12 @@ static int init_output_stream_streamcopy(OutputStream *ost) return ret; // copy timebase while removing common factors - if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) - ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); + if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) { + if (ost->frame_rate.num) + ost->st->time_base = av_inv_q(ost->frame_rate); + else + 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)