python - 将其他数据嵌入到 UDP 视频流 Python OPENCV
问题描述
我正在尝试从服务器流式传输视频以在客户端上进行分析。
我正在使用 vidgears 创建一个 ffmpeg UDP 流供客户端连接。
但是,我需要有一个集中的帧数才能同步客户端提供的所有数据。
Client:
cap = cv2.VideoCapture('udp://localhost:23000')
while cap.isOpened():
print(cap.get(cv2.CAP_PROP_FRAME_COUNT))
Will only get me the frame count from the time the client connected.
Is there a way to embed a timecode or frame count when I am stream out the video so I can sync them all up?
服务器:
i = 0
output_params = {"-vcodec": "mpeg4", '-f': 'mpegts'}
streamer = WriteGearStream(output_filename='udp://localhost:23000', compression_mode=True, logging=True, **output_params)
cap = cv2.VideoCapture(0)
while cap1.isOpened():
i+=1
ret, frame = cap.read()
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
streamer.write(vis)
类 WriteGearStream(WriteGear):
def __init__(self, output_filename='', compression_mode=True, custom_ffmpeg='', logging=False, **output_params):
super(WriteGearStream, self).__init__(output_filename='temp.pm4', compression_mode=compression_mode, custom_ffmpeg=custom_ffmpeg, logging=logging, **output_params)
self.out_file = output_filename
有谁知道如何获得与服务器同步的帧数?
谢谢!
解决方案
我是VidGear视频处理 python 库的作者。这不是使用 WriteGear API 的正确方法,也不是为此目的而设计的,因此恐怕行不通。
请使用 VidGear 的新NetGear API,该 API 专门用于通过网络在互连系统之间实时同步传输视频帧。这个新的 API 实现了一个围绕 PyZmQ python 库的高级包装器,其中包含 ZeroMQ 的 python 绑定——一个高性能异步分布式消息传递库,旨在用于分布式或并发应用程序。
推荐阅读
- python - 如何在python程序中使用概率
- reactjs - 如何在 React 中渲染组件而不将其放入 render() 方法中?
- python - 计算熊猫中无关紧要的行数
- flutter - 如何在有状态小部件中编辑最终对象
- html - VBA 从包含空格的 HTML 中检索数据
- python - 如何解决“cuDNN 未启用”
- sql - SAP HANA SQL 中是否有任何方法可以计算迭代中没有循环操作的百分比?
- python - 日期时间戳无法正确读取为字符串
- javascript - 如何在 javascript ( w/ webpack) 中播放 mp3 文件?
- ruby-on-rails - 如何让 Rails 5 上的 avatar.variant(size: "200x200") 在生产中使用 aws 工作?