How to make a Live streaming Video Calling App with the help of OpenCV library in Python?

Ishita Mittal
3 min readJun 16, 2021

Let’s learn how to do live streaming through cv2 module in python and integrating it with Socket Programming.

We need a Server and a Client as we already know that Live-streaming would only be possible when the client requests a server and in return the server acknowledges the Client back.

Therefore, we use Socket Programming to fulfill the agenda for the client and server and hence made a Client and a Server file wherein the Client gives the IP address and the port number where it has to connect.

For Camera live-streaming app over the network, TCP(Transmission Control Protocol) or IP(Internet Protocol )could be used. This method allows a large piece of information or data let it be in the form of image of burst images forming a video to be transmitted reliably, as it manages how a larger packet being broken into smaller packets to be transmitted and again reassembled in the right order at the the destination without losing the property.

Another known network protocol is UDP (User Datagram Protocol). The use of this protocol is for faster data transmission over a network. However, UDP’s drawback is less reliable compared to TCP/IP as there is always chance of data loss (packet drop).

TCP Server –

  1. using create(), Create TCP socket.
  2. using bind(), Bind the socket to server address.
  3. using listen(), put the server socket in a passive mode, where it waits for the client to approach the server to make a connection
  4. using accept(), At this point, connection is established between client and server, and they are ready to transfer data.

TCP Client –

  1. Create TCP socket.
  2. connect newly created client socket to server.

Step 1: In this task I have used socket programming and cv2 module in python-

cv2 module-

Using the Python-OpenCV module, you can transform the image from color to black-white, from black-white to gray, or from RGB to Hue Saturation and Value. Understand Image types and color channels are essential when working with the cv2 module in Python.

We can think of Images in Python are numpy arrays, and using the cv2 module, we can modify the arrays and transform the images into various forms.

Socket Programming-

Sockets and the socket API are used to send messages across a network. They provide a form of inter-process communication. The network can be a logical, local network to the computer, or one that’s physically connected to an external network, with its own connections to other networks. The obvious example is the Internet, which you connect to via your ISP.

Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while other socket reaches out to the other to form a connection. Server forms the listener socket while client reaches out to the server.
They are the real backbones behind web browsing. In simpler terms there is a server and a client.

I have created two python files client.py and server.py

--

--