From patchwork Tue May 22 22:40:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 9059 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp129746jad; Tue, 22 May 2018 15:48:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZowcdmXMhIScvwF9+PDRcp56b2WqACSKFLvpd/IO6by76MJ/p0/pgP6PwSFycAPHwSPDF7z X-Received: by 2002:a1c:14d4:: with SMTP id 203-v6mr2249724wmu.130.1527029299938; Tue, 22 May 2018 15:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527029299; cv=none; d=google.com; s=arc-20160816; b=sGjpk8ys69aNQneM2M+7hGvKT7pWztqOT/i8rPhGw49Az1U68sXeLaKFa74TQyWjh7 xAJqzuJWDV6RLt/HWCeELgbAj5udeHuglcQV0GPTnM9QwNSHUkXrNsEzE4YjMYHRz0Xd tJ5NjQi+++zJRg8B+U7OWcwDE62a+AAyDIqxmFhy2eYlVKZDm1k0j8N+NzU6h2RHN59X yUT+jFQ8THezsvcvHCmU2/gp0iG4aiKWwnsNbUQH6pHjTUe35ECIlJJW0/IcUj6hLhWk Sk2YZMbtWgAyNllblj0ei0XhRL7lQTY1B07A79F+vIR31jmZEFSc5WN6xfMeQdFM6urB opew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=3u+x44K20TWjPpCbA8rPpZvTjGMjYrPh7MF21/Nccww=; b=Jl8BeMvCO0k2QGJhCYSFplVueT56AedzWgozte31fDMDn9rW4HOcIyxgJpAP5vzNJv AP9Ph7lqy3vD44PRaqfIMA1upGVKEoO8gS5hRCsoqVcU5c2SzT1KPXGu3Ch4Nr8KFsdn GNI6CLlaLc3aM2Dj5hpWm0nRAIty5EkosJgqjPSAnmQF2GsJ6DKF95mNWEN5MrTAzjf6 5IJS+0IR8kPeMSsmu6g7zDjwtwXheE0PfezmpH5xq4IQYbFraZKpg+y/zbrWxkwGjmSB ts/4hxyAX2Eh7qm2ycU9ILkGtSPCond1h3Uia6rmkh0/WxKuy3q6xaGFZFJf1SThamJc h8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RDbamN3+; 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 n15-v6si4602059wrh.400.2018.05.22.15.48.19; Tue, 22 May 2018 15:48:19 -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=RDbamN3+; 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 5A12B68A12D; Wed, 23 May 2018 01:47:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8EEF689940 for ; Wed, 23 May 2018 01:47:29 +0300 (EEST) Received: by mail-pl0-f67.google.com with SMTP id c41-v6so11744791plj.10 for ; Tue, 22 May 2018 15:48:11 -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; bh=+e02sl1w/Y5tMwHHmW7wDwA3qw/n0IxCPw669P0lK/4=; b=RDbamN3+ITfZr9rrOi56IZyxgoI37ZJ4Bujxq0CTH0sqPfU27NRoIsmzgnTX73sdWM HuU+4Z+nQs2BM/8BKu0gziSVJTCPnitVzY28wOEUfw+NIRlvVlr3S35DiZLbgvhuArJk sCKX2xy8LWtmMpqaAQps/WstkoQtbdxMCmigzlBuO3lPVlJkvscTDNljHagNeQZ5UxGQ TrGpA2gymQLgj8di0o7FV0iKLLsmJ+cgdny/Q5wF6ekMX6EWCx8OBEwCv2pkUVxQj8fH cKQCcm92mFlNp1XVLWgHWGKKD/pClEstKEQVk6c1iyl8alDHJ7nqOjq6839yzNXOxPbj ORbw== 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; bh=+e02sl1w/Y5tMwHHmW7wDwA3qw/n0IxCPw669P0lK/4=; b=i8bfm/TZCTz4LIdr4LekXseVaX+Q+Pe+CiEH/Q/0sxJqaw4FqnjKufAnIj1P3Wpyxp LAsutiAToa43Yjej8PkbRG9gSYJQwyNmMQgcECe59j4o0zEzvs/AT9bdaMODjUy2fJF1 snCmmM8mxk6pPkXO0tfviF42j1goc177NG1DaN63poWlEoIlE7wbHGslRRR8U+R/6FNH NNC/cOavaGuEyOl39HnIhh2R2pNMNrsS/cwv9OxQh36M1hNMbNTHM5BnA93YAnX/Sv/z mWMvuf+Jtq9dt9Gv6M+X/TCZoh0YJ82aWrad8Fy0Co71duISrN20M5/IOHI+82iZUh6L w2/A== X-Gm-Message-State: ALKqPwdWuERnAC0g1DLri5jmcW4YD8D1iz5Ehxf9o+SNqGYl/PkwTDPK SdGNpXdh3nOsHnG8CmsA6XvIrlz4 X-Received: by 2002:a17:902:ba87:: with SMTP id k7-v6mr332121pls.193.1527028863195; Tue, 22 May 2018 15:41:03 -0700 (PDT) Received: from wangcao.mtv.corp.google.com ([2620:0:1000:4011:7b84:dc77:c8b2:63c]) by smtp.gmail.com with ESMTPSA id x88-v6sm50080324pfj.126.2018.05.22.15.41.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 15:41:02 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Tue, 22 May 2018 15:40:54 -0700 Message-Id: <20180522224054.217713-1-wangcao@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180519120950.GA23145@sunshine.barsnick.net> References: <20180519120950.GA23145@sunshine.barsnick.net> Subject: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" - Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. - The report of video/audio sizes is clear as previously all output video/audio sizes were combined to report and it is unclear such stats is for one output files or aggregates for all output files. Signed-off-by: Wang Cao --- fftools/ffmpeg.c | 65 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5a19a09d9a..0b98521852 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1526,17 +1526,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; + AVFormatContext *oc; for (i = 0; i < nb_output_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; @@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size) } extra_size += ost->enc_ctx->extradata_size; data_size += ost->data_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; - + av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ", video_size / 1024.0, audio_size / 1024.0, subtitle_size / 1024.0, other_size / 1024.0, extra_size / 1024.0); + if (percent >= 0.0) av_log(NULL, AV_LOG_INFO, "%f%%", percent); 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++) { @@ -1676,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, 1); @@ -1693,12 +1709,13 @@ 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) { + if (is_last_report || !is_last_report && !vid) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { float fps; frame_number = ost->frame_number; @@ -1750,14 +1767,16 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti ost->file_index, ost->index, p); } vid = 1; - } + } + /* compute min output value */ if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), - ost->st->time_base, AV_TIME_BASE_Q)); + ost->st->time_base, AV_TIME_BASE_Q)); if (is_last_report) nb_frames_drop += ost->last_dropped; - } + + total_size = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1810,14 +1829,18 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti av_bprintf(&buf, " speed=%4.3gx", speed); 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 av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end); - fflush(stderr); } av_bprint_finalize(&buf, NULL); @@ -1835,9 +1858,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti "Error closing progress log, loss of information possible: %s\n", av_err2str(ret)); } } - + if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)