From patchwork Tue Sep 19 19:10:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 43788 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp168709pzb; Tue, 19 Sep 2023 12:21:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQwSympI4DXCG/xklt+oh5OVZBB+niOywvDvPVtwgfDQutCgBMA6IfS0qaJ/sY+KTXAIUm X-Received: by 2002:aa7:c746:0:b0:527:251e:1be7 with SMTP id c6-20020aa7c746000000b00527251e1be7mr331016eds.11.1695151289154; Tue, 19 Sep 2023 12:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695151289; cv=none; d=google.com; s=arc-20160816; b=aboZGR9j7jkYwlKVxPdzhImgenLDFU2xft/FyqIdej3RO9xRLssVZ0aqEsCnjkt6lk OmpWe+O1RgYhO7pOQOi03obu3xrgETzx62ULqoWUJ7YkdhfZEqZeD9OtVmetOYDPwUCh 3+/851jAUDb0eP8N+rEycdLiOoT1R8f2Cp6UMrzwoQXRaVWtUpt6OWOMuggvAH91qgh+ t7Pfv1W5CmNlaPbjb1UpFfGKI9MzKg5BxKlEoh7NkkAU7vNRX1kdFHrSOOAxvBQgDKcw maXvYsJPyaMj2LQhkJUtvqDtIvq9cApG717AU7hHdrzBceLuYVjlLHzN3BHJQDLBZkKh qc0Q== 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=RNSB1CYMEJOlAN6mqVWsjHRSk9bfYaaq1Qt6ABsnCqg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=G+FPbAkCces9nHWlAveEMrIaa0pDTLINP1Z1oGoR8EPrxnYuXjNf+lbcdMukx4sSHk ++OXIP9Q5M4uoOr90F2I5GXwbqkIwtjdKofSj28AzC6FJMfsxiqkdir4aBcAd+rRz5on AFS4iPMfNZYK1WZe+1uM1uTQxAQiy0LBgNHrYxg5+SuHaDRyp4yZ3gWe8EengJF9QCDg QNPA6FckGv1p3mQDK6cyLDQrcuH9jfssjZ+KGf+DXR9VHSlw9JHYHwx+LY6AdgAq8e9G dgu9vB30HFM+LldSWU7gf3MQZTAVoxfURBAQTI83jqW+NDvjuZZ+a8nZcmm4UM85bpFM f0MA== 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 f14-20020a056402160e00b00532d2b51266si982038edv.468.2023.09.19.12.21.28; Tue, 19 Sep 2023 12:21:29 -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 24C5668C916; Tue, 19 Sep 2023 22:21:01 +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 141BD68C8ED for ; Tue, 19 Sep 2023 22:20:53 +0300 (EEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id B2B7B10 for ; Tue, 19 Sep 2023 21:20:52 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ZWu8rJA88GHj for ; Tue, 19 Sep 2023 21:20:47 +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 2C50B5103 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 16F513A150F 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:29 +0200 Message-Id: <20230919191044.18873-3-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 02/27] fftools/ffmpeg_enc: move handling video frame duration to video_sync_process() 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: 5AdHmINItagB That is a more appropriate place for this. --- fftools/ffmpeg_enc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 9b8b3e0226..9aa00f682c 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -965,12 +965,12 @@ early_exit: * should this (and possibly previous) frame be repeated in order to conform to * desired target framerate (if any). */ -static void video_sync_process(OutputFile *of, OutputStream *ost, - AVFrame *frame, double duration, +static void video_sync_process(OutputFile *of, OutputStream *ost, AVFrame *frame, int64_t *nb_frames, int64_t *nb_frames_prev) { Encoder *e = ost->enc; - double delta0, delta, sync_ipts; + AVCodecContext *enc = ost->enc_ctx; + double delta0, delta, sync_ipts, duration; if (!frame) { *nb_frames_prev = *nb_frames = mid_pred(e->frames_prev_hist[0], @@ -979,6 +979,8 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, goto finish; } + 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); /* delta0 is the "drift" between the input frame and * where it would fall in the output. */ @@ -1107,12 +1109,8 @@ static int do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; int64_t nb_frames, nb_frames_prev, i; - double duration = 0; - if (frame) - duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base)); - - video_sync_process(of, ost, frame, duration, + video_sync_process(of, ost, frame, &nb_frames, &nb_frames_prev); if (nb_frames_prev == 0 && ost->last_dropped) {