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

K.S.L.K.Harini
4 min readJun 16, 2021

IN order to start our Program, lets jump into the step by step process. Firstly we need to install libraries and also make sure to have devices. From My side I have a mobile and laptop, I’ m going with them..

If you also having a mobile and laptop then,

Download and install IP Webcam application on your mobile phone.

Then make sure your PC and Phone both are connected to the same network. Open your IP Webcam application on your both, click “Start Server” (usually found at the bottom). This will open a camera on your Phone.

A URL is being displayed on the Phone screen, type the same URL on your PC browser, and under “Video renderer” Section, click on “Javascript”.

In order to create data transfer we need to write our video streaming in socket programming.

server code:

import socket
import pickle
import cv2

cap = cv2.VideoCapture(0)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # creating socket
ip=”127.0.0.1" # own IP
port=1234 # own port
socket_address = (ip,port)

try:
s.bind((ip,port)) # binding port
print(“Binded”)
s.listen() # waiting for client to connect
print(“LISTENING AT:”,socket_address)

o , addr = s.accept()
print(o)
print(“Connected to {}”.format(addr))
while True: # — — — — — -sending part — — — — — —
ret , photo = cap.read() #
ret, buffer = cv2.imencode(‘.jpg’,photo) # compressing the .jpf file and storing it in the memory buffer that is resized to fit the result
bytedata = pickle.dumps(buffer) # pickle serialises the object file. Serializing and saving it in bytedata
o.send(bytedata) # sending to client
# — — — — — — — receiving part — — — — —
x = o.recv(1000000) # receiving bytes from the socket

data = pickle.loads(x) # serializing back the deserialized data that was received in x.
data = cv2.imdecode(data,cv2.IMREAD_COLOR) # doing reverse of what is done in line 27. Uncompressing and getting the info from memory buffer
if data is not None :
cv2.imshow(‘server’,data)
if cv2.waitKey(10) == 13 :
break

cv2.destroyAllWindows()
cap.release()
except:
cap.release()
cv2.destroyAllWindows()

output of server code

client code:

import socket
import urllib
import json
import pickle
import numpy as np
import cv2

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # creating socket
ip=”127.0.0.1" # IP address of destination
port=1234 # port of destination IP address

s.connect((ip,port)) #creating the connection
#o , addr = s.accept()

cap = cv2.VideoCapture(1)
address=’https://192.168.0.103:8080/video' # using the ip of the external webcam for using it in cap
cap.open(address)

try:
while True:

x = s.recv(1000000) #receiving from the socket connected
print(“Recieved”)

ret , photo = cap.read() # — — — -sending part — — — — — — -
ret, buffer = cv2.imencode(‘.jpg’,photo) # compressing the .jpf file and storing it in the memory buffer that is resized to fit the result
bytedata = pickle.dumps(buffer) # pickle serialises the object file. Serializing and saving it in bytedata
s.send(bytedata) # sending over s socket

try: # — — — — receiving part — — — — — -
data = pickle.loads(x) # serializing back the deserialized data that was received in x.
data = cv2.imdecode(data,cv2.IMREAD_COLOR) # doing reverse of what is done in line 27. Uncompressing and getting the info from memory buffer
if data is not None :
cv2.imshow(‘client’,data)
if cv2.waitKey(10) == 13 :
break
except:
print(“Waiting for the server!”)

cv2.destroyAllWindows()
except:
cv2.destroyAllWindows()

server screen
client screen

This is my second output :

Laptop webcam capturing my wall, My mobile camera is capturing rolled yoga mat ….let’s see the output

Live video streaming snapshot

Now , you can clearly see that “Laptop cam is capturing wall and mobile cam is capturing yoga mat” and the server (Laptop) is viewing yoga mat and client(mobile) is viewing wall.

THANK YOU for reading….This is My INTERNSHIP Task.

Task Description 📄

📌 Create Live Streaming Video Chat App without voice using cv2 module of Python:

on mission: Making India, Future Ready

Thanks to vimal daga sir, and preeti mam

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

--

--