From patchwork Wed May 17 10:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41685 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1080065pzb; Wed, 17 May 2023 03:25:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a6g6F3n2XtFvoWGr3nxCiYibeIiTiZCdkQt6LMJuZnCY1wKm6Fin0E84VyfTbBReMHf7r X-Received: by 2002:a17:907:96a0:b0:96a:1022:eca0 with SMTP id hd32-20020a17090796a000b0096a1022eca0mr27117583ejc.23.1684319128636; Wed, 17 May 2023 03:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319128; cv=none; d=google.com; s=arc-20160816; b=HxxGBAogSVOoTv8L2V2gyRNX8HhRJAHTEe/EpVghavMUpGm/ZhGAZFby5hcEszGPPu PaV4uEGlBq8KFQez6C9GiQxo+HLgMaq7rhS4rcU+9SETdJJfl1adq47iH57zV8WgkNu4 6aDS7yXGmzoJCCaW5M8G02T7tEABp1aXEgkRkWH4RGzBUZ/DhmAw7gXF9vfH28pF2o5Y SiveZ8ZlfSjnNMvGkKXxES0ZFx/gLM3G8KBnEYi3RTqSwpV2EMldLvOFwS+6AgM3Qo6C 1QhK2S+OfU/QIGT6IR43lXWr6JE37sLByXKYwcm/JmWprRpSadiSOxUnvbTJGzjIQd/m 0wKA== 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=LdkPYrCCCfMNqwVoEn0q7UNZlHNzLLGmLRFzdEnh7CM=; b=QyarWsFfHF/NXo6dpseE5UDbqB3z4039KMbDoE7DcUrjvVRP+wJRkqF9rbGToLaCJb OUBl6XoFBhBojHUhs5E0Qt7j42recHSs5YoGS3fn0m9n9xU1tN5Iyt5CXKkMf9X7nLPa KY/UqKneC9QYcQzBXugTLVxLzCum9Lx/x4699cLn3kmWp2Tru2Y5smfO4kAC6z6fTUuC RXAhXV7oIIlYnUqa5NaSQFGu2hpF6yqpxieNHS/LMaG0kS0cjQQ4rsXUjZgxfQvGb2iA ZN/7kaK6QJPnVwvSb6rvnWO7QhxEPwJW8WzX8KnsCIeGUEyjGb5n4ZFbGibqGRPYyuP3 6xZg== 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 u19-20020aa7d993000000b0050d8caa68fdsi16869504eds.159.2023.05.17.03.25.28; Wed, 17 May 2023 03:25:28 -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 CD87A68C1F8; Wed, 17 May 2023 13:21:23 +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 ED3AE68C17F for ; Wed, 17 May 2023 13:21:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BB413240177 for ; Wed, 17 May 2023 12:21:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wq8eCwcqZHZW for ; Wed, 17 May 2023 12:21:00 +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 5DBDE240D20 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8FA283A210F for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:19 +0200 Message-Id: <20230517102029.541-26-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/36] fftools/ffmpeg: rework handling -max_error_rate 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: lW8834zgwsGU Replace the decode_error_stat global with a per-input-stream variable. Also, print an error message when the error rate is exceeded. --- fftools/ffmpeg.c | 28 ++++++++++++++++------------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 5 +++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 537f287637..2e9a2b940a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -121,7 +121,6 @@ static int64_t getmaxrss(void); int64_t nb_frames_dup = 0; int64_t nb_frames_drop = 0; -static int64_t decode_error_stat[2]; unsigned nb_output_dumped = 0; static BenchmarkTimeStamps current_time; @@ -771,8 +770,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti static void check_decode_result(InputStream *ist, int *got_output, int ret) { - if (*got_output || ret<0) - decode_error_stat[ret<0] ++; + if (ret < 0) + ist->decode_errors++; if (ret < 0 && exit_on_error) exit_program(1); @@ -1807,14 +1806,15 @@ static int transcode_step(OutputStream *ost) /* * The following code is the main loop of the file converter */ -static int transcode(void) +static int transcode(int *err_rate_exceeded) { - int ret, i; + int ret = 0, i; InputStream *ist; int64_t timer_start; print_stream_maps(); + *err_rate_exceeded = 0; atomic_store(&transcode_init_done, 1); if (stdin_interaction) { @@ -1858,6 +1858,12 @@ static int transcode(void) if (!input_files[ist->file_index]->eof_reached) { process_input_packet(ist, NULL, 0); } + + if ((ist->frames_decoded + ist->decode_errors) * max_error_rate < ist->decode_errors) { + av_log(ist, AV_LOG_FATAL, "Maximum error rate %g exceeded\n", max_error_rate); + *err_rate_exceeded = 1; + } + } enc_flush(); @@ -1921,7 +1927,7 @@ static int64_t getmaxrss(void) int main(int argc, char **argv) { - int ret; + int ret, err_rate_exceeded; BenchmarkTimeStamps ti; init_dynload(); @@ -1958,7 +1964,7 @@ int main(int argc, char **argv) } current_time = ti = get_benchmark_time_stamps(); - ret = transcode(); + ret = transcode(&err_rate_exceeded); if (ret >= 0 && do_benchmark) { int64_t utime, stime, rtime; current_time = get_benchmark_time_stamps(); @@ -1969,12 +1975,10 @@ int main(int argc, char **argv) "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n", utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0); } - av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, %"PRIu64" decoding errors\n", - decode_error_stat[0], decode_error_stat[1]); - if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1]) - exit_program(69); - ret = received_nb_signals ? 255 : ret; + ret = received_nb_signals ? 255 : + err_rate_exceeded ? 69 : ret; + exit_program(ret); return ret; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3a332768df..87e684a147 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -413,6 +413,7 @@ typedef struct InputStream { // number of frames/samples retrieved from the decoder uint64_t frames_decoded; uint64_t samples_decoded; + uint64_t decode_errors; } InputStream; typedef struct LastFrameDuration { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index df87e0f30a..401ae1f850 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -786,8 +786,9 @@ static void demux_final_stats(Demuxer *d) ds->nb_packets, ds->data_size); if (ist->decoding_needed) { - av_log(f, AV_LOG_VERBOSE, "%"PRIu64" frames decoded", - ist->frames_decoded); + av_log(f, AV_LOG_VERBOSE, + "%"PRIu64" frames decoded; %"PRIu64" decode errors", + ist->frames_decoded, ist->decode_errors); if (type == AVMEDIA_TYPE_AUDIO) av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded); av_log(f, AV_LOG_VERBOSE, "; ");