From patchwork Thu Oct 15 08:43:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 22963 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 68A4244B739 for ; Thu, 15 Oct 2020 11:44:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 485FD68B967; Thu, 15 Oct 2020 11:44:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 34FC568B77C for ; Thu, 15 Oct 2020 11:43:52 +0300 (EEST) IronPort-SDR: 3cxyQwjbY076dG2wlDe2DwPh7omHWQfToL+70nG2rbRsMtwgvVC9h/n/rrSHKjJnuVkAgenppN QxYee+orBFBQ== X-IronPort-AV: E=McAfee;i="6000,8403,9774"; a="153229742" X-IronPort-AV: E=Sophos;i="5.77,378,1596524400"; d="scan'208";a="153229742" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2020 01:43:50 -0700 IronPort-SDR: dH4BAT12ZrvLOQF/UAwGsXO0AG/axmMwbwtGsi0MqFIvoOIsCvAmHdPiz3q37cbCxTkMEplkSE zgllh736jKyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,378,1596524400"; d="scan'208";a="346008450" Received: from yguo18-skl-u1604.sh.intel.com (HELO yguo18-skl-u1804.sh.intel.com) ([10.239.159.53]) by fmsmga004.fm.intel.com with ESMTP; 15 Oct 2020 01:43:37 -0700 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:43:15 +0800 Message-Id: <20201015084315.21587-1-yejun.guo@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: add option fps_skip_frames X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: yejun.guo@intel.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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 },