From patchwork Wed May 31 14:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41923 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328579pzb; Wed, 31 May 2023 07:57:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MUjeL71LNDt7gMG8cqGyDhlevGvCHREMlNeqib28RXwiviU0Ss9GX1crrcfuTSx9pVCvk X-Received: by 2002:a17:907:a426:b0:96f:c988:93b with SMTP id sg38-20020a170907a42600b0096fc988093bmr5502927ejc.35.1685545062016; Wed, 31 May 2023 07:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545062; cv=none; d=google.com; s=arc-20160816; b=V75pYTt/Zxfld9sB/IX4sWatTJt8kypvh3x5CElihNSo8W9xoDnb1lU9hnphG8OWJx mR7bG8NWXdOfnhvUdb/yq2D07IQVgQ6xU7PQu+2OddB22szKQRyanxhpmpOBc3ZrR70Q m6bj+PZDYPeCoAbQ0vkg3mSUZNh0QLZ87XHqGXzGDzy86clkn0JopV+oQeGgf6APVSEd yVIBh0LAzx1FJjJBWGcPPlYoKtCFrgIPULbpakiJg3bu7f5YsQnX08CRWOhs138cDE5o jY6mqQWUQfFoLkTS7gPDP/zT5HzZpRonGRK4Pjbp4ajKSY/PKvxYI3o3ZEiHuWD8XuC5 GY4Q== 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=yDOSwV2f3J0YRq5BEdsIW2PRxVSSiDXti7tUF2vwLLI=; b=nl8b2jZwAsnlUuUp+96ADHTcwuaAzc04JeNEgD00wjVN/ZzAtLFibTK7v6t7M1FCKB uKBCcI4W6xvz11lgDJOYg4CzEBwRrNzAOy5V/xQnE7YkDCkv05ZVDJaOag0346J6YknK 3eaDQslm1Rd1uMZQ99uRGq2g2OsD0xCaOrUM/542APMZdr/rDMR5A/s/EXugXYo9sjhI VqjSEnDCK9yLbBirhshf9zRcVO+HSyO54hFyNV4Q+EFeSK3Ll5Gx+pVPGbZAP64ElOHr BAyXdJyASAAf0T0HiUYIkl32Hwbe26lw1bm8eYfjCiPXhsTeGb73Jslg7kfKhkmOPBx3 OWwg== 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 w17-20020a17090652d100b0096f818bfb47si3162495ejn.1009.2023.05.31.07.57.41; Wed, 31 May 2023 07:57:42 -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 2309068C2B2; Wed, 31 May 2023 17:55:30 +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 2551068C28D for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5CA70240591 for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 949nfy7b3xfF for ; Wed, 31 May 2023 16:55:07 +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 C45812405B5 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 69AB63A0BC6 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:44 +0200 Message-Id: <20230531145453.20994-14-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 14/23] fftools/ffmpeg: convert timestamps inside the muxer 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: +ktGRGb17kSl Packets submitted to the muxer now have their timebase attached to them, so the muxer can do conversion to muxing timebase and avoid exposing it to callers. --- fftools/ffmpeg_enc.c | 17 ++--------------- fftools/ffmpeg_mux.c | 6 ++++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 1b0410ae74..f6431b29d1 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -512,8 +512,8 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub) } av_shrink_packet(pkt, subtitle_out_size); - pkt->time_base = ost->mux_timebase; - pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, pkt->time_base); + pkt->time_base = AV_TIME_BASE_Q; + pkt->pts = sub->pts; pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, pkt->time_base); if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling @@ -735,19 +735,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); } - av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase); - pkt->time_base = ost->mux_timebase; - - if (debug_ts) { - av_log(ost, AV_LOG_INFO, "encoder -> type:%s " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " - "duration:%s duration_time:%s\n", - type_desc, - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base), - av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); - } - if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) { av_log(NULL, AV_LOG_ERROR, "Subtitle heartbeat logic failed in %s! (%s)\n", diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 121796a55a..dc2d189ff0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -334,6 +334,12 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) if (!eof && pkt->dts != AV_NOPTS_VALUE) ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q); + /* rescale timestamps to the muxing timebase */ + if (!eof) { + av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase); + pkt->time_base = ost->mux_timebase; + } + /* apply the output bitstream filters */ if (ms->bsf_ctx) { int bsf_eof = 0;