From patchwork Fri Jun 22 08:03:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 9478 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:141:0:0:0:0:0 with SMTP id c62-v6csp639179jad; Fri, 22 Jun 2018 01:09:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6s1cQ49rJXTF3a5RuYPn+IBVdloNUB46fRq58DwtrXdlv/uEO/IIWff3C3gmyE2fxG6V9 X-Received: by 2002:a1c:8a4b:: with SMTP id m72-v6mr915256wmd.2.1529654974815; Fri, 22 Jun 2018 01:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529654974; cv=none; d=google.com; s=arc-20160816; b=ICkut1mNmckUmoAnA4e1OEgEs7ix5db8jaPAMCSdvkefNKnhqBnCdjLyOp0k0BvLUm oOeJCnjbenH1oTEUiJHVWgPOS8XbBv2dMe/lGo2qrAZMFN40Obiy1jFzDL252xlVaI/m nKOCe4XiUZPlMzF5KaZAZq46qjk2khUGzkBsu5OlzM6sCdGJxz/kUcVOdqHngUbqXzyh tYv13VeuYxkzzNaaWkEUtYXx92vIJicSatYB+Cqpf6xBx9N6PoyowXYzx30P7jqeUpH/ 059AbhzX7MISNpej7JkE65VhF/kbCYspBz7RIvrVFARiYORY8aq/hytYDsdr/JE7GMFP cFPQ== 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=k7DzTOrlpW/S/qaZPpu1aAyriExA78/Nks2N37n68GU=; b=c25SJ7YmbC/4cY4VIAV4p5Sb/bybeELqSz4m9MFrtNSsQ1DAjNb8aFIIXpgGwTN6sE HmveKDN6IytKNFilHwURr+xm+3diwPzurVnk/gJPk/v10U/pmSgVH5r/+atLk11FIDfJ yOxE6urUg1ohV5f5GdBo1dB1m2C/8srZPcFjHkE6uhzPPfP5O+UqQrPCECdl6uaQMidL 9YoAB6Myjj7cvL1q2GuY2VnZyd4Zw+3/uPU/p1z8CdaiPCkdxnw5MP4g83EH39KGLAp/ KmOJJq1a80Atyt0r/hi8yX8ERpwmQhpCLIKGzaj3GrK/pcGFPlnPMVSm+GZ1wdqpHrd4 c1XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pff8lQ7H; 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 n192-v6si1044008wmg.186.2018.06.22.01.09.34; Fri, 22 Jun 2018 01:09:34 -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=pff8lQ7H; 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 C08A868A814; Fri, 22 Jun 2018 11:08:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CDD568A7EA for ; Fri, 22 Jun 2018 11:08:32 +0300 (EEST) Received: by mail-pl0-f66.google.com with SMTP id k1-v6so3105177plt.2 for ; Fri, 22 Jun 2018 01:09:26 -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=zmVATneEFrGJAZgmedl0u4cPsMwSb4zt30F862IN+/M=; b=pff8lQ7HzjWFHvjeS55X869ri9UvAGMAfdBuPpLhCJbTNG8DrFurVndvWGTkSxk8uB YecZYBoRPZ1NmuJfCxze3G1TqHwN1SvmLu3+0AjEVedkpsMUEy7SgSkNzT7AnexoGejG p3S2NMSkKXrPvkKnOncIXZ6hg6J4nTf4xqseqIhZtEPdyI19Ey7NG6LwzBom2wZvLEDX Bxk8lF12ewldnJpxxMPUjKqk+B6d4XzzpyBTw04DKGprpqJIuy+873hFsbVq+bYPqE6p UyqDe7y5p61GGEcg1ZaznBHBr8HhmnXuQo/6WmMxIkSf0RJZEiy0V+q6/iPfH+50AvOi 7R3w== 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=zmVATneEFrGJAZgmedl0u4cPsMwSb4zt30F862IN+/M=; b=XC6PUoOBwUd/yOFEaSeye6yKsBeMHc9uq4tyXHyAIS1GKF6/aLNvONpCVQipy3UbQM amWXlR7NMnEIBP5R1vgxnaH1GmmToEINSjS2EPnB1uG6nWCJq6ojWpsrdWdMD3e3SpZs 44McSs9SocANktgRjRlHxki14RfOTIcm9zApoY+ZAffbI6VGZGif8Q+uh1erZpEHMC4m uxOay94+cfXGiJbwipDTrEbi4tbTOnIFyIuX9eZMSTCWCSwP5ppqxxJ3mAERMmSeHeCG uGXrkklhc8u3oTvHRvaH/jgCWNOI1KmL+iEPMB1+xIy4413wSJDFEyO2DOA9fSXfk7b8 LBMw== X-Gm-Message-State: APt69E3mSZRIYCEVIFi1rYSDL+RDjQuMm4WRoLwT+CgdHPonoDLp5IQq TnDXOQd63Q+B+MUPFAbJGGJgALhw X-Received: by 2002:a17:902:563:: with SMTP id 90-v6mr562155plf.327.1529654641946; Fri, 22 Jun 2018 01:04:01 -0700 (PDT) Received: from wangcao1.bej.corp.google.com ([2401:fa00:44:10:97fa:2969:3ac1:d58e]) by smtp.gmail.com with ESMTPSA id e5-v6sm8350281pgs.59.2018.06.22.01.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 01:04:01 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Jun 2018 16:03:38 +0800 Message-Id: <20180622080338.99498-2-wangcao@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: <20180622080338.99498-1-wangcao@google.com> References: <20180621160823.GN4859@michaelspb> <20180622080338.99498-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 | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index d4ac6903cc..321f7a6017 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(void) { 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++) { @@ -1651,7 +1669,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti { AVBPrint buf, buf_script; OutputStream *ost; - AVFormatContext *oc; int64_t total_size; AVCodecContext *enc; int frame_number, vid, i; @@ -1680,13 +1697,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 +1707,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; @@ -1759,9 +1770,11 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti 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)); - if (is_last_report) + 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 +1828,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 +1861,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)