From patchwork Thu Aug 23 19:43:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 10110 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp2522585jap; Thu, 23 Aug 2018 12:43:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0IVNAMZnAdCHqcCj4JPLhYYabG+OxOFxeJG4D6I7+8QUKs3NtuG6v0TB/wiWhVwDwF+Lj X-Received: by 2002:a1c:3a8f:: with SMTP id h137-v6mr6566351wma.41.1535053429275; Thu, 23 Aug 2018 12:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535053429; cv=none; d=google.com; s=arc-20160816; b=PjWrqOK5bbvhcat4oU5O/uj6hIS9k+X4kWUeohqHVCa6J6h91Mumjel2RXgJQBIaRe JV6ZySYLpWHOaxQ34xedZnx8JNzl/YP6IfwYZEQl6dUPupihNpKBDywX9l2+p4FTZZJi CLp2wtUjWnwgDEqh9P+q5mkr4g2mLTjPyPc08ubefPSV59X0FbCtOo2GWNm6KF4lnp5N uHhpM/CWLfAtjgvpvCpRGnUaBBnjBUV+LTme46XgYWPi9SX/RQMsQVv3/7EcMJNOTUpD p5v9VdzUKVSodYUWCzESlbfyPzSHOxgRRripkqkxb6n8FNuF1u1vtM7ArA+g6dwCJAe0 /TgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to :arc-authentication-results; bh=AOEbKIqaPzVDEn1j7dch+DEQY+evW+2rBnQfbR/tHw4=; b=UWm14GocPuKdfUKDi+yH9brICIlLGps9cLZ77q0aqAeI51DwpD5JUyTeGtOpY9qzxH DElxFhKtjJguAVGZsS//bkXXl5d7OxOy9CSYby0ezVL9lsWKxjHO6UWSXkuKy5Lqw5Ox iDlDX6lN2NGaxECE4SIWEmVe0P9eVIVSqPEPHfmOfTXZEDbfv9wTZi/u6GtvShtiOhnV 8/f6WiEEsU1CHLSBg8dJLaElb8GeTxx0FcxBYw0YLAA3uVB9tvX0lozNPSpfe7LkkpB9 8lwvJj4kgm5T1tt957Rk1Ri9Ld9j8NT+f2+V/zcuctLvTgKTx6U+qA0STeraKa/Upb1q x8Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qW1hdIQL; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p16-v6si3782770wrw.285.2018.08.23.12.43.47; Thu, 23 Aug 2018 12:43:49 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qW1hdIQL; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 52EFD689C7C; Thu, 23 Aug 2018 22:43:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18D24689ADF for ; Thu, 23 Aug 2018 22:43:38 +0300 (EEST) Received: by mail-pl1-f182.google.com with SMTP id 60-v6so54927ple.0 for ; Thu, 23 Aug 2018 12:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HRb8pfQVL97jMiq2va7qwQOGfciX7omAw3dOkIRaDgg=; b=qW1hdIQLyDUZv+E2kQashSbUX3WaTbnlUj4LudZIXRNo1cZMeI1mp0p/YVbkzUJA8o +c0ICKmw2KNg9ZrZDTJQkQKTX+H1PsD9lq4gqROZXwZ8jEmLUq1XkJrEOFHpVyQoHsEV ZZ7uPlqxGwmMqpcQdtedmk410642Qv7mI3Vngp5gqA9hqN7uB/OF+lTEq05NOJ6Eq+Av XEIOLgmJPg5858WNQmBYVRcIbCajnplqRyuoEx461AkgqQxfNXjSuIShMKg9NB91Kgcu zO0qdJvnEoXwDcw/9SvISmO6L1kdhBTVp4NHw5uK1Et/7HrA4SUUiuRZeHHlsZ4nu4pa CguQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HRb8pfQVL97jMiq2va7qwQOGfciX7omAw3dOkIRaDgg=; b=csS7NvTimcTf2sbtM2GGrqJOetjh53kwmClQrVoPPsHSYyIdXzPxIE8xYN0S+NTRRF Ak7P6slUOBELK/yj/RILq4cvw2SySZNoSxlJgq+PmWzTrvHvxlWHyOE2noo+hgaaX/4S LX3Cpd1A36Rv4LfSkyK2G6E4BvXiGV3X9xXN5WEVtHuU8hsN9qXV2KCSladZT/0UqEB6 /P5xg64+Dj0t7nRRJD5ZqojnKR0vtZSNK3MCN+N+PeuDjcm1L+jqzeTqA/VfJUDOb5T8 GN1sB1fY1pOXQXfpp/TN1FnXNIosgcpCd7zE3Sa0WoU4StFc9p6Tsu8ettQwghdturLI rfYQ== X-Gm-Message-State: APzg51AbQzF28vixEZ9aX8KWsv3VU5/Hil3ZLSflY7GT42zg4L0XpruF QyWu5DGqbAYrqGlN+Klj1WC5WNGl X-Received: by 2002:a17:902:a583:: with SMTP id az3-v6mr11552228plb.0.1535053417749; Thu, 23 Aug 2018 12:43: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 x2-v6sm9344459pfi.166.2018.08.23.12.43.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Aug 2018 12:43:36 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Aug 2018 12:43:25 -0700 Message-Id: <20180823194325.158544-1-wangcao@google.com> X-Mailer: git-send-email 2.18.0.1017.ga543ac7ca45-goog In-Reply-To: <20180713003842.GE4859@michaelspb> References: <20180713003842.GE4859@michaelspb> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffmpeg.c: add an option "detail_stats" to allow ffmpeg to output stats for each stream 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 Cc: Wang Cao , Wang Cao Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Wang Cao Add an option "detail_stats" to ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. The format of stats is unchanged. Signed-off-by: Wang Cao --- doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg.c | 53 +++++++++++++++++++++++++++++++------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 4 +++- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..53a5be9791 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats to be rtp). Allows discarding specific streams or frames of streams at the demuxer. Not all demuxers support this. +@item -detail_stats (@emph{global}) +Allows printing stats for each output stream and output file at the end of +processing. + @table @option @item none Discard no frame. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2459374f08..2bd057ace1 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,28 @@ static int reap_filters(int flush) return 0; } -static void print_final_stats(int64_t total_size) +static void print_final_stats() { uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0; uint64_t subtitle_size = 0; uint64_t data_size = 0; + int64_t total_size; float percent = -1.0; int i, j; int pass1_used = 1; - - for (i = 0; i < nb_output_streams; i++) { + int nb_display_streams = enable_detail_stats ? nb_output_streams : 1; + AVFormatContext *oc; + + for (i = 0; i < nb_display_streams; i++) { OutputStream *ost = output_streams[i]; + if (i > 0 && ost->file_index != output_streams[i-1]->file_index) { + video_size = 0; + audio_size = 0; + extra_size = 0; + other_size = 0; + subtitle_size = 0; + data_size = 0; + } 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; @@ -1552,7 +1563,13 @@ static void print_final_stats(int64_t total_size) if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; - } + + // Print stats for each output file. + if (i == nb_output_streams-1 || ost->file_index != output_streams[i+1]->file_index) { + oc = output_files[ost->file_index]->ctx; + total_size = avio_size(oc->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(oc->pb); if (data_size && total_size>0 && total_size >= data_size) percent = 100.0 * (total_size - data_size) / data_size; @@ -1568,6 +1585,8 @@ static void print_final_stats(int64_t total_size) else av_log(NULL, AV_LOG_INFO, "unknown"); av_log(NULL, AV_LOG_INFO, "\n"); + } + } /* print verbose per-stream stats */ for (i = 0; i < nb_input_files; i++) { @@ -1680,13 +1699,6 @@ 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; - - total_size = avio_size(oc->pb); - if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too - total_size = avio_tell(oc->pb); - vid = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC); @@ -1697,12 +1709,14 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (!ost->stream_copy) q = ost->quality / (float) FF_QP2LAMBDA; - if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&buf, "q=%2.1f ", q); av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", ost->file_index, ost->index, q); } - if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { + // Only print the stats for the first stream during processing + if ((is_last_report && (enable_detail_stats && vid || !vid)) || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1761,7 +1775,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + total_size = avio_size(output_files[ost->file_index]->ctx->pb); + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too + total_size = avio_tell(output_files[ost->file_index]->ctx->pb); secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1831,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf_script, "speed=%4.3gx\n", speed); } + if (is_last_report) + av_bprintf(&buf, "\n"); + } + } + if (print_stats || is_last_report) { - const char end = is_last_report ? '\n' : '\r'; + const char end = '\r'; if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) { fprintf(stderr, "%s %c", buf.str, end); } else @@ -1841,7 +1862,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(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..275f128435 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -610,6 +610,7 @@ extern char *videotoolbox_pixfmt; extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; +extern int enable_detail_stats; extern const AVIOInterruptCB int_cb; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 58ec13e5a8..c71cf97ad9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -110,7 +110,7 @@ float max_error_rate = 2.0/3; int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; - +int enable_detail_stats = 0; static int intra_only = 0; static int file_overwrite = 0; @@ -3529,6 +3529,8 @@ const OptionDef options[] = { "this option is deprecated, use the yadif filter instead" }, { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr }, "calculate PSNR of compressed frames" }, + { "detail_stats", OPT_BOOL | OPT_EXPERT, { &enable_detail_stats }, + "allow stats report for each output" }, { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats }, "dump video coding statistics to file" }, { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },