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

Python provides various libraries for image and video processing. One of them is OpenCV. OpenCV is a vast library that helps in providing various functions for image and video operations. With OpenCV, we can capture a video from the camera. It lets you create a video capture object which is helpful to capture videos through a webcam and then you may perform desired operations on that video.

Steps to capture a video:

  • Use cv2.VideoCapture() to get a video capture object for the camera.
  • Set up an infinite while loop and use the read() method to read the frames using the above-created object.
  • Use cv2.imshow() method to show the frames in the video.
  • Breaks the loop when the user clicks a specific key.

Now, this is the code for running camera on your computer.

What is SSH?

SSH, also known as Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network. In addition to providing secure network services, SSH refers to the suite of utilities that implement the SSH protocol. Secure Shell provides strong password authentication and public key authentication, as well as encrypted data communications between two computers connecting over an open network, such as the internet. In addition to providing strong encryption, SSH is widely used by network administrators for managing systems and applications remotely, enabling them to log in to another computer over a network, execute commands and move files from one computer to another.

What is an X server?

An X server is a program in the X Window System that runs on local machines (i.e., the computers used directly by users) and handles all access to the graphics cards, display screens, and input devices (typically a keyboard and mouse) on those computers.

The X Window System often referred to merely as X, is a complete, cross-platform, and free client-server system for managing GUIs (graphical user interfaces) on single computers and on networks of computers. The client-server model is an architecture (i.e., network design) that divides the work between two separate but linked applications referred to as clients and servers.

In the typical client-server relationship, the client application runs on the local machine. It helps the user request data from the server and displays the requested data appropriately on the user’s display screen. The server application, which processes the data as requested and returns the results to the client, typically can run on either a remote machine (i.e., a computer located elsewhere on the network) or the local machine with no obvious difference to the user (so-called network transparency). When running on a remote machine, the server program can accommodate the requests of multiple clients.

What is X11 forwarding?

In order to enable this, you must log in with,

ssh -X <username>@<host>

SSH supports tunneling of X11 (X-Windows). This is also very useful if you want to open graphical displays from the remote machine on your local computer. To achieve this, an X11 server must be running on your local machine. The X11 connections are then tunneled and automatically encrypted by your SSH client.

In order to enable this, you must log in with,

ssh -X <username>@<host>

SSH supports tunneling of X11 (X-Windows). This is also very useful if you want to open graphical displays from the remote machine on your local computer. To achieve this, an X11 server must be running on your local machine. The X11 connections are then tunneled and automatically encrypted by your SSH client.

Task

Now, to achieve the video chat functionality,

In First System, we will write the program to open the camera.

Then we would allow the access to use our x server by command xhost+

Then we would use the ssh command with the -X option which will enable x11 forwarding.

ssh -X root@192.168.43.243 python3 camera.py

Now, we will do the same in the Second System.

Now, we can see that the two systems have achieved video chat functionality with no audio.

Thank you, for reading this blog.

This is the source code for the above task.

https://github.com/shiv0112/videochat_app

I automate things 😉