From patchwork Thu Jun 16 19:55:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36267 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1128138pzb; Thu, 16 Jun 2022 13:05:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sajT5TudPmzEyC7TrfNntPnVmWmiOOjXkWa/HPuqlA29RUq8tRybXwi9uNNxFDih5dmBxQ X-Received: by 2002:a17:906:7f06:b0:70e:2dc9:aec0 with SMTP id d6-20020a1709067f0600b0070e2dc9aec0mr5813813ejr.674.1655409916448; Thu, 16 Jun 2022 13:05:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655409916; cv=none; d=google.com; s=arc-20160816; b=VPJZWukMEl7WGYwSE6Ak2QV3jES4/LZFLPDgLr8Z0qHLpEWbu7/X++1TBrcmKHSi9h YRuFkdCGfDyg+C9gV56WNgm1f4Rsk+xWzi/wgibKgVusBpxFJrDayW6m2ZMI/Gksbr2o Wc9HSCZqXA4n2UVCyI4ZwNXqhT8Bwsvb1/V9FUYLkin1dE2x4KstcssHA45n1oY0xVIF j25av7bRey1xaOpsJWSFFqhX7Zs7dgO1Qyzu7gYZuGECnxRkuExIS2RdgLQqeM7xQJZ7 vzGUa1KLXy68i9QMppI/mGFvLJsw16P3Fmg+mUFxQeG8vwwqRr/0gY1nLTnuoBgL4AyZ ZXMg== 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=nQhnmz763wUUtBPWQmC8b0Gxt8Q1k79U0ZAplOg4AGU=; b=JNEd+/3w+vX1H19gR/XdsBlCH7ocewcVfNaiL5gK/dezfMnDo3bfxG8UsKIoMN7nqS 0VvQIy3pjid66xcfYIZSG2XpTWMKcvIdXcURJ3A9A2Np6CI6jk2/McKKgZipahMe2DBT QrovEee+G6fqiYkHMNCQkn0bu9WsaEFOBVcOyl8I+8tQCR2zA761IbPLc35HKhlrQ28m J85C6csqWt5PK1c940jJ6DhRcDtcaT9MjpEYLb/0/FTarLlF/HnSNj1B1sXImGpWpp0N zVzG45d0zzuSX1xzrfhzJe1N3aURQmNbaIpbueY/oKqBt9MnQ028x0gFyubzzlKfZNO6 BWTA== 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 g19-20020a170906349300b0071208964108si2579928ejb.635.2022.06.16.13.05.16; Thu, 16 Jun 2022 13:05:16 -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 E827D68B85A; Thu, 16 Jun 2022 23:03:50 +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 EF4FE68B81A for ; Thu, 16 Jun 2022 23:03:42 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B4AFD24017C for ; Thu, 16 Jun 2022 22:03:41 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id de3zb58faLgh for ; Thu, 16 Jun 2022 22:03:41 +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 31B0A2405F5 for ; Thu, 16 Jun 2022 22:03:34 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id ED8CC3A2101; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:25 +0200 Message-Id: <20220616195534.5278-26-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195534.5278-1-anton@khirnov.net> References: <20220616195534.5278-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/35] fftools/ffmpeg: only set OutputStream.frame_number for video encoding 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: 7zpiELt0uGzn It is unused otherwise. Rename the field to vsync_frame_number to better reflect its current purpose. --- fftools/ffmpeg.c | 10 +++++----- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_mux.c | 10 ---------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index beb07928bf..ab3665e53c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1176,7 +1176,7 @@ static void do_video_out(OutputFile *of, switch (ost->vsync_method) { case VSYNC_VSCFR: - if (ost->frame_number == 0 && delta0 >= 0.5) { + if (ost->vsync_frame_number == 0 && delta0 >= 0.5) { av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); delta = duration; delta0 = 0; @@ -1184,7 +1184,7 @@ static void do_video_out(OutputFile *of, } case VSYNC_CFR: // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c - if (frame_drop_threshold && delta < frame_drop_threshold && ost->frame_number) { + if (frame_drop_threshold && delta < frame_drop_threshold && ost->vsync_frame_number) { nb_frames = 0; } else if (delta < -1.1) nb_frames = 0; @@ -1214,7 +1214,7 @@ static void do_video_out(OutputFile *of, * But there may be reordering, so we can't throw away frames on encoder * flush, we need to limit them here, before they go into encoder. */ - nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); + nb_frames = FFMIN(nb_frames, ost->max_frames - ost->vsync_frame_number); nb0_frames = FFMIN(nb0_frames, nb_frames); memmove(ost->last_nb0_frames + 1, @@ -1226,7 +1226,7 @@ static void do_video_out(OutputFile *of, nb_frames_drop++; av_log(NULL, AV_LOG_VERBOSE, "*** dropping frame %d from stream %d at ts %"PRId64"\n", - ost->frame_number, ost->st->index, ost->last_frame->pts); + ost->vsync_frame_number, ost->st->index, ost->last_frame->pts); } if (nb_frames > (nb0_frames && ost->last_dropped) + (nb_frames > nb0_frames)) { if (nb_frames > dts_error_threshold * 30) { @@ -1320,7 +1320,7 @@ static void do_video_out(OutputFile *of, exit_program(1); ost->sync_opts++; - ost->frame_number++; + ost->vsync_frame_number++; } av_frame_unref(ost->last_frame); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 106580adb2..3d55370d3a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -460,7 +460,8 @@ typedef struct OutputStream { int source_index; /* InputStream index */ AVStream *st; /* stream in the output file */ int encoding_needed; /* true if encoding needed for this stream */ - int frame_number; + /* number of frames emitted by the video-encoding sync code */ + int vsync_frame_number; /* input pts and corresponding output pts for A/V sync */ struct InputStream *sync_ist; /* input stream to sync against */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 56444770bf..87c7bdc4e3 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -232,18 +232,8 @@ static void submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) { - AVStream *st = ost->st; int ret; - if (pkt) { - /* - * Counting encoded video frames needs to be done separately because of - * reordering, see do_video_out(). - */ - if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) - ost->frame_number++; - } - if (of->mux->header_written) { submit_packet(of, ost, pkt); } else {