[FFmpeg-cvslog] fftools/ffmpeg: rewrite printing the final output sizes

Anton Khirnov git at videolan.org
Thu Apr 13 16:42:13 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Mar 28 11:13:32 2023 +0200| [37b118096ae278f8123bc918a283e7ff6f0611a9] | committer: Anton Khirnov

fftools/ffmpeg: rewrite printing the final output sizes

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=37b118096ae278f8123bc918a283e7ff6f0611a9
---

 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)



More information about the ffmpeg-cvslog mailing list