From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3AB4245EFC for ; Thu, 18 May 2023 06:19:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92E7D68C116; Thu, 18 May 2023 09:19:31 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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, "; "); -- 2.39.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".