ffmpeghardware-acceleration

How to check ffmpeg hardware acceleration status


Several questions regarding hardware acceleration with ffmpeg (which I think is NOT same question as this one):

  1. How can I tell if my version of ffmpeg support hardware acceleration or not, and what are the acceleration features it support?

  2. From the output of an transcoding process, can I tell if ffmpeg is using hardware acceleration or not?

  3. I am using ffmpeg to pull H265 video from camera, and convert it to H264 HLS chunks. The problem now is the transcoding process is too CPU intensive. I hope to use hardware acceleration. Due to the application, I cannot use expensive GPUs such as NVidia cuda platform. If using only Intel HD graphics comes with CPU, can I significantly lower CPU usage when transcoding H265 => H264? What is the estimated performance gain in %?

Thanks.


Solution

  • If your CPU support for example Intel Quick Sync than you can significantly reduce the CPU load using hardware acceleration (in my test case below it was from 90% using libx264 to 20% using h264_qsv). And after enabling the hardware accelerated decoding it reduced the CPU load from 20% to 4%. So in summary from 90% to 4%. But the load depends also on other things like bitrate, resolution and CPU/hardware.

    Encoding

    First of all you need to know, what encoders have been enabled in your FFmpeg version. To check this you can simply execute

    ffmpeg -codecs
    

    In this this you should find your target codec (h264):

    [...]
    DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_qsv h264_cuvid ) (encoders: libx264 libx264rgb h264_amf h264_mf h264_nvenc h264_qsv )
    [...]
    

    Take your attention on the "encoders". Some are software-, some are hardware-encoders. This list is dependent to your OS and the enabled encoders during FFmpeg compilation. To get a short description of each encoder you can execute:

    ffmpeg -encoders
    [...]
     V....D libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
     V....D libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
     V....D h264_amf             AMD AMF H.264 Encoder (codec h264)
     V....D h264_mf              H264 via MediaFoundation (codec h264)
     V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
     V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
    [...]
    

    Note: not all encoders might actually work. E.g. if you have no NVIDIA graphics card the h264_nvenc will not work.

    Here on my Windows machine I will choose the "h264_qsv" (Intel Quick Sync Video acceleration) encoder. On macOS you want to use "h264_videotoolbox":

    ffmpeg -i mysource -c:v h264_qsv -c:a copy output.mp4
    

    Pay attention on the output quality: libx264 might have a better quality by default than a hardware accelerated encoder. So make sure that you finetune the encoding using e.g. a defined bitrate (-b:v 6M for 6MBit).

    This encodes the input using the h264 encoder of Intel Quick Sync (because of the -c:v option). Please find more details on https://trac.ffmpeg.org/wiki/HWAccelIntro

    Decoding

    Using the option "-hwaccel auto" before the inputs (-i) tries to use hardware accelerated decoding as well:

    ffmpeg -hwaccel auto -i mysource .....
    

    If a hardware decoder is available it is automatically used. If not then FFmpeg falls back to the software decoder. Check the console output to see what happens:

    [hevc @ 00000176c91d0fc0] Using auto hwaccel type dxva2 with new default device.