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 7D5F143898 for ; Tue, 2 Aug 2022 11:30:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08E1468BAB1; Tue, 2 Aug 2022 14:30:02 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06DCF68BAAE for ; Tue, 2 Aug 2022 14:29:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2E9D3240179; Tue, 2 Aug 2022 13:29:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rHNgf1RdSWWf; Tue, 2 Aug 2022 13:29:53 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 477F72400F5; Tue, 2 Aug 2022 13:29:53 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id 9C2401601B2; Tue, 2 Aug 2022 13:29:53 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20220802075601.31925-2-haihao.xiang@intel.com> References: <20220802075601.31925-1-haihao.xiang@intel.com> <20220802075601.31925-2-haihao.xiang@intel.com> Mail-Followup-To: FFmpeg development discussions and patches , Haihao Xiang Date: Tue, 02 Aug 2022 13:29:53 +0200 Message-ID: <165943979360.15471.7494839221217612939@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [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 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: Quoting Xiang, Haihao (2022-08-02 09:56:01) > 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; Maybe a verbose-level log message like "Selecting decoder '%s' because of requested hwaccel method %s\n", c->name, av_hwdevice_get_type_name(hwaccel_device_type) would be appropriate. No need to send a new patch, just add it (or not, as you like) and push. -- Anton Khirnov _______________________________________________ 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".