Answer the question
In order to leave comments, you need to log in
How to create a video broadcast server?
How to create a video broadcast server? What is the best protocol to send video? How can I send a video from OpenCV to the browser?
I threw something, but for obvious reasons it does not work:
import socket
import cv2
RESPONSE = "HTTP/1.1 200 OK\r\nServer: hrenoten\r\nAccept-Ranges: bytes\r\nContent-Type: application/octet-stream\r\nConnection: keep-alive\r\n\r\n"
BUFF_SIZE = 64*1024
#ip, port = tuple(input().split(' '))
ip, port = '127.0.0.1', 8000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind( (ip, int(port)) )
sock.listen(10)
cap = cv2.VideoCapture(0)
conn, addr = sock.accept()
print('New connection: ' + addr[0])
while not conn.recv(BUFF_SIZE):
pass
while True:
ret, img = cap.read()
byteImg = img.tostring()
#А ещё я не понимаю нужны-ли HTTP заголовки
conn.send(RESPONSE.encode('utf-8') + byteImg)
print(addr[0] + ' is closed')
conn.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question