2

I'd like to use a marker on a live video source which has external live data to set x,y coordinates. sendcmd can read the text file but it won't update it, so later updates are not executed. Is it possible only with zmq? And if so, can I use zmq as a single filter (with drawtext), not with filter complex?

I have a python that exports live coordinates in the appropriate format to a cmd.txt file. I use unix time for the coordinates and I also copy the input timestamps from the live loopback device so they have almost the same time. There's a small delay so I have compensated the exported timestamps with +1.5s. This means the marker is moving for this extra period (while timestamps in cmd.txt are a bit ahead of the live source), but it won't update any more. I assume that FFmpeg reads this cmd.txt and won't update it any more but my python is writing it continuously.

Example line of the cmd.txt:

1557402120.3119707 drawtext reinit 'x=752:y=480';

This is the actual ffmpeg pipe:

ffmpeg -fflags nobuffer -vaapi_device /dev/dri/renderD128 -f v4l2 -i /dev/video0 -vf "sendcmd=f=cmd.txt,drawtext=fontfile=font.ttf:fontsize=30:fontcolor=white:r=25:text='o',format=nv12,hwupload" -copyts -c:v h264_vaapi -qp 24 -y 0.mp4

Source is a loopback device with unix time as input timestamp.

DavidK
  • 111
  • 7

1 Answers1

3

You can use zmq in place of sendcmd in a simple filterchain.

There is another way, currently undocumented. Send the keystrokes

Cdrawtext 1557402120.3119707 reinit 'x=752:y=480'<enter>

to ffmpeg's stdin.

The initial c or C is for command, immediately followed (no spaces) by the filter class/instance. You can use all to send a command to all filters which can receive one. You can send \n to signal <enter>

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • I've tried the above and I don't get any errors but it won't read coordinates and encoding has some latency issues as well. As for zmq, when I try to use that in a simple filterchain, I get the "no such filter: zmq" error. As far as I understood for zmq I don't have to use timestamps, it will be handled as live data and set coordinates according to the actual value. This is much preferred but I have a hard time to get there. Any help would be appreciated. – DavidK May 14 '19 at 11:29
  • For zmq, ffmpeg has to be compiled with libzmq. *it won't read coordinates* --> does it work with other parameters. How are sending keystrokes? Does ffmpeg stderr acknowledge receiving the command. – Gyan May 14 '19 at 12:12
  • I was able to use zmq, didn't know it has to be run as root (otherwise I get a no such filter error). Problem is that it has pretty large delays. Sendcmd was faster but when I was using it with file source it stopped as soon as it reached the actual position (it was unable to update position with newly written coordinates). Stdin requires sendcmd too? If so, what should I use instead of sendcmd=f (file)? When I use only the cdrawtext it doesn't work although I don't get any errors. – DavidK May 21 '19 at 10:20
  • When do you send commands? i.e. how far in the future is the cmd timestamp when you type in the command – Gyan May 21 '19 at 12:46