Broadcast video from Raspberry Pi

For so long, I became the proud owner of a Raspberry Pi. Since then, experiments have not stopped. Now I'm messing with the camera. In this regard, I wanted to implement the broadcast. I hope this article will be useful to newcomers like me.

image

There are several ways of varying degrees of complexity to organize the broadcast of video from the Raspberry Pi camera. It all depends on where exactly you need to receive the broadcast. Consider some of the options, moving from simple to more complex.

VLC media player


The easiest way to organize the broadcast of video from the Raspberry Pi camera is to install the VLC media player on both the computer and the raspberry. The latter is done by the following command:

sudo apt-get install vlc -y

After that, we start recording video and broadcasting it. In the example below, a video with a size of 800 by 400 pixels and a frequency of 24fps will be broadcast in h264 format via port number 8160:

raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264

We start VLC on the computer, select "Open URL" from the menu and enter 192.168.0.9 : 8160 (replace 192.168.0.9 with the real IP address of your Raspberry Pi). If you install VLC on an Android device, then this method also works. However, for smartphones there is a more convenient way.

Raspicam remote




This is a more convenient way - the RaspiCam Remote application . Firstly, it does not require installing anything additional on the Raspberry Pi (when using the basic functions). Secondly, no manipulations with the start of shooting, as in the previous example, are also required. Also, the application allows you to apply filters to the picture (if I understood correctly, on the side of the Raspberry Pi) and save pictures to the phone’s gallery. For some additional functions, you need to install a couple of third-party applications on the "raspberry". In particular, for video broadcasting with a frequency of 30fps, VLC will be required, and fswebcam for using a UBS-camera. In any case, the application is simple and useful, which is what I liked. In addition, this is one of the easiest ways to test if the camera is working.

Web Browsing


Actually, we came to the most important thing. There is no browser now on almost any device connected to the Internet. Broadcasting to the browser is the most popular way. Considering that different web browsers are still determined with which video formats they play and which ones do not, it makes no sense for us to communicate with the video in the literal sense. An additional argument is the lack of a microphone on the “raspberry” camera and, as a result, the sound track as such. Therefore, it is most reasonable to take a photo, not a video. The mechanism is simple: the standard raspistill commandwe take pictures with an interval and save in one file, constantly rewriting it. We also install a web server on the Raspberry Pi, on which we launch a web page with our photo. It is clear that the photo needs to be updated at the same interval with which shooting is being done (ideally). You can do this, for example, with Javascript:

setInterval(function(){
    $("#cam_image").attr("src", "output.jpg?time="+new Date().getTime());
},250);

The time in the time variable in this case is only transmitted in order to avoid caching the image.

If you are far from web programming, there is an excellent turnkey solution - RPi-Cam-Web-Interface . This is a whole package that installs and configures everything you need (including the server) and gives a website on the local server with a camera image and a huge number of settings (up to the ability to restart or turn off the Raspberry Pi). In addition, this package uses Motion software and supports Pi-Pan and Pi-Light devices, if any.

Before installing RPi-Cam-Web-Interface, it is mandatory to update the system with the sudo rpi-update commandand reboot. After that you need to download the distributive:

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
chmod u+x RPi_Cam_Web_Interface_Installer.sh

RPi-Cam-Web-Interface uses Apache as a server and therefore installs it. For example, I do not need it, since I prefer lighttpd , which I already have installed. In this case, I open the script file and remove the installation of Apache from the instructions.

sudo nano ./RPi_Cam_Web_Interface_Installer.sh

There you can change the directory in which the site will be installed. Now you can start the installation:

./RPi_Cam_Web_Interface_Installer.sh install

After its completion, we reboot and now, if you type the IP of your “raspberry” in the browser, a page with the camera image and settings will open. By default, the application starts automatically. You can disable it and run it manually. Here is a list of commands:
  • ./RPi_Cam_Web_Interface_Installer.sh autostart_yes - enable autoload
  • ./RPi_Cam_Web_Interface_Installer.sh autostart_no - disable startup
  • ./RPi_Cam_Web_Interface_Installer.sh start - manual start
  • ./RPi_Cam_Web_Interface_Installer.sh stop - manual shutdown
  • ./RPi_Cam_Web_Interface_Installer.sh remove - remove RPi-Cam-Web-Interface and all additional applications

Read more about this package here and here .

Also popular now: