From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>
To: "ffmpeg-devel@ffmpeg.org" <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder
Date: Fri, 29 Jul 2022 08:37:53 +0000
Message-ID: <a8d415d02e52d1da7593c523792c9d771f920ad4.camel@intel.com> (raw)
In-Reply-To: <20220725043051.9692-2-haihao.xiang@intel.com>
On Mon, 2022-07-25 at 12:30 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
>
> 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 <marioeroy@gmail.com>
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
> fftools/ffmpeg_opt.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 2771c5d993..614bfeea80 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -861,6 +861,48 @@ static const AVCodec *choose_decoder(OptionsContext *o,
> AVFormatContext *s, AVSt
> return avcodec_find_decoder(st->codecpar->codec_id);
> }
>
> +static const AVCodec *choose_decoder2(InputStream *ist, OptionsContext *o,
> AVFormatContext *s, AVStream *st)
> +{
> + char *codec_name = NULL;
> +
> + MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
> + if (codec_name) {
> + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar-
> >codec_type, 0);
> + st->codecpar->codec_id = codec->id;
> + if (recast_media && st->codecpar->codec_type != codec->type)
> + st->codecpar->codec_type = codec->type;
> + return codec;
> + } else {
> + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
> + ist->hwaccel_id == HWACCEL_GENERIC &&
> + ist->hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
> + const AVCodec *p;
> + void *i = 0;
> +
> + while ((p = av_codec_iterate(&i))) {
> + int j;
> +
> + if (p->id != st->codecpar->codec_id ||
> + !av_codec_is_decoder(p) ||
> + !avcodec_get_hw_config(p, 0))
> + continue;
> +
> + for (j = 0; ;j++) {
> + const AVCodecHWConfig *config = avcodec_get_hw_config(p,
> j);
> +
> + if (!config)
> + break;
> +
> + if (config->device_type == ist->hwaccel_device_type)
> + return p;
> + }
> + }
> + }
> +
> + return avcodec_find_decoder(st->codecpar->codec_id);
> + }
> +}
> +
> /* Add all the streams from the given input file to the global
> * list of input streams. */
> static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
> @@ -973,7 +1015,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_decoder2(ist, o, ic, st);
> ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st-
> >codecpar->codec_id, ic, st, ist->dec);
>
> ist->reinit_filters = -1;
Hi,
libdav1d is the preferred AV1 decoder in FFmpeg, libdav1d is always used when
running the command below even if user expects vaapi or other HW acceleration
methods.
$ ffmpeg -hwaccel vaapi -i av1.ivf -f null -
A similar command works as expected for other codecs, e.g. GPU is used when
running the command below (see
http://ffmpeg.org/pipermail/ffmpeg-user/2022-July/055227.html)
$ ffmpeg -y -hwaccel vdpau -i input_vp9.webm output.ts
This patchset can ensure FFmpeg chooses a HW accelerated decoder when '-hwaccel
arg' is specified in the command line.
Is there any comment for this patchset ?
Thanks
Haihao
_______________________________________________
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".
next prev parent reply other threads:[~2022-07-29 8:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 4:30 [FFmpeg-devel] [PATCH v3 1/2] ffmpeg_opt: select a decoder after getting values for per-stream hwdec options Xiang, Haihao
2022-07-25 4:30 ` [FFmpeg-devel] [PATCH v3 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder Xiang, Haihao
2022-07-29 8:37 ` Xiang, Haihao [this message]
2022-07-29 8:50 ` Ronald S. Bultje
2022-07-29 9:46 ` Soft Works
2022-08-01 1:52 ` Xiang, Haihao
2022-08-01 2:14 ` Soft Works
2022-08-01 2:37 ` Xiang, Haihao
2022-08-01 9:12 ` Anton Khirnov
2022-08-02 7:57 ` Xiang, Haihao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8d415d02e52d1da7593c523792c9d771f920ad4.camel@intel.com \
--to=haihao.xiang-at-intel.com@ffmpeg.org \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git