mihuj
mihuj

Reputation: 33

Receiving ZMQ video stream in NodeJS

I'm writing an electron app in which I'd like to receive a video (webcam video) sent from python backend via ZeroMQ PUB/SUB patter. I have a properly working server in python which I tested with a python client-receiver.

My python video publisher

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)

I've tried receiving it in NodeJS using a simple subscribe client similar to this one from zmq official page but it didn't seem to receive anything.

Upvotes: 1

Views: 513

Answers (1)

mihuj
mihuj

Reputation: 33

The problem was with sending the topic in the message. NodeJS wrapper didn't see the topic when it was send as a string with only a blank whitespace separating the topic and the payload. To properly send the message topic I had to use a send_multipart function.

footage_socket.send_multipart([b"video", byte_buffer])

Upvotes: 1

Related Questions