From patchwork Sun Apr 9 14:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41049 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1590986pzb; Sun, 9 Apr 2023 07:10:02 -0700 (PDT) X-Google-Smtp-Source: AKy350bFWC1IxmScP0SotNSnX6tSaJTOas/GAWpKW7oWMGmshfWXRX0MV23djPttB8EzqpKC+6hR X-Received: by 2002:aa7:c0c7:0:b0:4fb:395a:6aa4 with SMTP id j7-20020aa7c0c7000000b004fb395a6aa4mr6895745edp.31.1681049402617; Sun, 09 Apr 2023 07:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681049402; cv=none; d=google.com; s=arc-20160816; b=ZnGGAl8ipLOXAIQSIiX3tGq/6e0xD+Brah4gp+tLLMkwh2nBzBn82eTdhYBDD5/hdA ZheqcSrjpftije+njW4OG1VXKevAG2gzcVlYuo43k/9bWnJdQKH0BfylUR+oYCGDn1db VvGyuhDcMVOHYeBZj0N2a7+2Nj4ka/ITcgNS6q5KdCaDujJqPDQjC/naLY0GE93wxtzt uBWW+gVugaRJDIHiTtYMLM32sU2wiU9xaDCcNxyhlWYcdrWqmFrh2DSopopsABSmQiOB qmA22ARKo59WFhVcfGPLutjr/m0Lohhaum8QCdwDd7/Rs7tT2LoQkrArXyqLoZw/dXEG hRVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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:delivered-to; bh=QDVI97M1MbDAEoOSkW/4daMpJaZPT2gcOEAKMc+Rf7E=; b=ZirfxD8vfxvoXHpwaZTCJM9NKaso9Tda8io+AhwN8E3x3pw4NXUbUk95ctt3ZirC79 2oVHiiUUNUqSoyUxl5aRcQ/fyYwBoku9ElvXNSg0i0ox3a0iGd9kmypOh2ULosbHc9Bf qsENCU3/HRxMxf3p1Gp6Eg2BTdDr/2fYbYi8qRxuRluQoAgAEpCtgtZnSslIt5BOS0Ef ZRATiPOn9Eya3zvufvdlcvWuU5CFtTAEULapwZaRx4blaTaPDUHLRicL9DbzrHessfyg b3zRY1pPzeUjB5++Rm3D5LX1fUf54Yr4q417kiBT/NyM7QqT3NZLLZzAGiHC+hMRYlOf AJ/g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j16-20020a50ed10000000b004f0f197861bsi8590031eds.310.2023.04.09.07.10.02; Sun, 09 Apr 2023 07:10:02 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F233968BAEC; Sun, 9 Apr 2023 17:09:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F07E768BBCC for ; Sun, 9 Apr 2023 17:09:17 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A84FB2406CE for ; Sun, 9 Apr 2023 16:09:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id TFvqgfASrpmz for ; Sun, 9 Apr 2023 16:09:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 67FAE2406CF for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 583053A038E for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2023 16:08:38 +0200 Message-Id: <20230409140853.28858-14-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230409140853.28858-1-anton@khirnov.net> References: <20230409140853.28858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TvEeCL0cqLts Current code in print_final_stats(), printing the final summary such as video:8851kB audio:548kB subtitle:0kB other streams:0kB global headers:20kB muxing overhead: 0.559521% was written with a single output file in mind and makes very little sense otherwise. Print this information in mux_final_stats() instead, one line per output file. Use the correct filesize, if available. --- fftools/ffmpeg.c | 37 ++----------------------------------- fftools/ffmpeg_mux.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e1748114b3..0a2dc85629 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -738,43 +738,10 @@ 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; - float percent = -1.0; int i, j; - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - AVCodecParameters *par = ost->st->codecpar; - const uint64_t s = ost->data_size_mux; - - switch (par->codec_type) { - case AVMEDIA_TYPE_VIDEO: video_size += s; break; - case AVMEDIA_TYPE_AUDIO: audio_size += s; break; - case AVMEDIA_TYPE_SUBTITLE: subtitle_size += s; break; - default: other_size += s; break; - } - extra_size += par->extradata_size; - data_size += s; - } - - 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++) { InputFile *f = input_files[i]; @@ -1005,7 +972,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti first_report = 0; if (is_last_report) - print_final_stats(total_size); + print_final_stats(); } int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 441f1cd3a7..01a11117a9 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -641,15 +641,30 @@ static void mux_final_stats(Muxer *mux) { OutputFile *of = &mux->of; uint64_t total_packets = 0, total_size = 0; + uint64_t video_size = 0, audio_size = 0, subtitle_size = 0, + extra_size = 0, other_size = 0; + + uint8_t overhead[16] = "unknown"; + int64_t file_size = of_filesize(of); av_log(of, AV_LOG_VERBOSE, "Output file #%d (%s):\n", of->index, of->url); for (int j = 0; j < of->nb_streams; j++) { OutputStream *ost = of->streams[j]; - enum AVMediaType type = ost->st->codecpar->codec_type; + const AVCodecParameters *par = ost->st->codecpar; + const enum AVMediaType type = par->codec_type; + const uint64_t s = ost->data_size_mux; + + switch (type) { + case AVMEDIA_TYPE_VIDEO: video_size += s; break; + case AVMEDIA_TYPE_AUDIO: audio_size += s; break; + case AVMEDIA_TYPE_SUBTITLE: subtitle_size += s; break; + default: other_size += s; break; + } - total_size += ost->data_size_mux; + extra_size += par->extradata_size; + total_size += s; total_packets += atomic_load(&ost->packets_written); av_log(of, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ", @@ -663,13 +678,28 @@ static void mux_final_stats(Muxer *mux) } av_log(of, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ", - atomic_load(&ost->packets_written), ost->data_size_mux); + atomic_load(&ost->packets_written), s); av_log(of, AV_LOG_VERBOSE, "\n"); } av_log(of, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n", total_packets, total_size); + + if (total_size && file_size > 0 && file_size >= total_size) { + snprintf(overhead, sizeof(overhead), "%f%%", + 100.0 * (file_size - total_size) / total_size); + } + + av_log(of, AV_LOG_INFO, + "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB " + "global headers:%1.0fkB muxing overhead: %s\n", + video_size / 1024.0, + audio_size / 1024.0, + subtitle_size / 1024.0, + other_size / 1024.0, + extra_size / 1024.0, + overhead); } int of_write_trailer(OutputFile *of)