首页 > 解决方案 > 将其他数据嵌入到 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

有谁知道如何获得与服务器同步的帧数?

谢谢!

标签: pythonopencvserverudpvideo-streaming

解决方案


我是VidGear视频处理 python 库的作者。这不是使用 WriteGear API 的正确方法,也不是为此目的而设计的,因此恐怕行不通。

请使用 VidGear 的新NetGear API,该 API 专门用于通过网络在互连系统之间实时同步传输视频帧。这个新的 API 实现了一个围绕 PyZmQ python 库的高级包装器,其中包含 ZeroMQ 的 python 绑定——一个高性能异步分布式消息传递库,旨在用于分布式或并发应用程序。


推荐阅读