From patchwork Wed Jun 20 09:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 9448 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp528910jad; Wed, 20 Jun 2018 02:34:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJSaWiLxWsBxrdOocw8j8lhJh/UjD3K1l/Oe9o+gaKaVuGjAVWeStoxgL1GFwOzS6gtvjDl X-Received: by 2002:adf:e48e:: with SMTP id i14-v6mr18449020wrm.8.1529487240996; Wed, 20 Jun 2018 02:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529487240; cv=none; d=google.com; s=arc-20160816; b=kfteKyqiHdYlmze5YecRLZHdKUyjj63UC9JDHxaS1ix65kSJY4Ib3giTn7DheDqyTF e+eYRPKORBvsijbK5sdWWkXcPq7z9UiII1DRihihCCgE/i2iDRQDqUVrAeI5IescQdJ4 Svh9POMqPUL3gbDfwM0aTY9ACme0d8GCH5XBm8JX/+PgJBt8MbtgdLyrB+7NpkyYjX/1 af+lg21YUryxh6vIUAciDIB4wyLCPPly+VxVQfH/F8v5NVaB6KZm2Q+mirGumj8+n9dv qcwEb+X6LGAgUfGwDCrLyZ8HIVYeVHOBmdawXABrOYQo9Wac3kwWrf1AhWkr/KSPD+8I O8Iw== 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=apsxbIe3tWMk4hRJP2ud5amcD8iK5vMa9w8FFkqy3HA=; b=PP/fDD7h/BL36QiRrzj1hvCl0Z0wMAo5CEsjSbyoyVNzYUIV5PF7Ty3ErEwX9x0n7r GxqxmVYE1q8hHfllT64wEipfHwhnZ1kqgBqQvRuIEMrGq2/owbAbtU6w/0PAols1mHRV BjzemorQPpENz1f0b+NHG/3Tu1u0YiNPD0fbCxxAn+o9IM+qxBybZ9XM7wmcgMfUzbS/ XmreVqe60pdNGSyUWnOZi1eNzUkaxWGVBO5e4+BqI92TNRkkyBhgZvUWila7TByksPPH QRrk1e4GJDB5baNCCltGdXD6viXr3W5qRP2EiImVvF/pBrR5qeXgJRoJLfnWzUO8m6N/ UJww== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=gEOinO7A; 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 y18-v6si1939905wmc.152.2018.06.20.02.34.00; Wed, 20 Jun 2018 02:34:00 -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=gEOinO7A; 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 BE97E68A3D1; Wed, 20 Jun 2018 12:33:05 +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 34924689BB7 for ; Wed, 20 Jun 2018 12:32:59 +0300 (EEST) Received: by mail-pl0-f67.google.com with SMTP id f1-v6so1454167plt.6 for ; Wed, 20 Jun 2018 02:33:52 -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=SYpPOncBfuI/nkNviry4kWCUvj92M4FECtSZFh4UeX4=; b=gEOinO7A/cy2RZezjc9ez3kzrsLz00K16+5sulGL94w4I57nDMMBAsKbG9hPvuxamd Yrk5BGSFR402GL0cV9Bff5Uai7xd2e/8WcwbtCfKswrqNKJmCUpvGqWWXOsThLNwqGnr eb5/93PFj9HbYhZ2w1jKQ4adlo+pCjYcVZppun6pXqSithucE1yYkqQDqxh383RBqT89 Ie2/I219AE4whshnwhzTuKHD0Ey0Nw+71vh7wLpqScxS4dVUqjQPxNh+dIyIaXFnm9tU vg6KxkHNaUcpesznm4KOkSpr83PcL9BrkeGjpopYEPu1PAyZdt6PgyQqJol+dA2RiX9q nFVA== 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=SYpPOncBfuI/nkNviry4kWCUvj92M4FECtSZFh4UeX4=; b=UhbC5NBX7FQPBCg/cKecSI8F1yUBn6p7VHIf1HXHRDy5MM29jLRaphHqKhTOdGVVMH He/2COUVuZv6xFFPnmO1+xpnmM64HjRcBVuqJx/d+oCuuFQJU8WFuHU9I8I2NZkzyoo/ BrLQ6KxOMnkns2YP4HPMxOHE8Cu/msJNPuO3l6IGRJfmzb8+0Z0lO+6V1ZaKtOYpyY1J AjB1GPh+GPKPZmUhPVudiq4eQJe93czDCcYQrm3KLmnRnKP1icxh2KcB7bYKygaU4qQK otmtNfl/ef8qRCoOAzbvNHNx4bWr2OZ2KFABMrou+WuDU8/vrG/zVJg5uC2KmhalNTwz CO5A== X-Gm-Message-State: APt69E0U2lvhJ9BTWJqijvNCdvSTYgthAnBruxEiyU17NzvTWxdbuN/n ClINdWl+3Dkywv2NMoElCh6rK1Bl X-Received: by 2002:a17:902:5a1:: with SMTP id f30-v6mr22982630plf.167.1529486762280; Wed, 20 Jun 2018 02:26:02 -0700 (PDT) Received: from wangcao1.bej.corp.google.com ([2401:fa00:44:10:97fa:2969:3ac1:d58e]) by smtp.gmail.com with ESMTPSA id t192-v6sm2265888pgc.74.2018.06.20.02.26.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 02:26:01 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Jun 2018 17:25:33 +0800 Message-Id: <20180620092533.129039-2-wangcao@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180620092533.129039-1-wangcao@google.com> References: <20180615171928.GA8557@sunshine.barsnick.net> <20180620092533.129039-1-wangcao@google.com> 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 now 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 | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1842ccd543 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1530,17 +1530,27 @@ 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; @@ -1552,7 +1562,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 +1584,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 +1698,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); @@ -1697,12 +1708,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; @@ -1761,7 +1773,7 @@ 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 = ost->data_size; secs = FFABS(pts) / AV_TIME_BASE; us = FFABS(pts) % AV_TIME_BASE; @@ -1815,8 +1827,15 @@ 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"); + else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + av_bprintf(&buf, "\r"); + } + } + 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 +1860,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)