Using Janus and gStreamer to feed video straight into the browser.
WebRTC enables browser-based Real Time Communications (RTC) via simple APIs. It is royalty free and powerful. We can use Janus, a general purpose WebRTC gateway, to stream video from a Raspberry Pi directly to browsers, without having to install any extra software on client machines.
We will use a gStreamer pipeline to take the video output from a Raspberry Pi camera module and encode the video in H.264 format before passing it on to Janus.
- Raspberry Pi 2 (832-6274)
- USB Wifi adaptor (760-3621)
- 8GB micro SD card (666-1689)
- Raspberry Pi Camera (775-7731)
Initial Raspberry Pi setup
To begin with we will assume that:
- you are running the latest version of Raspbian (version ‘January 2015’ at time of writing).
- you have a Raspberry Pi camera module attached.
- the network is configured and you can SSH into the Pi.
First we will enable the Pi camera module:
- $ sudo raspi-config
- Choose ‘Enable Camera‘ and press return
- Save and quit raspi-config
Testing the camera
Now that we have enabled the camera module we can test that it is working correctly using the command line tool raspistill.
$ raspistill -o test.jpg
This should have taken a photo. Type ls to see if test.jpg has appeared in your directory.
Copy this photo over to your local machine and open it with an image viewer. If it needs rotating you can use the options -vf and -hf for vertical and horizontal flipping when taking the photo. E.g:
$ raspistill -vf -hf -o test2.jpg
Once you are happy the camera is working and you know which extra options to use we can move on to getting the camera streaming video over the network.
Setting up Janus
It is worth taking a look at the Janus GitHub repository for some background information and to assist with installation.
First make sure your Apt cache is up to date:
$ sudo aptitude update
Next we need to install build dependencies as follows:
$ sudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev libssl-dev libsrtp-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev libini-config-dev libcollection-dev pkg-config gengetopt libtool automake dh-autoreconf
We will not be making use of Data Channels, WebSockets or RabbitMQ so we don’t need to install the optional dependencies.
Next we can clone the repository onto the Pi, build and install:
$ git clone https://github.com/meetecho/janus-gateway.git
$ cd janus-gateway
$ sh autogen.sh
$ ./configure –disable-websockets –disable-data-channels –disable-rabbitmq –disable-docs –prefix=/opt/janus
$ sudo make install
Now run a comand to install default configuration files:
$ sudo make configs
Next modify /opt/janus/etc/janus/janus.plugin.streaming.cfg (we will use nano but you may use an editor of your choice):
$ sudo nano janus.plugin.streaming.cfg
Add the following lines (and comment out the other example streams by adding a semicolon before each line)
type = rtp
id = 1
description = RPWC H264 test streaming
audio = no
video = yes
videoport = 8004
videopt = 96
videortpmap = H264/90000
videofmtp = profile-level-id=42e028\;packetization-mode=1
Read More: Building a Raspberry Pi 2 WebRTC camera