
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)”
Just a typo on the hevc commands.
corrected, thank you.
Awesome, thank you for this page. I’m trying out hevc encoding and decoding now using a AMD GPU Radeon RX580
How to use hardware encoding in OBS. I have MSI R9 270X graphic card. Thanks
You’re still using software CPU to decode the input file. You can accellerate this too.
https://devblogs.nvidia.com/nvidia-ffmpeg-transcoding-guide/
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.
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
oops, failed to mention video card, 1050Ti.
For Nvidia cards you gotta use h264_nvenc not h264_amf.
it works ;-) … 5x faster than SW encoding :-) thank you!
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