Monday, June 17, 2024

Raspberry Pi Projects: Live Streaming Using Raspberry Pi Development Board

EFY TestedImagine you are talking to your friend who works in another country and at the same time you are streaming your plush drawing room images to him or her on the computer. For streaming images you would need an Internet connection and then use of the port-forwarding technique explained in this article.

But, is it a big deal? Skype or a similar messaging program does the same thing through the Internet. The only difference is that the process presented here is simple and has minimum footprint or load on bandwidth.

Port forwarding, or live streaming, allows the network to flow contents of a defined port to the outside world. It allows network administrators to use one IP address for all external communications on the Internet. It is useful for home network users who may wish to run a Web server or gaming server on network.

How to get started

You need a Windows or Linux computer with a camera and an old mobile phone with an Internet connection to live stream your video over the Internet. You can also use Raspberry Pi (Raspi) in place of a computer.

For testing live-streaming videos using Raspi with Raspbian OS, use Motion software and configure motion.conf file as explained below.

- Advertisement -

Get the software ready. To start with, you should have a working Raspi on a local network with Internet access.

Next, update Raspi using the following commands. This ensures that you have the latest software and drivers installed.

 [stextbox id=”grey”]$sudo apt-get update
$sudo apt-get upgrade[/stextbox]

- Advertisement -

Install Motion. We use a fairly lightweight application known as Motion, which is capable of accessing the USB camera, getting images and streaming these via the built-in Web server. Motion can also track and trigger events when motion is detected in video frames.
[stextbox id=”grey”]$sudo apt-get install motion[/stextbox]

Plug in webcam. Plug in the webcam and ensure that everything is working fine by typing lsusb command. The name of your webcam manufacturer should be visible on the terminal, which means Raspi has recognised your webcam.
[stextbox id=”grey”]$lsusb[/stextbox]

Configure software. Now, basic configurations are required in motion.conf file as follows:
sudo nano /etc/motion/motion.conf

• Daemon = off to on
• width 640
• height 480
• framerate 30
Go to # Live Webcam Server section and make the following changes:
• webcam_localhost = on to off
• webcam_port 8081
• webcam_quality 50
• webcam_maxrate 15 (if you have good bandwidth, you can make this 30)

Start software. To ensure that Motion service actually starts as a daemon, change configuration setting as given below.
[stextbox id=”grey”]$sudo nano /etc/default/motion[/stextbox]

Change, value start_motion_daemon=no to yes
Now, you can start Motion service to stream webcam images by typing the following command:
[stextbox id=”grey”]$sudo service motion start[/stextbox]

After about 30 seconds, browse a Web interface using a web browser, say, Mozilla Firefox, on the same computer or another computer on the same network, and enter the IP address along with the port number of your Raspi, say, http://192.168.123.100:8081

If you can see the live-streaming video, it means everything is working fine on the network.

Port forwarding

Now, try to access the live-streaming video from any other available network using port forwarding. To enable this on your home broadband router for Raspi on port 8081, follow the steps given below.

A router provides the route between the Intranet and the Internet. Most routers are set to work one way, although almost all routers have provision to work both ways. The most-popular route set to operate is from the Internet to the Intranet. For example, you are watching a Web page and sending mail, and all traffic is from the outside world to the inside.
In almost all router administration pages, there is port-forwarding facility that helps create the traffic route, which allows driving of contents from the Intranet to the Internet.
The router does not see which computer to use for reverse traffic flow; it only sees which port to allow for traffic flow.

Open Advanced page (of your modem or router’s administration page) and click on Port Forwarding.

Set the port (say, 8081, 8082, 5678, 8083 and so on) and associate the IP address of Raspi. This port will drive its contents to the Internet. In our case, anyone can view the contents by calling public IP address along with port 8081.

But the problem still remains—which computer’s IP address should be entered on the browser page?

For that, find out the IP address of the modem or router obtained from the Internet service provider at that point of time. For that, go to the status page of router again and find out its external IP address (say, http://a1.a2.a3.a4). This is your public IP address.
Now, you can share this IP address along with the port number with your friend. He or she can enter this IP address plus port number on the browser to access your live-streaming video.

Note that, this IP address may undergo changes many times in a day, as most home connections have a dynamic public IP address. So keep track of it before enabling port forwarding.

Author’s old mobile phones connected to a laptop for live streaming
Author’s old mobile phones connected to a laptop for live streaming

The easiest way to get an external IP is to use an old mobile with a SIM card along with an Internet pack, and go online. Run ifconfig at command prompt; you will get the external IP address for the laptop or Raspi.

The old mobile acts as a modem to get connected with the Internet for reverse traffic flow. Since the modem in the phone is primitive in nature, it has no firewall. When an old mobile is connected to the Internet it gets a public IP address (202.54.x.x or 132.56.x.x) unlike 192.168.x.x or 10.10.1.2.

In short, if your friend wants to access your live-streaming video through your computer, he or she can type, say, http://a1.a2.a3.a4:8081 on the browser or VLC player of his or her computer or mobile phone. And you can talk on your old phone as you look at the live-streaming video on your computer.

You may also like these DIYs: click here


Somnath Bera is an avid user of open source software. Professionally, he is a thermal power expert and works as additional general manager at NTPC Ltd

SHARE YOUR THOUGHTS & COMMENTS

Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators

×