From patchwork Tue Sep 19 19:10:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 43789 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp168782pzb; Tue, 19 Sep 2023 12:21:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaSHTwiXD8RBHgZnD02Hqy0Hi/F0ZXv1Ki/SF9hs4TbqqeyOEZr19/CqgJdPKSwx7TbDxF X-Received: by 2002:a17:907:7714:b0:9ad:e389:4bf5 with SMTP id kw20-20020a170907771400b009ade3894bf5mr286617ejc.3.1695151298388; Tue, 19 Sep 2023 12:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695151298; cv=none; d=google.com; s=arc-20160816; b=mBwXKrW3YYki5CvS8VTz4W8bWdR+ZCMoubKq0Rqjv547OnKCcEPinA9lxyTyAfxs2K jixChL1R9z3Xgg21daqYjiS3KJmQLmiNAkz6d6rd2x8MJ0u0dipKy60DgrXZb5cJxRqH 2U3a7p4gtUp2vR5jWI2usPj4jQ1bcIRIldomHhbouJwMq6ifOKpJN1PHJqMe11uZnNlX /8zcQoU6WluFlmZIQWILziPrsvDcxbE1wFXEE55YTjCInDS44y4/IH9M/Ess6EcwvlYG 1smYSHweUsFbWpJ0F6g6wUJvmvhxxUqycEgEkI7cE3sgnKjdE9FgPkwtx+EzLrXOUNyo 3w/A== 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=vzyy7IA9uhG2Qx6FnUH2IlX7rkwSSGlhDPoCPjL/kW4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VPzhpTuPdxHdwX2HGzdK5MUdhaxdY+ch9pWBL/jSKGTYR4PH1zW2YqEPQ7DT38PStk fASwCJuky+O2i0tPo009Sh+CXIiWamruai6PHiUlIrxELfZxb7fJQGD7DeL6RySuhuoZ oTWJNRmLtYoc+GBrjPrTk1dOr93J4s1eNZTf0d+BnCH9wo2Nnixa3mGLtQzBbCDRiRRS sIIIvWHNkfAFXpSM4zjZy7tx3NaDkR7jXkSa09wLfXaANO60m3YzCEsf+PKBQSv/RuFT HCH3TCIG6INSJn/n676G+Hp7pwnCulkzVuJ11PIkbzLzIdd1GrYmIK6P9jSUBqRnfcnd gHMw== 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 i16-20020a1709061cd000b0098e444cba76si9678459ejh.91.2023.09.19.12.21.38; Tue, 19 Sep 2023 12:21:38 -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 3B07768C91B; Tue, 19 Sep 2023 22:21:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4594568C911 for ; Tue, 19 Sep 2023 22:20:58 +0300 (EEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id F1F835103 for ; Tue, 19 Sep 2023 21:20:57 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 9Nl8zgoUeVPW for ; Tue, 19 Sep 2023 21:20:52 +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 mail1.khirnov.net (Postfix) with ESMTPS id 423DC510E for ; Tue, 19 Sep 2023 21:20:42 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2D5443A15AC for ; Tue, 19 Sep 2023 21:20:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:10:31 +0200 Message-Id: <20230919191044.18873-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230919191044.18873-1-anton@khirnov.net> References: <20230919191044.18873-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/27] fftools/ffmpeg_enc: simplify adjust_frame_pts_to_encoder_tb() signature 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: EXMXSMeDGlrU It does not need an OutputFile and an OutputStream, only the target timebase and the timestamp offset. --- fftools/ffmpeg_enc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 420fe96c97..df79eaff59 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -917,16 +917,12 @@ static int do_audio_out(OutputFile *of, OutputStream *ost, return (ret < 0 && ret != AVERROR_EOF) ? ret : 0; } -static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, - AVFrame *frame) +static double adjust_frame_pts_to_encoder_tb(AVFrame *frame, AVRational tb_dst, + int64_t start_time) { double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision - const int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? - 0 : of->start_time; - AVCodecContext *const enc = ost->enc_ctx; - - AVRational tb = enc->time_base; + AVRational tb = tb_dst; AVRational filter_tb = frame->time_base; const int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); @@ -943,19 +939,17 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, if (float_pts != llrint(float_pts)) float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); - frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) - - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); - frame->time_base = enc->time_base; + frame->pts = av_rescale_q(frame->pts, filter_tb, tb_dst) - + av_rescale_q(start_time, AV_TIME_BASE_Q, tb_dst); + frame->time_base = tb_dst; early_exit: if (debug_ts) { av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n", frame ? av_ts2str(frame->pts) : "NULL", - (enc && frame) ? av_ts2timestr(frame->pts, &enc->time_base) : "NULL", - float_pts, - enc ? enc->time_base.num : -1, - enc ? enc->time_base.den : -1); + av_ts2timestr(frame->pts, &tb_dst), + float_pts, tb_dst.num, tb_dst.den); } return float_pts; @@ -981,7 +975,8 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, AVFrame *frame duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base)); - sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, frame); + sync_ipts = adjust_frame_pts_to_encoder_tb(frame, enc->time_base, + of->start_time == AV_NOPTS_VALUE ? 0 : of->start_time); /* delta0 is the "drift" between the input frame and * where it would fall in the output. */ delta0 = sync_ipts - e->next_pts;