Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPU-accelerated video processing with ffmpeg

I want to use ffmpeg to accelerate video encode and decode with an NVIDIA GPU.

From NVIDIA's website:

NVIDIA GPUs contain one or more hardware-based decoder and encoder(s) (separate from the CUDA cores) which provides fully-accelerated hardware-based video decoding and encoding for several popular codecs. With decoding/encoding offloaded, the graphics engine and the CPU are free for other operations.

My question is: can I use CUDA cores to encode and decode video, maybe faster?

like image 533
Wang Hai Avatar asked Jun 13 '17 00:06

Wang Hai


People also ask

Can FFmpeg use the GPU?

FFmpeg with NVIDIA GPU acceleration is supported on all Windows platforms, with compilation through Microsoft Visual Studio 2013 SP2 and above, and MinGW. Depending upon the Visual Studio Version and CUDA SDK version used, the paths specified may have to be changed accordingly.

What is GPU accelerated video encoding?

GPU Acceleration reduces the stress that video editing software apply on CPU and improve the speed and efficiency of these software. Enabling GPU acceleration for video rendering, playback saves you from waiting and improve the playback quality.


2 Answers

FFmpeg provides a subsystem for hardware acceleration, which includes NVIDIA: https://trac.ffmpeg.org/wiki/HWAccelIntro

In order to enable support for GPU-assisted encoding with an NVIDIA GPU, you need:

  • A ​supported GPU
  • Supported drivers for your operating system
  • The NVIDIA Codec SDK
  • ffmpeg configured with --enable-nvenc (default if the drivers are detected while configuring)
like image 184
Mike Versteeg Avatar answered Sep 23 '22 08:09

Mike Versteeg


Quick use on ​supported GPU:

CUDA

ffmpeg -hwaccel cuda -i input output 

CUVID

ffmpeg -c:v h264_cuvid -i input output 

Full hardware transcode with NVDEC and NVENC:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input -c:v h264_nvenc -preset slow output 

If ffmpeg was compiled with support for libnpp, it can be used to insert a GPU based scaler into the chain:

ffmpeg -hwaccel_device 0 -hwaccel cuda -i input -vf scale_npp=-1:720 -c:v h264_nvenc -preset slow output.mkv 

Source: https://trac.ffmpeg.org/wiki/HWAccelIntro

like image 38
GetoX Avatar answered Sep 22 '22 08:09

GetoX