在 FFmpeg 中将 vaapi 与 drawtext 结合使用

在 FFmpeg 中将 vaapi 与 drawtext 结合使用

我正在尝试为视频添加时间戳。

我使用 drawtext 与 pts 和 gmtime 来实现它。

但是,当我尝试使用VAAPI来加速进度时,出现了错误。

这是我的 ffmpeg 命令:

ffmpeg \
  -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
  -i input.mp4 \
  -vf "drawtext=fontfile='/usr/share/fonts/truetype/msttcorefonts/arial.ttf': \
  [email protected]: fontsize=50: x=60: y=1000: \
  text='%{pts\:gmtime\:$(/bin/date -d "20200101 10:30:00" +"%s")\:%Y-%m-%d %T}', \
  format=nv12|vaapi,hwupload,hwdownload" \
  -b:v 10M -c:a copy -vcodec h264_vaapi \
  -y output.mp4

它返回:

[hwupload @ 0x55d7727a4bc0] A hardware device reference is required to upload frames to.
[Parsed_hwupload_2 @ 0x55d7727a4ac0] Query format failed for 'Parsed_hwupload_2': Invalid argument
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

如果我删除 hwupload,我会得到:

Impossible to convert between the formats supported by the filter 'Parsed_format_1' 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
Conversion failed!

有人能帮忙指出我遗漏了什么或者命令错误的地方吗?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

更新:@Gyan 指出我应该hwdownload在 之前插入drawtext。我按照他的建议,没有硬件编码,ffmpeg 开始工作。我尝试启用硬件编码,但再次出现错误。这是我修改后的命令:

ffmpeg \
  -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
  -i input.mp4 \
  -vf "format=nv12|vaapi,hwdownload, \
  drawtext=fontfile='/usr/share/fonts/truetype/msttcorefonts/arial.ttf': \
  [email protected]: fontsize=50: x=60: y=1000: \
  text='%{pts\:gmtime\:$(/bin/date -d "20200101 10:30:00" +"%s")\:%Y-%m-%d %T}', \
  format=nv12|vaapi,hwupload" \
  -b:v 10M -c:a copy -vcodec h264_vaapi \
  -y output.mp4

错误信息如下:

[hwupload @ 0x557b78829880] A hardware device reference is required to upload frames to.
[Parsed_hwupload_4 @ 0x557b78839500] Query format failed for 'Parsed_hwupload_4': Invalid argument
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

有人能帮忙再检查一下命令吗?或者 drawtext 不能与硬件编码一起使用吗?

相关内容