From patchwork Fri Jun 15 05:37:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 9417 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp372001jad; Thu, 14 Jun 2018 22:46:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJzh5FaTiKJUDyiPG114PWTQglHBzAqDgtyxUciFqVv2X7rsvi5etouadd3dIHdBCIEIrtz X-Received: by 2002:adf:dd8c:: with SMTP id x12-v6mr284595wrl.212.1529041583224; Thu, 14 Jun 2018 22:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529041583; cv=none; d=google.com; s=arc-20160816; b=DEK5h7zAQX0xur6ou4gwEa6HYbLlv8INiAJdYJfwQCmDCwxoL3D5GjBlFs4Bdodpcp FTf4I6mgZUCQ8ncI7xVgdSkXFKZOhzlvL19z6KMaiJcn23YjAIKTKDbCEROyxpbz22ls S6BSFHODoc/iSmBS+eMKmLuVerOLwhoxk2NBOwvIEKANYHLtDcljE0WG0gihVox7dzjU oWvig8oAePsrJQwZQgGNsR+wNTNxPJezT/PI+DyTXc14UTffUX8Lidi3GmBBosWw2dXB Jc3Mc6GhEyKZWTZ6Q46rfvyMWYKdaGwpBscHeqqiWxirvc+AZs/3EU6/cOIqd5tI3b63 vy7g== 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=c1/ltMTNu/dDH/ffWceevVekd+hI2TvIYvOHu6JL51U=; b=u/DU8N5vmjV3eIsJFzNF7l7yN+btRnPiy6PuR+wg6fTE3Q6H+IE8tf4VZ960LgcY76 rUow/HI4MoKHUOxe8oeTtGhfoX8iG3QVUko1cyH9EhGPhdjpxjoI5bGvHcNeNu9ZF3sr dPDAaHkrsO7T9ocST23EDx6oUWmRWp3LysqvfW8K8416DyYqh32eeGuMh1m1Gzu4WY67 JrYnQ9w/SXiWUOhhy5CAh78zDTkrHHKVM2SxTCQGuCrxxXo9Bz/LAJNqVoE/KuSD7RJF 7trv+BjAZpfS7VEeFDSa9QYN1ruIG9BiHKeRrQb30AzyUqOMP3wprEWjZ66XsuMfho8t fWNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Jbi4HwXr; 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 z14-v6si6000034wrn.199.2018.06.14.22.46.22; Thu, 14 Jun 2018 22:46:23 -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=Jbi4HwXr; 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 D09BB68A78A; Fri, 15 Jun 2018 08:45:30 +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 E06EB68A788 for ; Fri, 15 Jun 2018 08:45:23 +0300 (EEST) Received: by mail-pl0-f67.google.com with SMTP id b14-v6so4772128pls.5 for ; Thu, 14 Jun 2018 22:46:15 -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=TUgsIH1rudeHg8t4b/oLWYJvDwpQVHsRLsGg0MInCoM=; b=Jbi4HwXrbqyaCzf7GOYzmDN73v0ATxwcDL0/4TNn1GdjK6v+WMgX/23P0zbFWuxTUV kCxjE6afbaVpuS1+PwyNlTMq77BfNFOZtAa0g82i5TeW3rssyCzCFQ6ByGtTu3I0IZXl 9rspt+GfuvLiz1t7/t5nFl6aOgu7LUXA3ErgDpUEoL414UiBOOs2cKepplLFPVbs9jBY 551uW5nLfPrig0RNdj8JAYU7lLeWibJuvAVlHlpNuWRKg6QLJryhZgo5API88PO6DAFN iDSzPl6emOQlsiyKkRNC1QTuqokegT1B6lFkjD2y569o4pIvzLhut/2RlMJg9Mq4TfQ2 ALrw== 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=TUgsIH1rudeHg8t4b/oLWYJvDwpQVHsRLsGg0MInCoM=; b=nxzSMuIPs95as7+o7L1utJNl6yzN/kgaluS1fR5ZNNLGbsUU9jurN7H+fk9K+ALiz7 XdBvPymOaTOZ9Iz+Rix9/WEqeYZGFQT6CZFIpGxMdaluM5ard8dKQrV90yn+oHG181eO 9RoRyAktxsVhT2P7dHhNf5hoNEbKK8e7ENkl3XO5ArdJWyd+BsDHYcOtd4SqXIXtVaQX 8TW1NNv7O0tfFWP6lP6wP1B3SMgN7ajv+liA40GfW84cdYKe5Pw5OhQcFwkTBPA67FRa DToIABBoxk0IAKRUUskmbjSa/wUED7LNrKNkSflIXqRh6F6zA7Cvw9cvzzjtWxYgQjtn XWng== X-Gm-Message-State: APt69E2QXoBcJNqc4ySpnx8SrI+Le7Dupn9K4jTXUvYVprycwiQ9UE0Y yfAqLfOjXmU09oa87NC4dRmjzGnb X-Received: by 2002:a17:902:8a94:: with SMTP id p20-v6mr313453plo.258.1529041088338; Thu, 14 Jun 2018 22:38:08 -0700 (PDT) Received: from wangcao1.bej.corp.google.com ([2401:fa00:44:10:97fa:2969:3ac1:d58e]) by smtp.gmail.com with ESMTPSA id a23-v6sm6171598pfj.117.2018.06.14.22.38.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 22:38:07 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Fri, 15 Jun 2018 13:37:31 +0800 Message-Id: <20180615053731.161792-1-wangcao@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180525143728.GQ4859@michaelspb> References: <20180525143728.GQ4859@michaelspb> 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 | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..1eaf344552 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,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 +1858,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)