HEVC 10bit encoding with NVENC

Questions involving a Windows version of FFmpeg.
ryuchayu
Posts: 3
Joined: Sun Jul 31, 2016 9:15 pm

HEVC 10bit encoding with NVENC

Post by ryuchayu » Sun Jul 31, 2016 9:21 pm

Hello.
I bought new pascal graphics card(gtx1070) a few days ago.
I know new pascal gpu can encode HEVC 10bit with NVENC.
(https://developer.nvidia.com/nvidia-video-codec-sdk)

But I don't know how to use this function with ffmpeg.
Please help me.
Sorry for my bad english.
Thank you.

oviano
Posts: 16
Joined: Sat May 14, 2016 9:15 am

Re: HEVC 10bit encoding with NVENC

Post by oviano » Tue Aug 16, 2016 5:11 pm

I'm interested in this too.

With x265 in ffmpeg you can encode with 10 bits by specifying a 10 bit pixel format. For example:

-pix_fmt yuv420p10le

Perhaps the same would work for nvenc and the request for a 10 bit encode would be passed to the GPU without needing the new SDK?

If not, then ffmpeg would need building with SDK 7.0. I don't think this is any more complicated than using the 7.0 header file when building ffmpeg as that is all it does for 6.0. If you want to build it yourself then google "ffmpeg windows build helper script". I might be able to help if you run into troubles with that.

Worse-case scenario is that some ffmpeg code needs changing somewhere to support 10 bit NVENC encodes, in which case it would need suggesting on the ffmpeg developer mailing list.

It all depends on how the nvenc API is used by ffmpeg.

DanSherman
Posts: 5
Joined: Wed Aug 03, 2016 5:08 am

Re: HEVC 10bit encoding with NVENC

Post by DanSherman » Wed Aug 17, 2016 1:59 am

I have a 1070 as well and i use this command to go from NDxHR to h264.

ffmpeg -i in.mov -c:v h264_nvenc -preset fast -profile:v high -level 5.1 -b:v 16M out.mp4


I think the encoder you want is "hevc_nvenc" so try this command and see whats available to you.

ffmpeg -h encoder=hevc_nvenc

oviano
Posts: 16
Joined: Sat May 14, 2016 9:15 am

Re: HEVC 10bit encoding with NVENC

Post by oviano » Wed Aug 17, 2016 6:29 am

Having looked at the ffmpeg code it seems there needs to be a few additions to unlock 10 bit encoding in NVENC HEVC.

At the moment it's clear that ffmpeg only implements the Main profile of NVENC HEVC, and not the Main 10.

I will experiment to see if I can produce a build that also implements Main 10, but in the absence of a Pascal card myself (yet) it would need one of you guys to test 10 bit encoding if I am able to make this change.

oviano
Posts: 16
Joined: Sat May 14, 2016 9:15 am

Re: HEVC 10bit encoding with NVENC

Post by oviano » Sat Aug 20, 2016 11:01 am

I have an ffmpeg build which *should* enable YUV444p and YUV444p10le (i.e. 10-bit) HEVC encoding using the latest Nvidia NVENC SDK if anyone is interested in testing...

ryuchayu
Posts: 3
Joined: Sun Jul 31, 2016 9:15 pm

Re: HEVC 10bit encoding with NVENC

Post by ryuchayu » Wed Aug 24, 2016 6:37 am

oviano wrote:I have an ffmpeg build which *should* enable YUV444p and YUV444p10le (i.e. 10-bit) HEVC encoding using the latest Nvidia NVENC SDK if anyone is interested in testing...
I'm very intereted in testing.
Can you send me your build to [email protected]?
I'll feedback ASAP.
Thank you.

oviano
Posts: 16
Joined: Sat May 14, 2016 9:15 am

Re: HEVC 10bit encoding with NVENC

Post by oviano » Wed Aug 24, 2016 10:24 am

Ok, here you go

https://www.dropbox.com/s/ha271otaef9os ... g.zip?dl=0

NVENC HEVC on Pascal natively supports the following 10-bit input pixel formats:

P010
YUV444P16

Note that ffmpeg does not currently support converting another pixel format to P010 (i.e. if your input file is something else, then trying to convert it to P010 with "-pix_fmt p010" will give an error message), however you can instead pass the one below in, and my patch will convert it to P010 with a slight slowdown:

YUV420P10

I'm not sure if this additional conversion functionality is going to be included in the official ffmpeg going forward, my patch for all of this is currently undergoing review.

I've also enabled the new rate-control feature "-rc-lookahead <x>" where x is the number of frames to lookahead up to a maximum 32. See the NVIDIA documentation for details.

Other Pascal features such as HEVC SAO and YUV444 (8-bit) support should also now work.

I've managed to get access to a Pascal GPU to test this and it seems ok, but let me know how you get on.

Some sample ffmpeg commands:

Encode as YUV420P (8-bit):

ffmpeg -i <input file name> -vcodec hevc_nvenc -pix_fmt yuv420p -preset hq -2pass 1 -vb 8000k -acodec copy <output file name>

Encode as YUV444P (8-bit):

ffmpeg -i <input file name> -vcodec hevc_nvenc -pix_fmt yuv444p -preset hq -2pass 1 -vb 8000k -acodec copy <output file name>

Encode as YUV420P10 (10-bit):

ffmpeg -i <input file name> -vcodec hevc_nvenc -pix_fmt yuv420p10 -preset hq -2pass 1 -vb 8000k -acodec copy <output file name>

Encode as YUV444P16 (10-bit):

ffmpeg -i <input file name> -vcodec hevc_nvenc -pix_fmt yuv444p16 -preset hq -2pass 1 -vb 8000k -acodec copy <output file name>

(Note that with the above examples I am explicitly asking for a certain pixel format, and if the input file has a different format then FFmpeg will automatically convert it. If you want to just feed the file's native format into the encoder then just leave out the -pix_fmt XXX bit. In this case I think FFmpeg will automatically override the file's native format if the encoder doesn't support it, but the output from FFmpeg should tell you this.)

Rate control lookahead:

ffmpeg -i <input file name> -vcodec hevc_nvenc -pix_fmt yuv420p -preset hq -2pass 1 -rc-lookahead 30 -vb 8000k -acodec copy <output file name>

ryuchayu
Posts: 3
Joined: Sun Jul 31, 2016 9:15 pm

Re: HEVC 10bit encoding with NVENC

Post by ryuchayu » Mon Aug 29, 2016 6:11 am

Everything works as you said.
Especially YUV420P10 patch is very good.
Thank you, oviano. :D

oviano
Posts: 16
Joined: Sat May 14, 2016 9:15 am

Re: HEVC 10bit encoding with NVENC

Post by oviano » Mon Aug 29, 2016 6:38 am

Ok, I'm glad to hear that, thankyou for confirming.

As of yesterday, my 10-bit NVENC encoding patches are in the official FFmpeg however they rejected the YUV420P10 part of it because it involved some conversion code which needs to be in a different place to where I put it and I don't have the time to do that at the moment.

So if you plan to use later versions of FFmpeg in future then you will only be able to encode YUVP010 or YUV444P16 10-bit input formats, or you will need to build FFmpeg yourself and I'd be happy to supply the patch file that I am using with my own builds that will enable YUV420P10!

diehummel
Posts: 2
Joined: Fri Dec 23, 2016 8:24 am

Re: HEVC 10bit encoding with NVENC

Post by diehummel » Fri Dec 23, 2016 8:49 am

Hello,

i found this thread via google :)
and i have a question.
Does hevc_nvenc already support BT2020 somehow?
When i re-encode an 4k HDR BT2020 Video the BT2020 Metadata gets lost.
With x265 and x265-params i can set bt2020 colormatrix etc.. and its ok. But i would like to use GPU performance.

thanks
Christian

Post Reply