Building a Raspberry Pi 2 WebRTC camera
来源:互联网 发布:注册域名 编辑:程序博客网 时间:2024/05/29 08:39
如果网络条件允许,建议看原文。原文地址:http://www.rs-online.com/designspark/electronics/blog/building-a-raspberry-pi-2-webrtc-camera
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.
Hardware used:
- Raspberry Pi 2
- USB Wifi adaptor
- 8GB micro SD card
- Raspberry Pi Camera
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
$ make
$ 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)
[gst-rpwc]
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
Save and exit the editor.
Installing gStreamer and Nginx
gStreamer is a pipeline-based multimedia framework that we will use to encode the video for streaming. To install gstreamer:
$ sudo aptitude install gstreamer1.0
Nginx is a lightweight web server that we will use to serve the Janus demos, specifically the streaming example. To install this:
$ sudo aptitude install nginx
Now copy the Janus HTML content to the Nginx server root:
$ sudo cp -r /opt/janus/share/janus/demos/ /usr/share/nginx/www/
Now start Nginx:
$ sudo service nginx start
Streaming test
Now open two SSH shell sessions logged into the Pi. We will run one command in each shell.
In the first shell execute the following:
$ raspivid --verbose --nopreview -hf -vf --width 640 --height 480 --framerate 15 --bitrate 1000000 --profile baseline --timeout 0 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=8004
This will take video from the camera, format it and pipe it into gStreamer to be H.264 encoded, before sending it on to Janus.
In the second shell navigate to /opt/janus/bin/ and execute:
$ ./janus -F /opt/janus/etc/janus/
This starts the Janus WebRTC gateway.
On a different computer connected to the same network, ensure you running a recent version of Firefox (we are using build 37). Enter the following into the address bar:
http://<IP_of_your_pi>/streamingtest.html
This will load the streaming demo that is bundled with Janus. Click the 'Start' button next to the heading, choose your stream and click 'Watch or Listen' to display the video stream from the Pi directly into your browser!
- Building a Raspberry Pi 2 WebRTC camera
- Building a Raspberry Pi Powered LoRaWAN Gateway
- Raspberry Pi + surveillance camera
- Raspberry PI camera ov5647
- RASPBERRY PI CAMERA MODULE
- Use the Raspberry Pi as a DIY Surveillance camera
- Building a 64bit Docker OS for the Raspberry Pi 3
- Raspberry Pi Camera Streaming to VLC Player
- Booting a Raspberry Pi 2 with u-boot
- Raspberry Pi 2初体验
- Raspberry pi 2 OSMC 安装
- Raspberry pi 2 安装GTK
- Raspberry pi 2网络配置
- RaspberrIPCam – Full HD IP Camera based on Raspberry Pi
- Accessing the Raspberry Pi Camera with OpenCV and Python
- Ubuntu Mate: mak Raspberry Pi camera work without raspi-config on Raspberry Pi2
- Building a WebRTC Client for Android
- 树莓派(raspberry pi)学习2: linux 命令
- C#获取日期汇总
- 【构建Android缓存模块】(三)Controller & 异步图片加载
- SVN服务器客户端以及环境的搭建和使用
- MFC DLL PreTranslateMessage 导致的快捷键不响应的问题?
- 2015年大一下第13周项目1-小玩文件
- Building a Raspberry Pi 2 WebRTC camera
- 期权期货及其他衍生产品
- Android手机屏幕px转dp和dp转px工具类
- UVa 10118 Free Candies
- poj 3254 状压DP
- Add Two Numbers
- 堆的基本操作:定义、创建、插入、删除、排序
- iOS的UIButton和UILable
- CCNA学习指南 网络互联