ffmpeg: "Impossible to convert between the formats" when using NVIDIA GPU hardware acceleration

Viewed 3835

I'm using ffmpeg from the command line on Windows 10 and I wanted to gave GPU acceleration a try to improve execution times. A simple cut command like this works fine and its execution time is reduced by 60-70%. Awesome.

ffmpeg -hwaccel cuvid -c:v h264_cuvid -ss 00:00:10 -i in.mp4 -c:v h264_nvenc out.mp4

Now I tried to use the -filter_complex flag to overlay, fade and translate a png image over a video. The working non-GPU enhanced command is this one:

ffmpeg -i in.mp4 -loop 1 -t 75 -i overlay.png -filter_complex "[1:v]fade=t=in:st=30:d=0.3:alpha=1,fade=t=out:st=35.7:d=0.3:alpha=1[png1];[0:v][png1]overlay=x='if(gte(t,30), (t-30)*10, NAN)'" -movflags +faststart out.mp4

Then, I added the GPU-related flags to the command like this.

ffmpeg -hwaccel cuvid -c:v h264_cuvid -i in.mp4 -loop 1 -t 75 -i overlay.png -filter_complex "[1:v]fade=t=in:st=30:d=0.3:alpha=1,fade=t=out:st=35.7:d=0.3:alpha=1[png1];[0:v][png1]overlay=x='if(gte(t,30), 60-tanh((t-30)*30/5)*60, NAN)'" -movflags +faststart -c:v h264_nvenc out.mp4

But it won't work. I get this error.

Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0:0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0

I don't even know what it means. Can I actually run ANY ffmpeg command on the GPU with GPU acceleration? I've found some information about the hwupload_cuda flag but I'm not sure if I should use it and how. My attempts have failed so far.

Any advice on how I should modify the command to make it work on the GPU?

1 Answers

Just add

hwdownload,YOUR_FILTER,hwupload

like this:

ffmpeg.exe
    -y
    -hwaccel_device 2
    -hwaccel cuvid
    -c:v h264_cuvid
    -i input.mp4
    -vfhwdownload,format=nv12,drawtext=textfile=file.txt:x=0:y=0:fontfile='c\:\/windows\/fonts\/arial.ttf',hwupload
    -c:v h264_nvenc
    -f mp4 output.mp4"
Related