使用NVIDIA GPU硬件加速时,FFmpeg提示“无法在格式间转换”

3

我正在使用Windows 10命令行中的ffmpeg,想尝试使用GPU加速来提高执行时间。像这样的简单剪切命令运行良好,其执行时间减少了60-70%。太棒了。

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

现在我尝试使用-filter_complex标志来叠加、淡入淡出和平移一张png图片到一个视频上。这是非GPU增强命令的工作原理:

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

然后,我像这样将与GPU相关的标志添加到命令中。

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

但是它不能工作。我收到了这个错误。
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

我甚至不知道它的含义。我是否可以在GPU上使用GPU加速来运行任何ffmpeg命令?我找到了一些关于hwupload_cuda标志的信息,但我不确定该如何使用它。我的尝试目前都失败了。

你有什么建议可以修改命令,让它在GPU上运行?


叠加滤镜是软件,因此必须先将GPU解码的帧传输到系统RAM,然后在叠加后发送回GPU进行硬件编码。 - Gyan
谢谢,我该如何将帧从系统RAM移动到其他地方?我需要使用hwdownload和hwupload_cuda吗? - MorenoGentili
你找到解决方案了吗? - live2
仍然没有解决方案,抱歉。 - MorenoGentili
1个回答

3

只需添加

hwdownload,YOUR_FILTER,hwupload

就像这样:

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"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接