Title: FFmpeg drawtext and live coordinates with sendcmd/zmq
Tags: ffmpeg;zeromq
Question: 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.


Here is another answer: 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&gt;
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&gt;
Comment for this answer: 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.
Comment for this answer: When do you send commands? i.e. how far in the future is the cmd timestamp when you type in the command
Comment for this answer: 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.
Comment for this answer: 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.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:05/09/19', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<ffmpeg><zeromq>', 'Title': 'FFmpeg drawtext and live coordinates with sendcmd/zmq', 'ViewCount': 1066, 'id': 56058909, 'user_AboutMe': None, 'user_AccountId': 15825661.0, 'user_DisplayName': 'DavidK', 'user_Reputation': 91.0, 'user_Views': 4.0, 'user_id': 11418626.0}}