From patchwork Wed Jan 4 16:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39871 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp8942606pzb; Wed, 4 Jan 2023 08:46:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlY+avx4OnwkXVcA1+uWpJcA16uWxqjSb4zpcEGDi354nYyPigXfMCMfQpfWB6sofDXzjP X-Received: by 2002:a17:907:cb85:b0:7c0:f216:cc14 with SMTP id un5-20020a170907cb8500b007c0f216cc14mr41800447ejc.11.1672850797237; Wed, 04 Jan 2023 08:46:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672850797; cv=none; d=google.com; s=arc-20160816; b=disXmlGnW2sT7KvGKizWcn5iAqvDhTurzFNyj+xfNS0J1GIc5GwKW2hPvFTu1oumkx tQx++3mXL+dgBxhohqlI7rB684KAQ48j8sPB1V1WpH7CRPnB+PHpvNIUKXzFMwe+NZxf X1awVd/Bs2HmqHXVhECvNBuJDmjqIBqQoaqPqqqjglyDL0sT0T9ZDInpzNTdiAFbmF6v VaFimfrNq49YmQAccB8tGgDw0dRKlG0RMPQMBwzgYrlZeGd+JxVb0g30zZ+JnNX5VqWO UyGJjQKRiKIaGMf0YW2kAoArc3comWfJkWJds3sVobN025iedRGApanUbpGhqdDNUPq1 90gA== 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=+yAyf8hy2HdgUhR/kxnIM9vulXB7FDl6oPsnFMFuFeo=; b=n0bucQg4xrGz7zM5GIc8XXCkWtc45ezZt4XNo9aZG8lcT0M+ALTEX9KWz76eexVbs8 8gbG2PZoM/IXbSJaJUT3pPGdECyxtBN9btE/XNcmNPQkyXnfdNIWbTNbshsdE6/1PlKn JrlY68g3Wt8P2JIFipscStqejzf2aX3XCa/WpJrNgTrmMNAxNNZRemF5lJJmw9oOm+rG IqRUz23h8qRFfpYxzU+UHgJvzQ0KxCZO1R8OL5TLDheuFwlueykcB6HHSMTAsIsA0Tjc OjW0Qq8ZhCdUzEQLcPfPdf9Re1xU8OvydYQ2f0+belkAR1Z6MrcRALKgfICznLf9u4D0 E2vw== 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 v3-20020a056402348300b0048edf59946fsi3862093edc.19.2023.01.04.08.46.36; Wed, 04 Jan 2023 08:46:37 -0800 (PST) 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 4D61768BD1D; Wed, 4 Jan 2023 18:45:33 +0200 (EET) 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 5AC1368BD09 for ; Wed, 4 Jan 2023 18:45:25 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 59D5D2406C7 for ; Wed, 4 Jan 2023 17:45:23 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id GzfEiSzj6qhX for ; Wed, 4 Jan 2023 17:45:21 +0100 (CET) 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 91D492404F8 for ; Wed, 4 Jan 2023 17:45:18 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9E3A73A034C for ; Wed, 4 Jan 2023 17:45:10 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Jan 2023 17:42:42 +0100 Message-Id: <20230104164246.6133-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230104164246.6133-1-anton@khirnov.net> References: <20230104164246.6133-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] fftools/ffmpeg: rename a variable to be more descriptive 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: 8cJRnQkNpXWX --- fftools/ffmpeg.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 00e4be68ea..66a24a1a9c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1088,7 +1088,7 @@ static void do_video_out(OutputFile *of, int ret; AVCodecContext *enc = ost->enc_ctx; AVRational frame_rate; - int64_t nb_frames, nb0_frames, i; + int64_t nb_frames, nb_frames_prev, i; double delta, delta0; double duration = 0; InputStream *ist = ost->ist; @@ -1114,9 +1114,9 @@ static void do_video_out(OutputFile *of, if (!next_picture) { //end, flushing - nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0], - ost->last_nb0_frames[1], - ost->last_nb0_frames[2]); + nb_frames_prev = nb_frames = mid_pred(ost->last_nb0_frames[0], + ost->last_nb0_frames[1], + ost->last_nb0_frames[2]); } else { double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture); /* delta0 is the "drift" between the input frame (next_picture) and @@ -1124,8 +1124,10 @@ static void do_video_out(OutputFile *of, delta0 = sync_ipts - ost->next_pts; delta = delta0 + duration; + // tracks the number of times the PREVIOUS frame should be duplicated, + // mostly for variable framerate (VFR) + nb_frames_prev = 0; /* by default, we output a single frame */ - nb0_frames = 0; // tracks the number of times the PREVIOUS frame should be duplicated, mostly for variable framerate (VFR) nb_frames = 1; if (delta0 < 0 && @@ -1158,7 +1160,7 @@ static void do_video_out(OutputFile *of, else if (delta > 1.1) { nb_frames = llrintf(delta); if (delta0 > 1.1) - nb0_frames = llrintf(delta0 - 0.6); + nb_frames_prev = llrintf(delta0 - 0.6); } next_picture->duration = 1; break; @@ -1182,35 +1184,35 @@ static void do_video_out(OutputFile *of, memmove(ost->last_nb0_frames + 1, ost->last_nb0_frames, sizeof(ost->last_nb0_frames[0]) * (FF_ARRAY_ELEMS(ost->last_nb0_frames) - 1)); - ost->last_nb0_frames[0] = nb0_frames; + ost->last_nb0_frames[0] = nb_frames_prev; - if (nb0_frames == 0 && ost->last_dropped) { + if (nb_frames_prev == 0 && ost->last_dropped) { nb_frames_drop++; av_log(NULL, AV_LOG_VERBOSE, "*** dropping frame %"PRId64" from stream %d at ts %"PRId64"\n", 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 > (nb_frames_prev && ost->last_dropped) + (nb_frames > nb_frames_prev)) { if (nb_frames > dts_error_threshold * 30) { av_log(NULL, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", nb_frames - 1); nb_frames_drop++; return; } - nb_frames_dup += nb_frames - (nb0_frames && ost->last_dropped) - (nb_frames > nb0_frames); + nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - (nb_frames > nb_frames_prev); av_log(NULL, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1); if (nb_frames_dup > dup_warning) { av_log(NULL, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", dup_warning); dup_warning *= 10; } } - ost->last_dropped = nb_frames == nb0_frames && next_picture; + ost->last_dropped = nb_frames == nb_frames_prev && next_picture; ost->kf.dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame; /* duplicates frame if needed */ for (i = 0; i < nb_frames; i++) { AVFrame *in_picture; - if (i < nb0_frames && ost->last_frame->buf[0]) { + if (i < nb_frames_prev && ost->last_frame->buf[0]) { in_picture = ost->last_frame; } else in_picture = next_picture;