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 68F5545D7E for ; Sun, 9 Apr 2023 14:12:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E99E668BE7C; Sun, 9 Apr 2023 17:09:39 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C4C2968BBE7 for ; Sun, 9 Apr 2023 17:09:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 549902405EC for ; Sun, 9 Apr 2023 16:09:13 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id x2OAauG9nUXs for ; Sun, 9 Apr 2023 16:09:12 +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 3CCFB2406CA for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2C3063A038E for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2023 16:08:34 +0200 Message-Id: <20230409140853.28858-10-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230409140853.28858-1-anton@khirnov.net> References: <20230409140853.28858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written 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: This is currently done in two places: * at the end of print_final_stats(), which merely prints a warning if the total size of all written packets is zero * at the end of transcode() (under a misleading historical 'close each encoder' comment), which instead checks the packet count to implement -abort_on empty_output[_stream] Consolidate both of these blocks into a single function called from of_write_trailer(), which is a more appropriate place for this. Also, return an error code rather than exit immediately, which ensures all output files are properly closed. --- fftools/ffmpeg.c | 30 ------------------------------ fftools/ffmpeg_mux.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 7431482acc..48e771cbc5 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -745,7 +745,6 @@ static void print_final_stats(int64_t total_size) uint64_t data_size = 0; float percent = -1.0; int i, j; - int pass1_used = 1; for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { AVCodecParameters *par = ost->st->codecpar; @@ -759,10 +758,6 @@ static void print_final_stats(int64_t total_size) } extra_size += par->extradata_size; data_size += s; - if (ost->enc_ctx && - (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) - != AV_CODEC_FLAG_PASS1) - pass1_used = 0; } if (data_size && total_size>0 && total_size >= data_size) @@ -848,14 +843,6 @@ static void print_final_stats(int64_t total_size) av_log(NULL, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n", total_packets, total_size); } - if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){ - av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded "); - if (pass1_used) { - av_log(NULL, AV_LOG_WARNING, "\n"); - } else { - av_log(NULL, AV_LOG_WARNING, "(check -ss / -t / -frames parameters if used)\n"); - } - } } static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time) @@ -2902,7 +2889,6 @@ static int transcode(void) int ret, i; InputStream *ist; int64_t timer_start; - int64_t total_packets_written = 0; ret = transcode_init(); if (ret < 0) @@ -2957,22 +2943,6 @@ static int transcode(void) /* dump report by using the first video and audio streams */ print_report(1, timer_start, av_gettime_relative()); - /* close each encoder */ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - uint64_t packets_written; - packets_written = atomic_load(&ost->packets_written); - total_packets_written += packets_written; - if (!packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM)) { - av_log(ost, AV_LOG_FATAL, "Empty output\n"); - exit_program(1); - } - } - - if (!total_packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT)) { - av_log(NULL, AV_LOG_FATAL, "Empty output\n"); - exit_program(1); - } - return ret; } diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index c2b7993e66..9a91861bd4 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -598,6 +598,45 @@ int of_stream_init(OutputFile *of, OutputStream *ost) return mux_check_init(mux); } +static int check_written(OutputFile *of) +{ + int64_t total_packets_written = 0; + int pass1_used = 1; + int ret = 0; + + for (int i = 0; i < of->nb_streams; i++) { + OutputStream *ost = of->streams[i]; + uint64_t packets_written = atomic_load(&ost->packets_written); + + total_packets_written += packets_written; + + if (ost->enc_ctx && + (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) + != AV_CODEC_FLAG_PASS1) + pass1_used = 0; + + if (!packets_written && + (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM)) { + av_log(ost, AV_LOG_FATAL, "Empty output stream\n"); + ret = err_merge(ret, AVERROR(EINVAL)); + } + } + + if (!total_packets_written) { + int level = AV_LOG_WARNING; + + if (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT) { + ret = err_merge(ret, AVERROR(EINVAL)); + level = AV_LOG_FATAL; + } + + av_log(of, level, "Output file is empty, nothing was encoded%s\n", + pass1_used ? "" : "(check -ss / -t / -frames parameters if used)"); + } + + return ret; +} + int of_write_trailer(OutputFile *of) { Muxer *mux = mux_from_of(of); @@ -629,6 +668,10 @@ int of_write_trailer(OutputFile *of) } } + // check whether anything was actually written + ret = check_written(of); + mux_result = err_merge(mux_result, ret); + return mux_result; } -- 2.39.1 _______________________________________________ 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".