diff mbox

[FFmpeg-devel] ffmpeg.c: allow ffmpeg to output stats for each video stream

Message ID 20180615053731.161792-1-wangcao@google.com
State Superseded
Headers show

Commit Message

Wang Cao June 15, 2018, 5:37 a.m. UTC
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 <wangcao@google.com>
---
 fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

Comments

Moritz Barsnick June 15, 2018, 5:19 p.m. UTC | #1
On Fri, Jun 15, 2018 at 13:37:31 +0800, Wang Cao wrote:

> 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.

(This needs some cleaing up of the grammar, but that's beside the point
right now.)

Somehow, this changes the stats while running. I no longer see the
overall stats. If I map video first, I see only the video stats, but it
seems like the audio stats flicker through. If I map audio first, I see
a duplicated line (extended), which shows video and audio stat lines
side by side.

I don't think this is what you intended. You only wanted to show the
*final* stats differently, correct? If it is intended, I'd like to
point out that the status line does not have enough space on most
screens to hold twice or more of its current content. I would still
like to see overall stats, also at the end, because it says something
about e.g. the total size. In the summary report, per file and per
stream stats may be nice though.

Moritz
Wang Cao June 20, 2018, 9:09 a.m. UTC | #2
For example: with (-psnr)
frame=  450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats)
size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=10.6x (audio stats)

If there are multiple files, stats of the second output would be concatenated
after the first one. Is this a acceptable behavior?
Wang Cao June 20, 2018, 9:25 a.m. UTC | #3
For example: with (-psnr)
frame=  450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats)
size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=10.6x (audio stats)

frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=3.74x
size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
Michael Niedermayer June 21, 2018, 4:08 p.m. UTC | #4
On Fri, Jun 15, 2018 at 01:37:31PM +0800, Wang Cao wrote:
> 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 <wangcao@google.com>
> ---
>  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()
>  {

there are some new warnings:

fftools/ffmpeg.c:1533:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 static void print_final_stats()
             ^
fftools/ffmpeg.c: In function ‘print_report’:
fftools/ffmpeg.c:1672:22: warning: unused variable ‘oc’ [-Wunused-variable]
     AVFormatContext *oc;
                      ^
[...]
Michael Niedermayer June 21, 2018, 4:10 p.m. UTC | #5
On Wed, Jun 20, 2018 at 05:25:32PM +0800, Wang Cao wrote:
> For example: with (-psnr)
> frame=  450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats)
> size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=10.6x (audio stats)
> 
> frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.01 bitrate= 210.0kbits/s speed=3.74x
> size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
> q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
> size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
> q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size=     385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
> size=     107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
> video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
> video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%
> video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.880871%

how does the user know which is which output ?

also some users may want just one line summarizing all

[...]
Gyan June 21, 2018, 4:13 p.m. UTC | #6
On 21-06-2018 09:40 PM, Michael Niedermayer wrote:

> how does the user know which is which output ?
> 
> also some users may want just one line summarizing all

Agreed. Better if each line is identified.

Regards,
Gyan
Wang Cao June 22, 2018, 8:03 a.m. UTC | #7
Thanks for pointing this out. I have modified the code according to your
comments.
diff mbox

Patch

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)