From patchwork Fri Nov 1 02:40:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 16053 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 E3D7D447521 for ; Fri, 1 Nov 2019 04:47:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B52F368AF0F; Fri, 1 Nov 2019 04:47:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8926268AF0F for ; Fri, 1 Nov 2019 04:47:09 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2019 19:47:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,253,1569308400"; d="scan'208";a="351839713" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by orsmga004.jf.intel.com with ESMTP; 31 Oct 2019 19:47:06 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Nov 2019 10:40:45 +0800 Message-Id: <1572576045-5252-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] lavc/qsv: improve the default GPU memory usage 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: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" A large initial_pool_size leads to redundant GPU memory allocations compared with MSDK. For some special cases which needs larger GPU memory like look_ahead, add -extra_hw_frames to allocate more. CMD: ffmpeg -hwaccel qsv -extra_hw_frames 50 -c:v hevc_qsv -i hevc.h265 -c:v h264_qsv -look_ahead 1 -look_ahead_depth 50 -y output.h264 Fix #7943. Reported-by: Eero T Signed-off-by: Linjie Fu --- fftools/ffmpeg_qsv.c | 2 +- libavcodec/qsvdec.c | 5 ++++- libavcodec/qsvenc_h264.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg_qsv.c b/fftools/ffmpeg_qsv.c index 9c4285b..5039a5a 100644 --- a/fftools/ffmpeg_qsv.c +++ b/fftools/ffmpeg_qsv.c @@ -93,7 +93,7 @@ int qsv_init(AVCodecContext *s) frames_ctx->height = FFALIGN(s->coded_height, 32); frames_ctx->format = AV_PIX_FMT_QSV; frames_ctx->sw_format = s->sw_pix_fmt; - frames_ctx->initial_pool_size = 64 + s->extra_hw_frames; + frames_ctx->initial_pool_size = 24 + s->extra_hw_frames; frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; ret = av_hwframe_ctx_init(ist->hw_frames_ctx); diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 0d34021..407e6de 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -300,8 +300,11 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame) else ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF); - if (ret < 0) + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "More memory in need, " + "try -extra_hw_frames to allocate more.\n"); return ret; + } if (frame->frame->format == AV_PIX_FMT_QSV) { frame->surface = *(mfxFrameSurface1*)frame->frame->data[3]; diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c index 27f36b9..4e8035b 100644 --- a/libavcodec/qsvenc_h264.c +++ b/libavcodec/qsvenc_h264.c @@ -112,8 +112,8 @@ static const AVOption options[] = { { "max_dec_frame_buffering", "Maximum number of frames buffered in the DPB", OFFSET(qsv.max_dec_frame_buffering), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, #if QSV_HAVE_LA - { "look_ahead", "Use VBR algorithm with look ahead", OFFSET(qsv.look_ahead), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, - { "look_ahead_depth", "Depth of look ahead in number frames", OFFSET(qsv.look_ahead_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, VE }, + { "look_ahead", "Use VBR algorithm with look ahead, extra_hw_frames is needed", OFFSET(qsv.look_ahead), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "look_ahead_depth", "Depth of look ahead in number frames, extra_hw_frames is needed", OFFSET(qsv.look_ahead_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, VE }, #endif #if QSV_HAVE_LA_DS { "look_ahead_downsampling", "Downscaling factor for the frames saved for the lookahead analysis", OFFSET(qsv.look_ahead_downsampling),