RPi-Streamer
Containerized video/audio streaming server made deployable via Docker. Connect a RPi camera module to a streaming server to capture video using rtsp/rtmp/rtp protocols. Optionally connect a USB microphone for audio streaming.
The following container heavily utilizes the Camera and Server libraries created by @iizukanao.
Pre-requisites
Equipment
Prepare the following:
- Raspberry Pi (2, 3 or Zero)
- Raspberry Pi Camera Module
- USB Microphone (Optional)
- SD Card w/ Jessie OS (Instructions here)
Enable Camera
Use the following command to open the Raspberry Pi configuration interface:
sudo raspi-config
Select Interfacing Options > Camera > Yes. Then select Finish and reboot device when prompted.
Enable USB Microphone (Optional)
Plug in USB Microphone. If the Raspberry Pi device is turned on, reboot the device.
Run arecord -l
and make sure that USB microphone device is detected. Below is an example output indicating that a device was detected. Note the USB device name in this particular output is AK5370.
**** List of CAPTURE Hardware Devices ****
card 1: AK5370 [AK5370], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
The example output also indicates card 1 (default) as the capture index. Card index may be different if more than one capture devices are attached to your Raspberry Pi. If the value is not card 1, the input flag hw:1,0
must be updated in the ./picam --alsadev hw:1,0 --rtspout -w 1136 -h 640
command line in /root/bin/startup.sh
. The value will be hw:2,0
for card 2, hw:3,0
for card 3 and so on.
Install Docker
Run the following command:
$ curl -sSL get.docker.com | sh
Make sure you're logged in as has enough access to run docker. Below is a command that adds user pi to the docker group:
sudo usermod -aG docker pi
Logout and log back into the device to have the command above take effect.
Prepare RTP/RTMP/RTSP Client
Use a client such as VLC (Mac/Win), FFMPEG (Linux), and RTSP Player (iPhone) to view the media broadcasted from the Raspberry Pi.
Usage
$ docker run -dit --rm --privileged \
-v /dev/snd/pcmC0D0p:/dev/snd/pcmC0D0p \
-v /dev/snd/pcmC1D0c:/dev/snd/pcmC1D0c \
-v /dev/snd/controlC0:/dev/snd/controlC0 \
-v /dev/snd/controlC1:/dev/snd/controlC1 \
-v /opt/vc/lib:/opt/vc/lib \
--device /dev/vchiq \
-p 8888:8888 \
groundhogday/rpi-streamer:latest
Command Breakdown
- -dit detatch interactive tty mode to enable ssh interfacing
- --rm Remove process when the image is stopped/quits
- --privileged Allow use of host device such as USB microphone
- -v /dev/snd/* Uses host USB Volumes
- -device /dev/vchiq/ Uses RPi Camera
- -p 8888:8888 Forward Host port 8888 (left side) to the container's port 8888 (right side)
Monitor Startup
Run docker logs <container_id>
to monitor the container's startup. Determine the container's ID by running docker ps
.
The line [rtsp] internal stream name has been set to: live/picam
indicates a succseeful startup.
Review the log below as an example of a successful startup output.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b30e6d547d9 groundhogday/rpi-streamer:latest "/root/bin/start.sh" 39 seconds ago Up 35 seconds 0.0.0.0:8888->8888/tcp suspicious_booth
$ docker logs suspicious_booth
Using server port 8888
Starting streaming server
... waiting 30 seconds for streaming server to come up
... waiting 30 seconds for streaming server to come up
$ docker logs suspicious_booth
Using server port 8888
Starting streaming server
... waiting 30 seconds for streaming server to come up
... waiting 30 seconds for streaming server to come up
... waiting 30 seconds for streaming server to come up
... waiting 30 seconds for streaming server to come up
... waiting 30 seconds for streaming server to come up
2017-06-15 22:22:30.724 attachRecordedDir: dir=file app=file
2017-06-15 22:22:31.071 [rtmp] server started on port 1935
2017-06-15 22:22:31.079 [rtsp/http/rtmpt] server started on port 8888
Starting Pi Cam...
created directory: ./rec/tmp
configuring devices
2017-06-15 22:22:59.318 [custom_receiver] new connection to VideoData
2017-06-15 22:22:59.335 [custom_receiver] new connection to VideoControl
2017-06-15 22:22:59.344 [custom_receiver] new connection to AudioData
2017-06-15 22:22:59.350 [custom_receiver] new connection to AudioControl
capturing started
2017-06-15 22:22:59.705 [rtsp] internal stream name has been set to: live/picam
Viewing Stream
Use a client such as VLC to view the stream by using the following address:
rtsp://<Host_IP>:8888/live/picam
The Host_IP is the address of the Raspberry Pi hosting the container and not the container itself.
Customization
Camera options
Visit the picam author's page to see available options.
These options may be added to the line ./picam --alsadev hw:1,0 --rtspout -w 1136 -h 640
in /root/bin/startup.sh
.
Streaming Options
Configurations such as ports, path, and bitrate can be found in /root/node-rtsp-rtmp-server/config.coffee
.