FFmpeg 绘图文本和使用 sendcmd/zmq 的实时坐标 [英] FFmpeg drawtext and live coordinates with sendcmd/zmq

查看:69
本文介绍了FFmpeg 绘图文本和使用 sendcmd/zmq 的实时坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在具有外部实时数据的实时视频源上使用标记来设置 x、y 坐标.sendcmd 可以读取文本文件但不会更新它,因此不会执行以后的更新.只能用zmq吗?如果是这样,我可以将 zmq 用作单个过滤器(带有 drawtext),而不是过滤器复合体吗?

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?

我有一个 python,它以适当的格式将实时坐标导出到 cmd.txt 文件.我使用 unix 时间作为坐标,并且我还从实时环回设备复制了输入时间戳,因此它们的时间几乎相同.有一个小的延迟,所以我用 +1.5s 补偿了导出的时间戳.这意味着标记会在这个额外的时间段内移动(而 cmd.txt 中的时间戳比实时源稍早),但不会再更新.我假设 FFmpeg 读取了这个 cmd.txt 并且不会再更新它,但我的 python 正在连续写入它.

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.

cmd.txt 的示例行:

Example line of the cmd.txt:

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

这是实际的 ffmpeg 管道:

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 是一个以 unix 时间作为输入时间戳的环回设备.

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

推荐答案

您可以在简单的过滤器链中使用 zmq 代替 sendcmd.

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>

到 ffmpeg 的标准输入.

to ffmpeg's stdin.

开头的 cC 用于命令,后面紧跟(无空格)过滤器类/实例.您可以使用 all 向所有可以接收一个命令的过滤器发送命令.您可以发送 \n 信号

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>

这篇关于FFmpeg 绘图文本和使用 sendcmd/zmq 的实时坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆