Home » Encode H.265 with FFMPEG on Nvidia GTX 960 GPU

Encode H.265 with FFMPEG on Nvidia GTX 960 GPU

H.265 offers the same video quality as H.264 but using only half the bit rate, therefore, a lot of people chose to encode H.264 or other digital file formats into H.265/HEVC codec for reduce the storage space used by your videos. For those people who have ever tried to encode H.265 with Handbrake, you will find that the process can be painfully slow, and a single movie may take several hours even with a machine with a power processor. Fortunately, for those people who have got a Nvidia GTX 960 Graphic card, a second generation Maxwell GPU, you can make better use of hard-ware accelerated technology used on those Graphic card to large accelerate H.265 encoding speed. The following article will mainly talk about how to use FFMPEG to fast encode H.265 on Nvidia GTX 960 by using Nvidia NVENC technology.

Encode H.265 with FFMPEG on Ubuntu

Although FFMPEG support NVENC, but just not by default, and you have to compile it yourself. There are instructions to built ffmpeg with nvenc in Ubuntun 15.10, but they did not work on Ubuntu 14.04 so I mixed those with ffmpeg Ubuntu compilation guide to build it for my computer.

First we'll need to install some dependencies and create a working directory:

Create a working directory

You'll also need to download and install/compile some extra packages depending on the codecs we want to enable. I'll skip H.264 and H.265 since this will be handled by Nvidia GPU instead, and will enable AAC and MP3 audio encoders, VP8/VP9 and XviD video decoders and encoders, and libopus decoder and encoder as explained in the building guide:

Install/compile some extra packages

Now I'll download and extract ffmpeg snapshot (January 3, 2016) and copy the required NVENC 6.0 SDK header files into /usr/local/include:

Extract FFMPEG snapshot

Before configuring and building ffmpeg with nvenc enabled:

Configurate and build ffmpeg

You can also optionally install it (which I did):

Optionally enable it

This will install it in $HOME/bin/ffmpeg. Now we can verify nvenc support for H.264 and H.265 is enabled:
Verify is enabled

Perfect. Time for a test with our 1080p H.264 video sample, and encoding at 2000 kbps.

It took 30 seconds, or about the same time as with NvTranscode, but this time I had a watchable video with audio, and I could not notice any visual quality degradation.

I repeated the test with a H.264 1080p movie lasting 1 hour 57 minutes 29 seconds. The movie H.264 stream was encoded at 2150 kbps, so to decrease the file size by half I encoded the movie at 1075 kbps (-b:v 1075k option). The encoding only took 13 minutes and 12 seconds, or about 9 times faster real-time at 218 fps.

I also checked some GPU details during the transcoding:

GPU details during the transcoding

This shows for example that it does not maxes out the GPU power consumption (P2 mode: 33 Watts). My processor load was however a bit higher than expected, although not at 100% all the time as would have been the case for software video transcoding.

GPU use during Nvidia GPU accelerated video transcoding

FFMPEG simple alternative to encode H.265 on Windows

If you are non tech-savy, you can easily overwhelmed by the complicated operating process offered by FFMPEG. Fortunately, there are some simple fastest H.265 encoding software on Windows for you easily complete the whole encoding process with just few clicks.

The program we highly recommend to you here is called Pavtube Video Converter Ultimate. Different from FFMPEG which needs to run with command, the program spots a pretty easy to navigate interface to guide you through the whole encoding process. With the program, you can comprehensively encode virtually any digital file formats and also commercial Blu-ray/DVD disc to H.265/HEVC MP4/MKV with up to 30x encoding speed on a PC with Nvidia NVENC technology supported Nvidia Graphic Cards such as Nvidia GTX 960 enabled.

My Profile