Encoding on CPU can be done via:

ffmpeg -i input.mp4 -vcodec h264 -crf 23 -acodec copy h264.mp4

GPU's alternative for the codec is h264_nvenc. How can I pass the same options to it?

I googled and came to following command:

ffmpeg -i input.mp4 -vcodec h264_nvenc -rc constqp -qp 23 -acodec copy h264_nvenc.mp4

But the file I get is much larger. And with other options quality is much worther.

PS: Same question in Russian.


from reading:

ffmpeg -h encoder=h264_nvenc

and the nvidia nvenc examples at (https://devblogs.nvidia.com/nvidia-ffmpeg-transcoding-guide/), I've arrived at:

ffmpeg -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i test_input.mp4 -c:a copy -c:v h264_nvenc -b:v 0 -cq 1 test3.mp4


-b:v 0 over-rides the default 2mbps bitrate as noted by Gyan
-cq 1 means target quality level 1 (highest)
 range of 0-51. 
 0 means automatic (in my case around 15mbps)
 1 gives about 15mbps, 26 results in around 5mbps, 51 results in 0.5mbps

CRF != CQP. The former may have variable QP but tries to maintain quality. CQP is a cruder form of rate-control.

For nvenc, use -rc vbr_hq -qmin 0 and add -cq X where X sets a quality level; range is 0-51. Smaller is better.

  • ffmpeg -i input.mp4 -vcodec h264_nvenc -vcodec h264_nvenc -cq 1 -acodec copy 25962-1.mp4 with values 0, 1 and 23 produce the same binary file having bad quality. With 51 file is 3 times smaller and quality is worther. So the parameter is not ignored. – Qwertiy Feb 12 '19 at 13:46
  • Edited cmd. Values below 26 will produce about the same quality. – Gyan Feb 12 '19 at 14:01
  • No, still bad quality. – Qwertiy Feb 12 '19 at 14:16
  • nvenc will not match x264 quality at the same bitrate. – Gyan Feb 12 '19 at 14:34

If you don't specify bit rate yourself, FFmpeg will assume a default bit rate of 256 kbit\s, you have to unset it with -b:v 0.

  • 1
    The h264_nvenc encoder has a default bitrate of 2 mbps. But in any case, the cq mode does not look at bitrate. – Gyan May 8 '19 at 5:32
  • Can you show the full command, please? – Qwertiy May 8 '19 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.