Live Streaming Video Chat App

SUMMER 2021 — Task 03

Task 03

Description 📄

🧿 Create Live Streaming Video Chat App without voice using cv2 module of Python.

GitHub Repo: https://github.com/Ravenblaze128/Summerprogram-lw/tree/main/Task3

  • The Sender(Server)
  • The Receiver(Client)

The Sender:

import socket
import cv2
import pickle
import struct
import imutils
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print('HOST IP:',host_ip)
port = 10050
socket_address = (host_ip,port)
server_socket.bind(socket_address)server_socket.listen(5)
print("Listening @",socket_address)
while True:
client_socket,addr = server_socket.accept()
print('Connection from:',addr)
if client_socket:
vid = cv2.VideoCapture(0)

while(vid.isOpened()):
img,frame = vid.read()
a = pickle.dumps(frame)
message = struct.pack("Q",len(a))+a
client_socket.sendall(message)

cv2.imshow('Sending...',frame)
key = cv2.waitKey(10)
if key ==13:
client_socket.close()

The Receiver :

import socket
import cv2
import pickle
import struct
import imutils
client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_ip = '<Host IP>'
port = <Port_No>
while True:
while len(data) < payload_size:
packet = client_socket.recv(4*1024)
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...",frame)
key = cv2.waitKey(10)
if key == 13:
break
client_socket.close()

The Output:

Thank You!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store