From patchwork Thu May 18 06:19:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41704 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp241728pzb; Wed, 17 May 2023 23:19:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5X4eZf/dL13OJ+hbb9kptbRZyt/ZOD145A44yP3LcPQoXl5+nZI+QyoCUEFn3a9gGxO++5 X-Received: by 2002:a17:907:7253:b0:96a:cdff:cb61 with SMTP id ds19-20020a170907725300b0096acdffcb61mr4318723ejc.4.1684390775753; Wed, 17 May 2023 23:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684390775; cv=none; d=google.com; s=arc-20160816; b=OsLPtBh54oKmC5BNmAYCoZYrpAs5b98DPtH2tKtPrk/O6A6Xu7oeMzOV16qMFf7hZr A4+5X19ufVs5gfwXgbN9KIHch3hoINyifUML9Y39ok5VctL7OeumBc9VuBSUItzJWAjD zdZZnocUPuQ9zpPoAzWVHtw2QajwBguWB0Ld6eP/kZstHhZpqOyPiKPokJcuQbvqOJev ERbz0yBMTAu7xPbx5cdFY8sIPcxmQigXO8i0NOU5yB5UHyIPdx98ny5k/kZTf6iVTzbW EKzWpaIY/s0NCfLj76R5uKw9Vx/4i8+evu6whlk288hXvv0LscKHvmq03rdwNnYyjLkP CXNg== 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=hiL6aWlZJBoC6MsLSWNffrJPM92bb7JfEfp7su2eoZU=; b=Gz3gZHh5rnk7jDN6vn7XMqxVWXxweKDragZ+zn3f9b19m/Zhq/vhmirB9f68kQuXkc lnJ1DmmmdWnGxcs4y8haY0culN1AA7Ruixh9ajX7vhnNZ3CGaJCiPukgktgSGsnTUGQk 5khYTi18ihp0jPG2rMufZQm5+kXFZEjp2pg/C2SIkTFJXLpcWevtG7C8o/Nm5gG8z40+ VJOcIQHvLPozvc0EPaleAYPfx0U3ZRBXNxtyvZhs4sMK0XCqMLVPaPHaBZ0JWIsAbPAG eMBTUb58+P3pAyZZXfl6EKlrhehVQhWAb6svBA0BJa+UFJ+slJIWj2k/TQt1ZId0XuTT NOHA== 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 fw4-20020a170907500400b0095317ae767esi695411ejc.46.2023.05.17.23.19.35; Wed, 17 May 2023 23:19:35 -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 C73D268C13C; Thu, 18 May 2023 09:19:31 +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 436C368C033 for ; Thu, 18 May 2023 09:19:25 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EBF262404EC for ; Thu, 18 May 2023 08:19:24 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LBFcyA00TPZF for ; Thu, 18 May 2023 08:19:24 +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 29D39240177 for ; Thu, 18 May 2023 08:19:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DDD973A01C0 for ; Thu, 18 May 2023 08:19:23 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 May 2023 08:19:23 +0200 Message-Id: <20230518061923.20521-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-26-anton@khirnov.net> References: <20230517102029.541-26-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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: ixnRfm0ukrOo Replace the decode_error_stat global with a per-input-stream variable. Also, print an error message when the error rate is exceeded. --- Now also printing the error rate value. --- fftools/ffmpeg.c | 33 +++++++++++++++++++++------------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 5 +++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 537f287637..414bae1747 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) { @@ -1855,9 +1855,20 @@ static int transcode(void) /* at the end of stream, we must flush the decoder buffers */ for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { + float err_rate; + if (!input_files[ist->file_index]->eof_reached) { process_input_packet(ist, NULL, 0); } + + err_rate = (ist->frames_decoded || ist->decode_errors) ? + ist->decode_errors / (ist->frames_decoded + ist->decode_errors) : 0.f; + if (err_rate > max_error_rate) { + av_log(ist, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n", + err_rate, max_error_rate); + *err_rate_exceeded = 1; + } else if (err_rate) + av_log(ist, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate); } enc_flush(); @@ -1921,7 +1932,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 +1969,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 +1980,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, "; ");