1

I am trying to add the timestamp to the video.

I use drawtext with pts and gmtime to achieve it.

However, when I try to use the VAAPI to accelerate the progress, the error occur.

Here is my ffmpeg command:

ffmpeg \
  -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
  -i input.mp4 \
  -vf "drawtext=fontfile='/usr/share/fonts/truetype/msttcorefonts/arial.ttf': \
  fontcolor=yellow@0.7: 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

It returns:

[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!

If I remove the hwupload, I get:

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!

Could anyone help to point out what I am missing or wrong with the command?

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

Update: @Gyan points out that I should insert the hwdownload before the drawtext. I follow his suggestion, and without hardware encoding, ffmpeg starts to work. I try to enable the hardware encoding, however, get the error again. Here is my modified command:

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': \
  fontcolor=yellow@0.7: 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

And the error message:

[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!

Could anyone help to check the command again? Or, does the drawtext can not work with hardware encoding?

  • drawtext does not work upon hw frames, so after hw decoding, hwdownload has to be inserted before drawtext. And unless you intend to encode with VAAPI, the hwupload is not required. – Gyan May 28 at 9:29
  • I do plan to encode with VAAPI, I was testing with and without hardware encoding before posting. That was my fault for forgeting to type the -vcodec h264_vaapi on the original post. Thank @Gyan for pointing out, I have revised it. I move the hwdownload in front of the drawtext, without hardware enconding, ffmpeg starts to work. Then, I enable the hardware encoding, still get the error. I will update the command and the error message on the original post. Could you please help to check the command again? Or, does the drawtext can not work with hardware encoding? – Anderson May 28 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.