From patchwork Mon Apr 4 11:30: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: 35188 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1914695pzb; Mon, 4 Apr 2022 04:38:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbGSR9y1GdYR7J212AGgo/PVSBbHUzQCBhVtgjlCvq4dU+uWhrd2KElpf/H7pd891GkGwu X-Received: by 2002:a05:6402:d0e:b0:418:f011:275e with SMTP id eb14-20020a0564020d0e00b00418f011275emr32238314edb.323.1649072305206; Mon, 04 Apr 2022 04:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649072305; cv=none; d=google.com; s=arc-20160816; b=m0cpwLkbRs4ChT2z+rSsLm4WlNKUyYXLRjUjjHWb2eii71cqbNe3yNseh5aVqtIl+P /aRHeT276z8RrSB+pOrJ9a7FgDbiQpBo2CljrHomCGoz95PaDDl10wwMWMAClnc5WdVU Hr6sza9XkGB1jEx5n9n+/kItCObhY5dlHm2nHWM9Se3zEkMpBuaXqwk0Wj57OvHbXjc2 V1GUKzpigdUy1PeLT3bQWnPnSBhVSCXxkd6Fma1wNt/w2/59uzOPFI15YEyiGd3Cu0ob FZbHxKNAT+NnC5VBOKMMstIT1fTq7w6YHovDURk/dVHHKWpdXWai2R95Kf9fJ5Chx1tO edVg== 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=PM426Es02WnST6hVsb5AsyP2cz3qjJyaDbhMqeEQzOk=; b=VLhlWG47xcO3sAgM49AFpwlle2DxC27fWKJXJJtuu0WQOd2J6c7HPkKp3kWidltt7W 4vYYyG3zOvwj9EjJyGTnoxlka/rgFvPdZwcNs3XJUJh839/ep31UsGp4I5TWkiBmtLOV ylNDHKcpmQU7xlc3mIiIei8m/zEOoj9oEADr+7kl+vXsU/McyIJPVxkKeXAlHW60iKQv 2t5aSHTKmzVw7wHB+aPZHkei+OoCi/Xot5KIEiYEaGb6u1Rm+9LX+ttoQcAC0KcDjqRu 2x2zHTAqrlDZ/NXVAChREdjzvZ9oZ4NW7cCTqEU7YO+O2/qrG2GceVs34nBCq8GvhgAA PwxQ== 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 h13-20020a170906854d00b006dffb2d6bdcsi6188130ejy.83.2022.04.04.04.38.24; Mon, 04 Apr 2022 04:38:25 -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 B208B68B2E8; Mon, 4 Apr 2022 14:37:46 +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 D6AC468B29B for ; Mon, 4 Apr 2022 14:37:42 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8C1F724017C for ; Mon, 4 Apr 2022 13:37:42 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id qGTKmtSzic3L for ; Mon, 4 Apr 2022 13:37:42 +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 3E4EA24017E for ; Mon, 4 Apr 2022 13:37:41 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2B63A3A0DEF; Mon, 4 Apr 2022 13:32:12 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Apr 2022 13:30:25 +0200 Message-Id: <20220404113037.13070-38-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404113037.13070-1-anton@khirnov.net> References: <20220404113037.13070-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 37/49] 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: wDuLtKahz58/ 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 | 11 ----------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 53b3657ec9..701baa3a28 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1108,7 +1108,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; @@ -1116,7 +1116,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; @@ -1146,7 +1146,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, @@ -1158,7 +1158,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) { @@ -1255,7 +1255,7 @@ static void do_video_out(OutputFile *of, av_frame_remove_side_data(in_picture, AV_FRAME_DATA_A53_CC); 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 dfda6ccbe9..962867b783 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -457,7 +457,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 11d5a0a885..1d8827277d 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -269,17 +269,6 @@ static void submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) { - AVStream *st = ost->st; - - if (!eof) { - /* - * 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 (ost->sq_idx_mux >= 0) { int ret = sq_send(of->sq_mux, ost->sq_idx_mux, SQPKT(eof ? NULL: pkt));