From patchwork Fri Jun 26 21:28:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 20636 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D9C1B44B1E2 for ; Sat, 27 Jun 2020 00:28:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B69CD68B051; Sat, 27 Jun 2020 00:28:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6840568AA64 for ; Sat, 27 Jun 2020 00:28:39 +0300 (EEST) Received: by mail-pf1-f193.google.com with SMTP id t11so304622pfq.11 for ; Fri, 26 Jun 2020 14:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=BP5rf0XCjU5/bOW3h0N2pBZP0J1F59sYX9j5dwdpUrU=; b=lDQTdNCkT8pJqzQe3iURrx1Mm/W4DQIc9sNqv+rPkf8J/QRAkMHowm+c1la/5lFWXN oBlpLJitqarJv3kCKPP4X4cLow1wDR8Goy2asjjM4Ft5/K/oBW+YLCFKHvOctb//oack eBGjbhUqi929D2Wj71BaktiffrNvrKD9GkyAISUuG8tGpR6nU7Bkuo7ItRq7sO1Ip1mP 2R3lOz8gcRELSeVc3vfBYt1GM2jZ3COov5a++r/Oa8iUe9osYcNlEchOG144fQO32FoR 19UCfbwFvtz52BmdGXoPIXIhzbyv21e6ntSBJhsv4dOFdgGEoonQjJJH+b5yQbjMjbTd tT4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=BP5rf0XCjU5/bOW3h0N2pBZP0J1F59sYX9j5dwdpUrU=; b=C7ZeDsRPzP8yFyC/ceZJjRIXQYYXjJmybf8Tg4+zYlGY1m6qHsTvp01LZhcZ1WFu4i eBl77b0xaWmYsx4lwu0uMKZ9lyKH5kRDFWL3g31SU5lLjA5fY5+yHdGWcrjtKhz8N7X6 ZDa2N5z8+Vm3wjhRD7IR/wl3u9sFZ1isSwNlfwyiZLKku1y7LwQMEsGjV5NEWUjmpZ3f c7GCwEt/MAEH1cHCmsBgdk3p5Bh5QKCMZ2FlwVMpD5n7YLGMije0bqWmtT9YVXmUFG7n np8xvP63GGMQt2uwrNgDFyABX7xGI6cu6AMqmFz5hhPB08yrOOaal+tQiq3tQ1CA3mF3 gieg== X-Gm-Message-State: AOAM531r1Z2WvdOILmWNuoqTN3ATQxDQmcuYc7yKoxo85Z1Cu/GgvZXR f9N3lWPWSTDB+7H8nenuKvgU1VBOSLI= X-Google-Smtp-Source: ABdhPJx0OytXUAKW5AgqPzp8gJ7rhXoEouizPBL0oKAmg/E7EvVtdopxDdk8cvTEvSbIm4OwHJOjUA== X-Received: by 2002:a65:640c:: with SMTP id a12mr675423pgv.88.1593206917093; Fri, 26 Jun 2020 14:28:37 -0700 (PDT) Received: from wangcao.mtv.corp.google.com ([2620:0:1000:4011:7b84:dc77:c8b2:63c]) by smtp.gmail.com with ESMTPSA id p10sm11866495pjp.52.2020.06.26.14.28.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 14:28:36 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Jun 2020 14:28:29 -0700 Message-Id: <20200626212830.1734049-1-wangcao@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg.c: Use the streams from the first output in print_final_stats. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" From: Wang Cao It appears the initial intention was to print stats for the first output. Currently all output streams are aggregated for the final stats which is inconsistent with the "size" reported in print_report. For example, when two outputs are specified, output 0 has size of 100 kB and output 1 has size of 50 kB. The output would look like: frame= 206 fps=3.6 q=0.0 LPSNR=Y:45.57 U:50.04 V:50.07 *:46.62 size= 100kB time=00:00:07.10 bitrate=1362.7kbits/s speed=0.124x video:140kB audio:79kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.382502% The "video" reported is larger than the previous line and this is confusing. Signed-off-by: Wang Cao --- fftools/ffmpeg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448ea2b..07396204b6 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1516,6 +1516,7 @@ static int reap_filters(int flush) static void print_final_stats(int64_t total_size) { + AVFormatContext *oc; uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; @@ -1523,7 +1524,9 @@ static void print_final_stats(int64_t total_size) int i, j; int pass1_used = 1; - for (i = 0; i < nb_output_streams; i++) { + oc = output_files[0]->ctx; + + for (i = 0; i < oc->nb_streams; i++) { OutputStream *ost = output_streams[i]; switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; @@ -1674,7 +1677,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); - for (i = 0; i < nb_output_streams; i++) { + for (i = 0; i < oc->nb_streams; i++) { float q = -1; ost = output_streams[i]; enc = ost->enc_ctx; From patchwork Fri Jun 26 21:28:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 20637 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6CCE744B060 for ; Sat, 27 Jun 2020 00:54:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49D0168B1AA; Sat, 27 Jun 2020 00:54:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2501068AD9D for ; Sat, 27 Jun 2020 00:54:47 +0300 (EEST) Received: by mail-oi1-f195.google.com with SMTP id 12so2802560oir.4 for ; Fri, 26 Jun 2020 14:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hyjCLwzE98aunlDY0FCS1QZGsPB628cioll7BYxkgJs=; b=e8xHKa8zDigwbU/5V+KKooqKF0qdGpCWFbGGIZaYDNui7LAr58WFVST59JV6rgIrB7 BXQKKFZrI9vWnNeGFMBODB3D/sG4VMZOgUb/Fni3zEBhCZLaiVXiunvXQqj96fvK+50C 6HEW1Am/w+u9TLB0pKo9N7XE3Cr3Jgfo7nxsGW/rBCfzpDz3sGxyCHyNHKp/eqxb/Z2D N+70Cz6kaCB+gSEbB6kBqBD86GhYu3EEeiER3+v1/Kn+Y4s/huiuPKyp7BgNNmEjlO8p ki6h0vSX4yZpki5cVPmJB1z2MuXT6Q+DkF8aAYTVEHpmPInrpuRAy/qjmsuDms7BA7OT 0paA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hyjCLwzE98aunlDY0FCS1QZGsPB628cioll7BYxkgJs=; b=fQHvso2387yoZUJmcVE+Gisl1qR04Ha8HOJ2upS7DoERXu/5KFLbg/WDUZFqMKkaTq PZ5op7HS74mj5yDvjAJcN5gXgxaiAyvtHLibTNcpyVzvfpUE2Q4RNmvj05kFO1sRufb4 f1GJ5LH1cnVvXjP8UOQwyg6/XVM7pSk6YUxY1lagGvneZq18pxswRsaQ8neMpNUeNOfz 29tK9v6XjMvIApERM0sMHUWuqJFIhUEmEsvsAZophFprVl/uP2KluxNxl0NJFlTex8d/ SBp7T8DioN2XPvRm1zKa4/cfkjqPM1ElDFXzQgvp7Rpc2PWXM1IzIKRbX60JBooqyG1s xejA== X-Gm-Message-State: AOAM533vQEo1QHSEe30OFsfBxM2/M1iHLmqXMIzv1kniHsPKR1oIg95i AeH7fbFngL86xASAVGxloh1+y1F1KgU= X-Google-Smtp-Source: ABdhPJx0deT/tY8WuXapx20+PG48KaQj+22V803KQ7cmiOvE2KfOw900Z1la+kY5FFvivwI5DYnC7A== X-Received: by 2002:a17:90a:65c5:: with SMTP id i5mr5490708pjs.155.1593206918283; Fri, 26 Jun 2020 14:28:38 -0700 (PDT) Received: from wangcao.mtv.corp.google.com ([2620:0:1000:4011:7b84:dc77:c8b2:63c]) by smtp.gmail.com with ESMTPSA id p10sm11866495pjp.52.2020.06.26.14.28.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 14:28:37 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Jun 2020 14:28:30 -0700 Message-Id: <20200626212830.1734049-2-wangcao@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog In-Reply-To: <20200626212830.1734049-1-wangcao@google.com> References: <20200626212830.1734049-1-wangcao@google.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] fftools/ffmpeg.c: Add an option "multiple_output_final_stats" X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" From: Wang Cao * "multiple_output_final_stats" is used to display stats for each output when ffmpeg completes processing. * Also refactor to add a new function to print verbose stats for input/output so that the behavior is same as before by default. Signed-off-by: Wang Cao --- doc/ffmpeg.texi | 6 +++++ fftools/ffmpeg.c | 53 +++++++++++++++++++++++++++++--------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 3 +++ 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 70b8965d7f..6c88c97c60 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -734,6 +734,12 @@ ffmpeg -dump_attachment:t "" -i INPUT Technical note -- attachments are implemented as codec extradata, so this option can actually be used to extract extradata from any stream, not just attachments. + +@item -multiple_output_final_stats (@emph{global}) +Print final stats for each output when processing completes. +@example +ffmpeg -i INPUT -multiple_output_final_stats out0.mkv out1.mkv +@end example @end table @section Video Options diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 07396204b6..1757899d7f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1514,8 +1514,9 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats(int64_t total_size, int output_file_index) { + OutputFile *of; AVFormatContext *oc; uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; @@ -1524,10 +1525,11 @@ static void print_final_stats(int64_t total_size) int i, j; int pass1_used = 1; - oc = output_files[0]->ctx; + of = output_files[output_file_index]; + oc = of->ctx; for (i = 0; i < oc->nb_streams; i++) { - OutputStream *ost = output_streams[i]; + OutputStream *ost = output_streams[of->ost_index + i]; switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; @@ -1555,6 +1557,18 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + 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_verbose_input_output_stats() { + int i, j; /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1624,20 +1638,14 @@ 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) +static void print_report(int is_last_report, int output_file_index, + int64_t timer_start, int64_t cur_time) { AVBPrint buf, buf_script; OutputStream *ost; + OutputFile *of; AVFormatContext *oc; int64_t total_size; AVCodecContext *enc; @@ -1668,7 +1676,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti t = (cur_time-timer_start) / 1000000.0; - oc = output_files[0]->ctx; + of = output_files[output_file_index]; + oc = of->ctx; total_size = avio_size(oc->pb); if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too @@ -1679,7 +1688,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); for (i = 0; i < oc->nb_streams; i++) { float q = -1; - ost = output_streams[i]; + ost = output_streams[of->ost_index + i]; enc = ost->enc_ctx; if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; @@ -1830,7 +1839,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti } if (is_last_report) - print_final_stats(total_size); + print_final_stats(total_size, output_file_index); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) @@ -4672,7 +4681,7 @@ static int transcode(void) } /* dump report by using the output first video and audio streams */ - print_report(0, timer_start, cur_time); + print_report(0, 0, timer_start, cur_time); } #if HAVE_THREADS free_input_threads(); @@ -4706,8 +4715,16 @@ static int transcode(void) } } - /* dump report by using the first video and audio streams */ - print_report(1, timer_start, av_gettime_relative()); + /* dump report for each output */ + if (multiple_output_final_stats) { + for (i = 0; i < nb_output_files; i++) { + print_report(1, i, timer_start, av_gettime_relative()); + } + } else { + /* dump report by using the first video and audio streams */ + print_report(1, 0, timer_start, av_gettime_relative()); + } + print_verbose_input_output_stats(); /* close each encoder */ for (i = 0; i < nb_output_streams; i++) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6e3f2545c7..44414746e0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -609,6 +609,7 @@ extern int frame_bits_per_raw_sample; extern AVIOContext *progress_avio; extern float max_error_rate; extern char *videotoolbox_pixfmt; +extern int multiple_output_final_stats; extern int filter_nbthreads; extern int filter_complex_nbthreads; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 9d1489ce01..2154a79aeb 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -172,6 +172,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; +int multiple_output_final_stats = 0; static int intra_only = 0; @@ -3569,6 +3570,8 @@ const OptionDef options[] = { "set the maximum number of queued packets from the demuxer" }, { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info }, "read and decode the streams to fill missing information with heuristics" }, + { "multiple_output_final_stats", OPT_BOOL | OPT_EXPERT, { &multiple_output_final_stats }, + "display the encoding stats for first stream of each output." }, /* video options */ { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },