Reputation: 2434
I have a project that uses FFmpeg to decode video streams and I want to make use of hardware decoding where available. According to this answer, the use of ff_find_hwaccel
and friends is deprecated in newer FFmpeg builds.
The answer states that ff_find_hwaccel
is deprecated. I want to know how the new method for allocating a hardware accelerated decoder works. Is it done automatically? Can I just pass hwaccel
in an AvDictionary as the third option to avcodec_open2
, or do I have to do something more involved?
Currently the code for allocating an AVCodecContext
looks like this:
auto video_codec = avcodec_find_decoder(codec_id);
auto context = avcodec_alloc_context3(video_codec);
auto retcode = avcodec_open2(context, video_codec, nullptr);
with error checking, of course.
I then push AVPackets into the decoder using avcodec_decode_video2
.
Upvotes: 3
Views: 11932
Reputation: 263
In current versions of FFMPEG hardware acceleration is supported automatically if available. That is also why ff_find_hwaccel
is deprecated.
Depending on platform and video codec used you might or might not have hardware acceleration support for video decoding. For example hardware accelerated decoding of H264 video has been supported on Nvidia graphics cards for quite a while now using the H264_NVDEC decoder, but HEVC decoding requires a graphics card that is a fair bit newer. For AMD graphics cards it's the same story, except that you would normally use the DXVA2 decoder as mentioned here.
I short: if your platform supports hardware acceleration it should be used automatically by FFMPEG. You could also do additional tests by forcing a decoder.
Upvotes: 2