> -----Original Message----- > From: Guo, Yejun <yejun....@intel.com> > Sent: 2020年10月15日 16:43 > To: ffmpeg-devel@ffmpeg.org > Cc: Guo, Yejun <yejun....@intel.com> > Subject: [PATCH] fftools/ffmpeg: add option fps_skip_frames > > When dnn based filter is used with GPU as the underlying hardware, it is > expected that the first model inference will be very slow due to the heavy > workload in dnn framework (especially in compiler). > Such 'loading' time are usually not added into FPS in graphics games, so, > also add > option fps_skip_frames to skip some frames in the beginning when calculate > FPS. > > Signed-off-by: Guo, Yejun <yejun....@intel.com> > --- > fftools/ffmpeg.c | 30 +++++++++++++++++++++++------- > fftools/ffmpeg.h | 1 + > fftools/ffmpeg_opt.c | 3 +++ > 3 files changed, 27 insertions(+), 7 deletions(-) > > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 84306818a2..ee096f6748 > 100644 > --- a/fftools/ffmpeg.c > +++ b/fftools/ffmpeg.c > @@ -1644,6 +1644,7 @@ static void print_report(int is_last_report, int64_t > timer_start, int64_t cur_ti > double speed; > int64_t pts = INT64_MIN + 1; > static int64_t last_time = -1; > + static int64_t fps_skip_timer_start = -1; > static int qp_histogram[52]; > int hours, mins, secs, us; > const char *hours_sign; > @@ -1691,13 +1692,28 @@ static void print_report(int is_last_report, int64_t > timer_start, int64_t cur_ti > float fps; > > frame_number = ost->frame_number; > - fps = t > 1 ? frame_number / t : 0; > - av_bprintf(&buf, "frame=%5d fps=%3.*f q=%3.1f ", > - frame_number, fps < 9.95, fps, q); > - av_bprintf(&buf_script, "frame=%d\n", frame_number); > - av_bprintf(&buf_script, "fps=%.2f\n", fps); > - av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", > - ost->file_index, ost->index, q); > + if (fps_skip_frames < 0) > + fps_skip_frames = 0; > + if (frame_number <= fps_skip_frames) { > + fps_skip_timer_start = cur_time; > + } else if (fps_skip_frames > 0 && fps_skip_timer_start == -1) { > + av_log(NULL, AV_LOG_WARNING, "The first %d frames run > very quickly, " > + "so skip these frames > to calculate FPS\n", frame_number); > + fps_skip_timer_start = cur_time; > + fps_skip_frames = frame_number; > + } else { > + fps = t > 1 ? frame_number / t : 0; > + if (fps_skip_frames > 0) { > + float newt = (cur_time - fps_skip_timer_start) / > 1000000.0; > + fps = newt > 1 ? (frame_number - fps_skip_frames) * > 1.0f / newt : 0; > + } > + av_bprintf(&buf, "frame=%5d fps=%3.*f q=%3.1f ", > + frame_number, fps < 9.95, fps, q); > + av_bprintf(&buf_script, "frame=%d\n", frame_number); > + av_bprintf(&buf_script, "fps=%.2f\n", fps); > + av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", > + ost->file_index, ost->index, q); > + } > if (is_last_report) > av_bprintf(&buf, "L"); > if (qp_hist) { > diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8665218dcf..af35dd5429 > 100644 > --- a/fftools/ffmpeg.h > +++ b/fftools/ffmpeg.h > @@ -609,6 +609,7 @@ extern int frame_bits_per_raw_sample; extern > AVIOContext *progress_avio; extern float max_error_rate; extern char > *videotoolbox_pixfmt; > +extern int fps_skip_frames; > > extern int filter_nbthreads; > extern int filter_complex_nbthreads; > diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index > 19f719e3ff..cfe2b7f8ba 100644 > --- a/fftools/ffmpeg_opt.c > +++ b/fftools/ffmpeg_opt.c > @@ -173,6 +173,7 @@ int filter_nbthreads = 0; int filter_complex_nbthreads > = 0; int vstats_version = 2; int auto_conversion_filters = 1; > +int fps_skip_frames = 0; > > > static int intra_only = 0; > @@ -3674,6 +3675,8 @@ const OptionDef options[] = { > { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC | > OPT_EXPERT | OPT_OUTPUT, > { .off = OFFSET(autoscale) }, > "automatically insert a scale filter at the end of the filter graph" > }, > + { "fps_skip_frames", OPT_INT | HAS_ARG | OPT_EXPERT, > { &fps_skip_frames }, > + "the number of frames skipped at beginning when calculate > + FPS"}, > > /* audio options */ > { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | > OPT_OUTPUT, { .func_arg = opt_audio_frames }, > -- > 2.17.1
this patch asks for review, thanks. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".