ffmpeg: AMD & NVIDIA hardware video encoding (h264, h265)

ffmpeg: AMD & NVIDIA hardware video encoding (h264, h265)

I recently needed to export some video from an Enterprise Video Surveillance system. The system will only export mjpeg avi videos, which are huge files. I ended up using ffmpeg to encode these videos into h.264 mp4 files. I performed the video encoding on a machine with an AMD GPU. This article documents some of the ffmpeg command line switches require to perform hardware video encoding on both NVIDIA and AMD GPUs.

Encode AVI to h.264 Video (Software Encoding)

ffmpeg -i input.avi -c:v libx264 output.mp4

Encode AVI to h.265 Video (Software Encoding)

ffmpeg -i input.avi -c:v libx265 output.mp4

Encode AVI to h.264 Video (AMD GPU Encoding)

ffmpeg -i input.avi -c:v h264_amf output.mp4

Encode AVI to h.265 Video (AMD GPU Encoding)

ffmpeg -i input.avi -c:v hevc_amf output.mp4

Encode AVI to h.264 Video (NVIDIA GPU Encoding)

ffmpeg -i input.avi -c:v h264_nvenc output.mp4

Encode AVI to h.265 Video (NVIDIA GPU Encoding)

ffmpeg -i input.avi -c:v hevc_nvenc output.mp4

11 Replies to “ffmpeg: AMD & NVIDIA hardware video encoding (h264, h265)”

      1. Awesome, thank you for this page. I’m trying out hevc encoding and decoding now using a AMD GPU Radeon RX580

  1. Hi, thanks for the clean and simply laid out article and commands. When using the h264_amf parameter, I get the following error message:

    “DLL amfrt64.dll failed to open
    Error initializing output stream 0:0 – Error while opening encoder for output stream #0:0 – maybe incorrect parameters such as bit_rate, rate, width or height”.

    I’ve got an AMD Radeon HD 5770 card with the latest updated drivers on Windows 10 Build 1909 x64 and my video output from this GPU is just fine. Could you please help? Thanks in advance.

    1. Same issue here. I’ve updated my FFMPEG to the latest but to no avail.
      The full message is:

      [h264_amf @ 000002ba8e5feb40] DLL amfrt64.dll failed to open
      Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 – maybe incorrect parameters such as bit_rate, rate, width or height

  2. how do you pass those to youtube-dl ?

    youtube-dl –sub-lang en –write-auto-sub –embed-subs –ffmpeg-location ./ –postprocessor-args ‘-c:v h264_amf’ ‘https://www.youtube.com/watch?v=k8RyV3VEDKI’

    throws an encoder error

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.