[FFmpeg-cvslog] ffmpeg: add -benchmark_all option.

Nicolas George git at videolan.org
Thu Apr 12 10:07:07 CEST 2012


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Wed Apr 11 19:26:09 2012 +0200| [733cf0ad5165d61afe8257b5c6297242869bf2be] | committer: Nicolas George

ffmpeg: add -benchmark_all option.

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

 Changelog       |    1 +
 doc/ffmpeg.texi |    3 +++
 ffmpeg.c        |   33 ++++++++++++++++++++++++++++++++-
 3 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index f03600b..dbd98bf 100644
--- a/Changelog
+++ b/Changelog
@@ -24,6 +24,7 @@ version next:
 - removelogo filter
 - drop support for ffmpeg without libavfilter
 - drawtext video filter: fontconfig support
+- ffmpeg -benchmark_all option
 
 
 version 0.10:
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 2ed3fae..42445c3 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -716,6 +716,9 @@ Show benchmarking information at the end of an encode.
 Shows CPU time used and maximum memory consumption.
 Maximum memory consumption is not supported on all systems,
 it will usually display as 0 if not supported.
+ at item -benchmark_all (@emph{global})
+Show benchmarking information during the encode.
+Shows CPU time used in various steps (audio/video encode/decode).
 @item -timelimit @var{duration} (@emph{global})
 Exit after ffmpeg has been running for @var{duration} seconds.
 @item -dump (@emph{global})
diff --git a/ffmpeg.c b/ffmpeg.c
index 3990f4f..80135ac 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -133,6 +133,7 @@ static const char *subtitle_codec_name = NULL;
 static int file_overwrite = 0;
 static int no_file_overwrite = 0;
 static int do_benchmark = 0;
+static int do_benchmark_all = 0;
 static int do_hex_dump = 0;
 static int do_pkt_dump = 0;
 static int do_psnr = 0;
@@ -165,6 +166,7 @@ static float dts_error_threshold = 3600*30;
 
 static int print_stats = 1;
 static int debug_ts = 0;
+static int current_time;
 
 static uint8_t *audio_buf;
 static unsigned int allocated_audio_buf_size;
@@ -434,6 +436,23 @@ static int64_t getutime(void)
 #endif
 }
 
+static void update_benchmark(const char *fmt, ...)
+{
+    if (do_benchmark_all) {
+        int64_t t = getutime();
+        va_list va;
+        char buf[1024];
+
+        if (fmt) {
+            va_start(va, fmt);
+            vsnprintf(buf, sizeof(buf), fmt, va);
+            va_end(va);
+            printf("bench: %8"PRIu64" %s \n", t - current_time, buf);
+        }
+        current_time = t;
+    }
+}
+
 static void reset_options(OptionsContext *o, int is_input)
 {
     const OptionDef *po = options;
@@ -1101,10 +1120,12 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
     }
 
     got_packet = 0;
+    update_benchmark(NULL);
     if (avcodec_encode_audio2(enc, &pkt, frame, &got_packet) < 0) {
         av_log(NULL, AV_LOG_FATAL, "Audio encoding failed (avcodec_encode_audio2)\n");
         exit_program(1);
     }
+    update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
 
     ret = pkt.size;
 
@@ -1601,7 +1622,9 @@ static void do_video_out(AVFormatContext *s, OutputStream *ost,
                 big_picture.pict_type = AV_PICTURE_TYPE_I;
                 ost->forced_kf_index++;
             }
+            update_benchmark(NULL);
             ret = avcodec_encode_video2(enc, &pkt, &big_picture, &got_packet);
+            update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
             if (ret < 0) {
                 av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
                 exit_program(1);
@@ -1835,7 +1858,9 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
                 }
                 break;
             case AVMEDIA_TYPE_VIDEO:
+                update_benchmark(NULL);
                 ret = avcodec_encode_video2(enc, &pkt, NULL, &got_packet);
+                update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
                 if (ret < 0) {
                     av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
                     exit_program(1);
@@ -1970,7 +1995,9 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
         avcodec_get_frame_defaults(ist->decoded_frame);
     decoded_frame = ist->decoded_frame;
 
+    update_benchmark(NULL);
     ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt);
+    update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index);
     if (ret < 0) {
         return ret;
     }
@@ -2085,8 +2112,10 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
     pkt->dts  = ist->dts;
     *pkt_pts  = AV_NOPTS_VALUE;
 
+    update_benchmark(NULL);
     ret = avcodec_decode_video2(ist->st->codec,
                                 decoded_frame, got_output, pkt);
+    update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index);
     if (ret < 0)
         return ret;
 
@@ -5068,6 +5097,8 @@ static const OptionDef options[] = {
     { "dframes", HAS_ARG | OPT_FUNC2, {(void*)opt_data_frames}, "set the number of data frames to record", "number" },
     { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
       "add timings for benchmarking" },
+    { "benchmark_all", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark_all},
+      "add timings for each task" },
     { "timelimit", HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" },
     { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump},
       "dump each input packet" },
@@ -5233,7 +5264,7 @@ int main(int argc, char **argv)
         exit_program(1);
     }
 
-    ti = getutime();
+    current_time = ti = getutime();
     if (transcode(output_files, nb_output_files, input_files, nb_input_files) < 0)
         exit_program(1);
     ti = getutime() - ti;



More information about the ffmpeg-cvslog mailing list