Hardware encoding ffmpeg NVENC - WORKING !!!

If you have a suggestion for a feature, post it here
Post Reply
bighead
Posts: 2
Joined: Fri Apr 17, 2020 11:01 pm

Hardware encoding ffmpeg NVENC - WORKING !!!

Post by bighead »

Nvidia graphics cards from Kepler family can hardware encode H.264 YUV 4:2:0 - https://developer.nvidia.com/video-enco ... ort-matrix
FFmpeg has support for this - https://devblogs.nvidia.com/nvidia-ffmp ... ing-guide/

I have tested a lot of variants but only hardware decoding is working.
From commnad line ffmpeg (version from UMS 9.4.1) is able to decode and encode without problem (ffmpeg -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4)
The problem in UMS is that one parameter is hardcoded for ffmpeg and cant be changed -pix_fmt yuv420p, the encoder h264_nvenc not support this parameter.
Parameters -preset ultrafast -level 31 arent supported too, but i have change they in CustomFFmpegOptions = -pix_fmt cuda -c:v h264_nvenc -zerolatency 1 -preset slow -level 41 -f matroska
Unfortunately -pix_fmt cuda is not working, the -pix_fmt yuv420p is still in parameters when transcoding is starting.

Can you add support for hardware encoding with Nvidia cards?
Last edited by bighead on Mon Apr 20, 2020 12:10 am, edited 1 time in total.
bighead
Posts: 2
Joined: Fri Apr 17, 2020 11:01 pm

Re: Hardware encoding ffmpeg NVENC

Post by bighead »

After a week of reading and tests i got finally working decode and encode with my Nvidia Quadro K2000 :-D.

When i using acceleration method -hwaccel cuvid or -hwaccel cuda the hardcoded parameter -pix_fmt yuv420p give always an error.
Hwaccel cuvid is deprecated and FFmpeg give a hint to use -hwaccel_output_format cuda and that i the solution for -pix_fmt yuv420p

To get fully working hardware transcoding you must do 2 steps:
  • 1 step
In GUI in acceleration method change auto to -hwaccel_output_format cuda -c:v h264_cuvid
DEBUG 2020-04-18 15:42:30.405 [main] Reading ffmpeg_available_gpu_acceleration_methods: "none,auto,cuda,dxva2,qsv,d3d11va" (default: "none")
DEBUG 2020-04-18 15:42:30.409 [main] Reading ffmpeg_gpu_decoding_acceleration_method: "-hwaccel_output_format cuda -c:v h264_cuvid" (default: "none")
  • 2 step
Put in the renderer file this line:
CustomFFmpegOptions = -c:v h264_nvenc -b:v 20M -zerolatency 1 -preset slow -level 41 -f matroska

0-04-18 19:54:33.546 [ffmpeg64.exe-48] Starting "C:\Program Files (x86)\Universal Media Server\win32\ffmpeg64.exe" -y -loglevel fatal -hwaccel_output_format cuda -c:v h264_cuvid -threads 1 -i N:\test.mkv -filter_complex subtitles=N\\:/test.srt:charenc=WINDOWS-1250:force_style=',Fontsize=21.0,PrimaryColour=&H000099FF,Outline=1,Shadow=1,MarginV=10' -bufsize 31250k -maxrate 31250k -crf 19 -ab 640k -c:a ac3 -pix_fmt yuv420p -c:v h264_nvenc -b:v 20M -zerolatency 1 -preset slow -level 41 -f matroska \\.\pipe\ffmpegvideo_5068_1587232473232
DEBUG 2020-04-18 19:54:33.546 [ffmpeg64.exe-48] Reading pipe: \\.\pipe\ffmpegvideo_5068_1587232473232
DEBUG 2020-04-18 19:54:33.561 [ffmpeg64.exe-48] Attaching thread: ffmpeg64.exe-48
DEBUG 2020-04-18 19:54:33.671 [Thread-170] Result of \\.\pipe\ffmpegvideo_5068_1587232473232: true
DEBUG 2020-04-18 19:54:34.841 [UPNP-AliveMessageSender] Sending ALIVE...
INFO 2020-04-18 19:54:36.247 [StartPlaying Event] Started playing test.mkv on your [TV][LG]47LA691S
masterjp
Posts: 1
Joined: Fri Jul 10, 2020 5:37 am

Re: Hardware encoding ffmpeg NVENC - WORKING !!!

Post by masterjp »

Thank you for your post about hardware encoding with nvidia cards.

I am using a Geforce GTX 1060 and tried your steps, but I does not correctly work for me.
My UMS Version is the latest version 9.7.1.

I can insert your parameters for gui "-hwaccel_output_format cuda -c:v h264_cuvid!" in the box,
but UMS does not save it! I tried to insert in the ums.config file. Nothing changed.

The customFFMPEGOptions I wrote in the renderer file. For a short moment I see a GPU usage (Windows 10 - taskmanager) during encoding, but it does not work.
My TV does not support the file.

Which other settings do you use or do you have a special ffmpeg encoder file? Thank you for your help.

In Status window of UMS I see the used ffmpeg parameter, but UMS ignore my CustomFFMPEgOptions.
Post Reply