Reputation: 31
I am using AVCodec as a video stream decoder and would like to know if it was possible to use hardware acceleration with hwaccel via FFMPEG? or is it already used by default? I have already listed codecs available but I do not understand how to implement them in my code.
AVHWAccel* pHwaccel = NULL;
pHwaccel = av_hwaccel_next(NULL);
while(pHwaccel!=NULL)
{
TkCore::Logger::info("%s", pHwaccel->name);
pHwaccel = av_hwaccel_next(pHwaccel);
}
i obtain : h264_qsv, h264_vaapi,h264_vdpaufor h264.
I saw that the command :
AVHWAccel * ff_find_hwaccel (codecID enum codec_id, enum PixelFormat pix_fmt)
been obsolete.
Thank you in advance for your help.
Upvotes: 2
Views: 3824
Reputation: 11954
See this thread on libav-user. Basically after listing the hw accelerated codecs you can try to lookup the appropriate decoder with avcodec_find_decoder_by_name (since the AVHWAccel struct has the name field) and then use that for decoding. But then you need to know the codec upfront. If you use avformat_open_input
then you may simply try to find a matching hw accelerated decoder by the codec id from the stream info, then open the hw accelerated codec by name and use that.
Update, since I got downvoted
To provide a working example of this, I have an ffmpeg installation from homebrew, that lists videotoolbox (which is a HW accelerated codec) via ffmpeg -encoders | grep h264
:
V..... h264_videotoolbox VideoToolbox H.264 Encoder (codec h264)
And the following snippet also finds it:
extern "C"
{
#include <libavcodec/avcodec.h>
}
int main(int argc, char** argv)
{
auto *codec = avcodec_find_encoder_by_name("h264_videotoolbox");
if (codec)
{
return 0;
}
return 1;
}
Moreover, if you check what avcodec_find_encoder_by_name
/avcodec_find_encoder_by_name
does, it is visible that it basically iterates the whole codec list just by applying a filter to distinguish encoders/decoders:
static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
{
void *i = 0;
const AVCodec *p;
if (!name)
return NULL;
while ((p = av_codec_iterate(&i))) {
if (!x(p))
continue;
if (strcmp(name, p->name) == 0)
return (AVCodec*)p;
}
return NULL;
}
AVCodec *avcodec_find_encoder_by_name(const char *name)
{
return find_codec_by_name(name, av_codec_is_encoder);
}
AVCodec *avcodec_find_decoder_by_name(const char *name)
{
return find_codec_by_name(name, av_codec_is_decoder);
}
The av_codec_iterate
will iteratre the codec_list
variable, which is a pregenerated list of supported codecs (populated by the features enabled when configuring the build). So if any hw accelerated codecs were enable during configuration, they will be there.
Upvotes: 0
Reputation: 31
I realized the call of the decoder with "avcodec_find_encoder" but I do not see how to apply hardware acceleration to this decoded frame ... I have seen that pix_fmt was able to assign material acceleration, for example if pix_fmt = This is exactly as it was in h264. The only question is what function is used to apply this vdpau acceleration ...
Upvotes: 0