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.
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_inputthen 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:
Moreover, if you check what
avcodec_find_encoder_by_name/avcodec_find_encoder_by_namedoes, it is visible that it basically iterates the whole codec list just by applying a filter to distinguish encoders/decoders:The
av_codec_iteratewill iteratre thecodec_listvariable, 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.