how to Create a Live Streaming Video Chat App without voice using the cv2 module of Python.

For this, we have to create two python files one for client and other for server.

  1. For server( Server.py) :

Step :1 first we have to import socket , cv2, pickle , struct and imutils libraries.

>>> import socket, cv2, pickle, struct, imutils.

Step 2: we have to create socket

server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
port = 9999
socket_address = (host_ip,port)

Step :3 Bind the socket

server_socket.bind(socket_address)

Step 4: Socket Listen

server_socket.listen(5)

Step 5: Socket Accept

while True:

client_socket,addr = server_socket.accept()

print(‘GOT CONNECTION FROM:’,addr)

if client_socket:

vid = cv2.VideoCapture(0)

while(vid.isOpened()):

img,frame = vid.read()

frame = imutils.resize(frame,width=680)

a = pickle.dumps(frame) message = struct.pack(“Q”,len(a))+a

client_socket.sendall(message)

cv2.imshow(‘TRANSMITTING VIDEO’,frame)

key = cv2.waitKey(1) & 0xFF

if key ==13 or key ==113 or key==81: msg=”q”

client_socket.send(msg.encode())

client_socket.close()

cv2.destroyAllWindows()

2. For client (client.py)

Step :1 first we have to import socket , cv2, pickle , struct and imutils libraries.

>>> import socket, cv2, pickle, struct, imutils.

Step 2: we have to create socket

client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_ip = ‘192.168.56.1’ # paste your server ip address here
port = 9999
client_socket.connect((host_ip,port)) # a tuple
data = b””

while True:
while len(data) < payload_size:
packet = client_socket.recv(4*1024) # 4K
if not packet: break
data+=packet
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack(“Q”,packed_msg_size)[0]

while len(data) < msg_size:
data += client_socket.recv(4*1024)
frame_data = data[:msg_size]
data = data[msg_size:]
frame = pickle.loads(frame_data)
cv2.imshow(“RECEIVING VIDEO”,frame)
key = cv2.waitKey(1) & 0xFF
if key ==13 or key ==113 or key==81:

cv2.destroyAllWindows()
break
client_socket.close()

# GitHub link : https://github.com/AnkitJha35/task3.git

#vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeducation #summertraining