im trying to make a webcam stream over two computers in the same network, so i did some research on the internet and i found this client and server code this is the Client
import socket
import numpy as np
import cv2
UDP_IP = '127.0.0.1'
UDP_PORT = 999
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
d = frame.flatten ()
s = d.tostring ()
for i in xrange(20):
sock.sendto (s[i*46080:(i+1)*46080],(UDP_IP, UDP_PORT))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
and this is the Server:
#Server prog
import socket
import numpy
import time
import cv2
UDP_IP="127.0.0.1"
UDP_PORT = 999
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
s=""
while True:
data, addr = sock.recvfrom(46080)
s+= data
if len(s) == (46080*20):
frame = numpy.fromstring (s, dtype=numpy.uint8)
frame = frame.reshape(480,640,3)
cv2.imshow("frame",frame)
s=""
if cv2.waitKey(1) & 0xFF == ord('q'):
break
there are some lines that i can't understand like this for
for i in xrange(20):
sock.sendto (s[i*46080:(i+1)*46080],(UDP_IP, UDP_PORT))
why is he using it? (i know that in UDP you can't send a huge file and that u need to send in parts but why like this? and why 46080? )
and in the server itself if len(s) == (46080*20):
+when you run the server and the client the video stream that the server received is lagging and the frames repeat themselves..