[FFmpeg-user] DASH/HLS with CUDA h264_nvenc

Douglas Rhiner douglasrhiner at gmail.com
Mon Mar 21 19:27:04 EET 2022


We are using Python and FFMPEG to create DASH & HLS VBS’s and want to be
able to leverage our GPU to its fullest potential.
Currently we have several ffmpeg commands/scriptings running that leverage
the GPU just fine. It's when we try to squeeze the requisite cuda/nvenc
elements things go awry.
This is the command that we have working right now using software-encoding:

VIDEO_IN = 'X:/DASH/VIDEO_7984.mp4'
BASE_OUT = 'X:/DASH/DASHOUT/'
VIDEO_OUT = 'dash.mpd'
FPS = '30'
GOP_SIZE = '90'
V_SIZE_1 = '1920x960'
V_KEYSIZE_1 = '960'

ffmpegcommand   = 'ffmpeg -i ' + VIDEO_IN + ' -y '
ffmpegcommand += ' -keyint_min ' + GOP_SIZE + ' -g ' + GOP_SIZE + ' -r ' +
FPS + '-sc_threshold 0'
ffmpegcommand += ' -c:v libx264 -allow_sw 1 -pix_fmt yuv420p'
ffmpegcommand += ' -c:a aac -b:a 128k -ac 1 -ar 44100'
ffmpegcommand += ' -map v:0 -s:0 ' + V_SIZE_1 + ' -b:v:0 2M -maxrate:0
2.14M -bufsize:0 3.5M'
ffmpegcommand += ' -map v:0 -s:1 ' + V_SIZE_2 + ' -b:v:1 145k -maxrate:1
155k -bufsize:1 220k'
ffmpegcommand += ' -map v:0 -s:2 ' + V_SIZE_3 + ' -b:v:2 365k -maxrate:2
390k -bufsize:2 640k'
ffmpegcommand += ' -map v:0 -s:3 ' + V_SIZE_4 + ' -b:v:3 730k -maxrate:3
781k -bufsize:3 1278k'
ffmpegcommand += ' -map v:0 -s:4 ' + V_SIZE_4 + ' -b:v:4 1.1M -maxrate:4
1.17M -bufsize:4 2M'
ffmpegcommand += ' -map v:0 -s:5 ' + V_SIZE_5 + ' -b:v:5 3M -maxrate:5
3.21M -bufsize:5 5.5M'
ffmpegcommand += ' -map v:0 -s:6 ' + V_SIZE_5 + ' -b:v:6 4.5M -maxrate:6
4.8M -bufsize:6 8M'
ffmpegcommand += ' -map v:0 -s:7 ' + V_SIZE_6 + ' -b:v:7 6M -maxrate:7
6.42M -bufsize:7 11M'
ffmpegcommand += ' -map v:0 -s:8 ' + V_SIZE_6 + ' -b:v:8 7.8M -maxrate:8
8.3M -bufsize:8 14M'
ffmpegcommand += ' -map 0:a'
ffmpegcommand += ' -init_seg_name init\$RepresentationID\$.\$ext\$
-media_seg_name chunk\$RepresentationID\$-\$Number%05d\$.\$ext\$'
ffmpegcommand += ' -use_template 1 -use_timeline 1 -f dash ' + VIDEO_OUT

I've tried the following modifications, trying to leverage our RTX-3090:

ffmpegcommand   = 'ffmpeg -hwaccel cuda -hwaccel_output_format cuda -y -i '
+ VIDEO_IN
ffmpegcommand += ' -keyint_min ' + GOP_SIZE + ' -g ' + GOP_SIZE + ' -r ' +
FPS + '-sc_threshold 0'
ffmpegcommand += ' -c:v h264_nvenc -pix_fmt yuv420p'
ffmpegcommand += ' -c:a aac -b:a 128k -ac 1 -ar 44100'
ffmpegcommand += ' -map v:0 -vf:0 scale_cuda=-2:' + V_KEYSIZE_1 + ' -b:v:0
2M -maxrate:0 2.14M -bufsize:0 3.5M'
...
ffmpegcommand += ' -map 0:a'
ffmpegcommand += ' -init_seg_name init\$RepresentationID\$.\$ext\$
-media_seg_name chunk\$RepresentationID\$-\$Number%05d\$.\$ext\$'
ffmpegcommand += ' -use_template 1 -use_timeline 1 -f dash ' + VIDEO_OUT

But get errors like:
when using the "-s:0 ' + V_SIZE_1" resize method.
*"Impossible to convert between the formats supported by the filter
'Parsed_scale_cuda_0' and the filter 'auto_scaler_0'"*
-or-
when using the "-vf:0 scale_cuda=-2:' + V_KEYSIZE_1"
*"read, ignoring remaining - vf options: Use ',' to separate filters"*

So it seems that the sticky-wicket is the resize command. I've tried all
sorts of modifications trying to get the mapping to work correctly to no
avail.

Anyone manage to pull this off or have suggestions?

-- 
Douglas Rhiner
JD Publishing
CTO
C.530-448-2754
Skype.douglasrhiner
924 Incline Way Suite L
Incline Village, NV
89451
douglasrhiner at gmail.com


xplorit.com <https://www.xplorit.com>


wendyourway.com <https://www.wendyourway.com>


More information about the ffmpeg-user mailing list