From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9F7654088B for ; Tue, 2 Aug 2022 07:56:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CAAD768BA55; Tue, 2 Aug 2022 10:56:28 +0300 (EEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7B1668B71B for ; Tue, 2 Aug 2022 10:56:21 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659426987; x=1690962987; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=z8ckmGnItsD7APqktrHbgRAb+B56Jgzq8x1IPXtiJhM=; b=XVkR0Zillv1RC3RfJDpWuqXi9HYUskiNyA6nOyV5d0rJsryf0PK4aYh0 SPJsFhk35ycaiSEmrLN8gWYY827Y+v+vjKbjF+7YYGZwxUkMtnhiz+0fs yAlu+X6F++ZefFqEY8K8lSz/Zf+DrwKdqYQKqjsr5UEkKmuYoQZro+GWm 0VIdw0zKP7t1l+Tlz0VTuEVdeXK/uzSAMDRLgTUaikgDsgReY6Lz69Ag8 jl1dL8xcY2vOt/8TEejALkaS4gtkTi5NV4I9X/8bDM2IkvA4H4q3UbDi8 n44ZCL8E9Pp2ZOPFQ4sUFJ8YONkcepCwMuWx7zyWkChsSjY2MuyGHkktx A==; X-IronPort-AV: E=McAfee;i="6400,9594,10426"; a="290563062" X-IronPort-AV: E=Sophos;i="5.93,210,1654585200"; d="scan'208";a="290563062" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2022 00:56:14 -0700 X-IronPort-AV: E=Sophos;i="5.93,210,1654585200"; d="scan'208";a="929873798" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2022 00:56:13 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Aug 2022 15:56:01 +0800 Message-Id: <20220802075601.31925-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220802075601.31925-1-haihao.xiang@intel.com> References: <20220802075601.31925-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v4 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Haihao Xiang MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Haihao Xiang Usually a HW decoder is expected when user specifies a HW acceleration method via -hwaccel option, however the current implementation doesn't take HW acceleration method into account, it is possible to select a SW decoder. For example: $ ffmpeg -hwaccel vaapi -i av1.mp4 -f null - $ ffmpeg -hwaccel nvdec -i av1.mp4 -f null - $ ffmpeg -hwaccel vdpau -i av1.mp4 -f null - [...] Stream #0:0 -> #0:0 (av1 (libdav1d) -> wrapped_avframe (native)) libdav1d is selected in this case even if vaapi, nvdec or vdpau is specified. After applying this patch, the native av1 decoder (with vaapi, nvdec or vdpau support) is selected for decoding(libdav1d is still used for probing format). $ ffmpeg -hwaccel vaapi -i av1.mp4 -f null - $ ffmpeg -hwaccel nvdec -i av1.mp4 -f null - $ ffmpeg -hwaccel vdpau -i av1.mp4 -f null - [...] Stream #0:0 -> #0:0 (av1 (native) -> wrapped_avframe (native)) Tested-by: Mario Roy Signed-off-by: Haihao Xiang --- fftools/ffmpeg_opt.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index cf0c31bdc2..db51cca66d 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -857,7 +857,9 @@ static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, return codec; } -static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st) +static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st, + enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) + { char *codec_name = NULL; @@ -868,8 +870,29 @@ static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVSt if (recast_media && st->codecpar->codec_type != codec->type) st->codecpar->codec_type = codec->type; return codec; - } else + } else { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + hwaccel_id == HWACCEL_GENERIC && + hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) { + const AVCodec *c; + void *i = NULL; + + while ((c = av_codec_iterate(&i))) { + const AVCodecHWConfig *config; + + if (c->id != st->codecpar->codec_id || + !av_codec_is_decoder(c)) + continue; + + for (int j = 0; config = avcodec_get_hw_config(c, j); j++) { + if (config->device_type == hwaccel_device_type) + return c; + } + } + } + return avcodec_find_decoder(st->codecpar->codec_id); + } } static int guess_input_channel_layout(InputStream *ist) @@ -1003,7 +1026,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; } - ist->dec = choose_decoder(o, ic, st); + ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type); ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); ist->reinit_filters = -1; @@ -1309,7 +1332,7 @@ static int open_input_file(OptionsContext *o, const char *filename) /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) - choose_decoder(o, ic, ic->streams[i]); + choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE); if (find_stream_info) { AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".