FFmpeg GPU Transcoding Examples

FFmpeg GPU Transcoding Examples

For using FFmpeg hardware acceleration you need compile FFmpeg with NVIDIA NVENC support. How To Compile FFmpeg With NVENC H264 Hardware Encoder.

Here is some examples how to use NVENC encoder.

Basic FFmpeg GPU transcoding. Decoding part using CPU encoding. Encoding using h264 NVENC video encoder:

$ ffmpeg -i INPUT -vcodec h264_nvenc -b:v 5M -acodec copy OUTPUT

Full hardware transcoding with using CUVID and NVENC:

$ ffmpeg -hwaccel cuvid -c:v h264_cuvid -i INPUT -vcodec h264_nvenc -preset slow OUTPUT

$ ffmpeg -hwaccel cuvid -c:v h264_cuvid -i INPUT -vcodec h264_nvenc -b:v 5M OUTPUT

FFmpeg resize using CUDA scale (filter scale_cuda is GPU accelerated video resizer ), full hardware transcoding example:

$ ffmpeg -hwaccel cuvid -c:v h264_cuvid -i INPUT -vf scale_cuda=-1:720 -vcodec h264_nvenc -acodec copy OUTPUT

scale_cuda=-1:720 means keep the same aspect ratio and match the other argument.

 

CUDA Deinterlace

$ ffmpeg -hwaccel cuvid -c:v mpeg2_cuvid -i INPUT -vf hwdownload,format=nv12,yadif,hwupload_cuda -preset fast -acodec aac -ar 44100 -ac 2 -b:a 96k -vcodec h264_nvenc -b:v 2500k -maxrate 3000k -bufsize 5000k -g 150 -qmin 1 -qmax 50 -f flv OUTPUT

Resize with NVIDIA video decoder

$ ffmpeg -c:v h264_cuvid -hwaccel nvdec -resize 1280x720 -i INPUT -vcodec h264_nvenc -b:v 5M -acodec copy OUTPUT

 

Check all available options for encoder h264_nvenc

Very usable function if you need to know all available options supported by specific encoder or decoder:

$ ffmpeg -h encoder=h264_nvenc

Example output for mpeg2_cuvid decoder:

mpeg2_cuvid decoder options

Read also: How To Choose GPU To Be Used In FFmpeg

 

 

If you like what you are reading, please:

Buy me a coffeeBuy me a coffee

arstech

2 Comments

  1. hi , thank you for your grate article , i have a question about choosing the best graphic card ! we convert videos to different sizes and hls and we have lots of video that we want to transcode them in the fastest way . what is the best nvidia graphic card for this ? thank you so much

    • thank you too
      Depends how many streams you need to encode. NVIDIA Quadro series great cards.
      For 1-2 streams you can use any Nvidia GPU with CUDA support

Leave a Reply