CUDA/CUVID/NvDecode

CUVID, which is also called nvdec by Nvidia now, can be used for decoding on Windows and Linux. In combination with nvenc it offers full hardware transcoding. CUVID offers decoders for H264, HEVC, MJPEG, mpeg1/2/4, vp8/9, vc1. Codec support varies by hardware. The full set of codecs being available only on Pascal hardware, which adds VP9 and 10 bit support. While decoding 10 bit video is supported, it is not possible to do full hardware transcoding currently.

Full hardware transcode with CUVID and NVENC:
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input -c:v h264_nvenc -preset slow output.mkv

Partial hardware transcode, with frames passed through system memory (This is necessary for transcoding 10bit content):
ffmpeg -c:v h264_cuvid -i input -c:v h264_nvenc -preset slow output.mkv

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 cuvid -c:v h264_cuvid -i input -vf scale_npp=-1:720 -c:v h264_nvenc -preset slow output.mkv

The -hwaccel_device option can be used to specify the GPU to be used by the cuvid hwaccel in ffmpeg.

#!/bin/bash

echo ==========================

read -erp 'Input: ' input
#read -erp 'Output: ' output
#read -erp 'Video Bitrate: ' vb
#read -erp 'GOP: ' gop

echo ==========================

echo

set -x #echo on

ffplay -x 640 -y 360 -vf "drawtext=text='%{pts\:hms}':box=1:x=(w-tw)/2:y=h-(2*lh)" "$input"
#!/bin/bash

echo ==========================

read -erp 'Input: ' input
read -erp 'Output: ' output
read -erp 'Video Bitrate: ' vb
read -erp 'GOP: ' gop

echo ==========================

echo

set -x #echo on

ffmpeg -hwaccel cuvid -c:v h264_cuvid -i "$input" -c:v h264_nvenc -g $gop -b:v $vb -c:a aac -metadata:s:a language=eng -metadata creation_time=now -loglevel verbose "$output"
#!/bin/bash

echo ==========================

read -erp 'Input: ' input
read -erp 'Output: ' output
read -erp 'Video Bitrate: ' vb
read -erp 'GOP: ' gop
read -erp 'Start (hh:mm:ss): ' start
read -erp 'Time (hh:mm:ss): ' time

echo ==========================

echo

set -x #echo on

ffmpeg -ss $start -hwaccel cuvid -c:v hevc_cuvid -i "$input" -map 0 -ss 00:00:30 -t $time -c:v h264_nvenc -g $gop -b:v $vb -c:a ac3_fixed -c:s copy -metadata:s:a language=eng -metadata creation_time=now -loglevel verbose "$output"

Partial hardware transcode, with frames passed through system memory (This is necessary for transcoding 10bit content):

#!/bin/bash

echo ==========================

read -erp 'Input: ' input
read -erp 'Output: ' output
read -erp 'Video Bitrate: ' vb
read -erp 'GOP: ' gop

echo ==========================

echo

set -x #echo on

ffmpeg -c:v hevc_cuvid -i "$input" -map 0 -c:v h264_nvenc -pix_fmt yuv420p -g $gop -b:v $vb -c:a ac3_fixed -c:s copy -metadata:s:a language=eng -metadata creation_time=now -loglevel verbose "$output"

Leave a Reply

Your email address will not be published. Required fields are marked *