在 NodeJS 中接收 ZMQ 视频流
Receiving ZMQ video stream in NodeJS
我正在编写一个电子应用程序,我想在其中接收通过 ZeroMQ PUB/SUB 模式从 python 后端发送的视频(网络摄像头视频)。我在 python 中有一台正常工作的服务器,我用 python 客户端接收器进行了测试。
我的 python 视频发布者
import base64
import cv2
import zmq
context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://localhost:5555')
camera = cv2.VideoCapture(0)
while True:
_, frame = camera.read()
frame = cv2.resize(frame, (640, 480))
_, buffer = cv2.imencode('.jpg', frame)
byte_buffer = base64.b64encode(buffer)
footage_socket.send(byte_buffer)
我尝试在 NodeJS 中使用类似于 this one 的简单订阅客户端从 zmq 官方页面接收它,但它似乎没有收到任何东西。
问题在于发送消息中的主题。当 NodeJS 包装器作为字符串发送时没有看到主题,只有一个空白分隔主题和有效负载。为了正确发送消息主题,我必须使用 send_multipart 函数。
footage_socket.send_multipart([b"video", byte_buffer])
我正在编写一个电子应用程序,我想在其中接收通过 ZeroMQ PUB/SUB 模式从 python 后端发送的视频(网络摄像头视频)。我在 python 中有一台正常工作的服务器,我用 python 客户端接收器进行了测试。
我的 python 视频发布者
import base64
import cv2
import zmq
context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://localhost:5555')
camera = cv2.VideoCapture(0)
while True:
_, frame = camera.read()
frame = cv2.resize(frame, (640, 480))
_, buffer = cv2.imencode('.jpg', frame)
byte_buffer = base64.b64encode(buffer)
footage_socket.send(byte_buffer)
我尝试在 NodeJS 中使用类似于 this one 的简单订阅客户端从 zmq 官方页面接收它,但它似乎没有收到任何东西。
问题在于发送消息中的主题。当 NodeJS 包装器作为字符串发送时没有看到主题,只有一个空白分隔主题和有效负载。为了正确发送消息主题,我必须使用 send_multipart 函数。
footage_socket.send_multipart([b"video", byte_buffer])