Reviewed by Editor: Jack Allison
Raspberry Pi Camera modules:
– Daylight (ebay)
– Infra-red sensitive Pi NoIR module (ebay): PiNoIR
Installation
– Install picamera python library:
Installation command:
sudo apt-get install -y python-picamera
Optional command (for development in python version #3 and up):
sudo apt-get install python3-picamera python-rpi.gpio
You will be able to start using the camera (directly from terminal command line or by some minimal Python scripting) with the help of the links provided below.
Find my usage in the descriptions of my experiments in this blog.
Streaming video to Web
Note: To me using nc (Netcat) appeared as best network+cpu performance option with highest resolution being transmitted and displayed on RPi with less possible delay/glitches/hangs.
Upgrade your RPi before any streaming approach you will chose
sudo apt-get update sudo apt-get dist-upgrade sudo rpi-update
Streaming to youtube
- to have /dev/video0
sudo modprobe bcm2835-v4l2 chmod 666 /dev/video0
- to stream to youtube you will need your personal channel code in format: username.xxxx-xxxx-xxxx-xxxx
raspivid -o - -t 0 -vf -hf -w 1280 -h 720 -fps 20 -b 4000000 -g 50 | ./ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv -force_key_frames 'expr:gte(t,n_forced*2)' rtmp://a.rtmp.youtube.com/live2/<your personal channel in format: username.xxxx-xxxx-xxxx-xxxx>
Streaming using VLC (RPi can NOT serve receiving side: suffocated)
– Install VLC player
sudo apt-get install vlc
– To start streaming, type the following at shell command-line:
raspivid -o - -t 0 -n -w 640 -h 480 -f 20 |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8080}' :demux=h264
– Now you should be able to receive your stream by VLC’s ‘Open Network Stream’ menu-command by using the following URL: http://<RPi_IP>:8080/
To be able to receive this stream through WEB login into your router and edit Network Address Translation (NAT) parameters. You will need to define a Virtual Server so that remote users accessing services such as the Web or FTP at your local site via Public IP Addresses can be automatically redirected to local servers configured with Private IP Addresses. In other words, depending on the requested service (TCP/UDP) port number, the Broadband router redirects the external service request to the appropriate internal server (located at one of your LAN’s Private IP Address).
– What remained is to detect which IP address is assigned to your home router at WAN. This may be done by the following command:
ping -r 4 www.google.com
You will notice that first address appearing in this ping trace that doesn’t rel;ate to your LAN is fixed while the rest change between pings.
– You can use this fixed Web IP address to access your RPi stream with VLC UI or command line:
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "http://<RPi_Web_IP>:8080/"
Streaming RPi to RPi using Netcat (nc)
Streaming side on the RPi camera:
TCP: raspivid -t 0 -w 1280 -h 720 -vf -ih -fps 10 -o - | nc -k -l -p 2222
or
TCP: raspivid -t 0 -w 1280 -h 720 -vf -ih -fps 10 -o - | nc <IP-OF-THE-CLIENT> 2222
UDP: raspivid -t 0 -w 1280 -h 720 -vf -ih -fps 10 -o - | nc -u <IP-OF-THE-CLIENT> 2222
Receiving side on the RPi HDMI display:
TCP: nc -l 2222 | mplayer -fps 20 -demuxer h264es -
UDP: nc -lu 2222 | mplayer -fps 20 -demuxer h264es -
Streaming RPi to RPi using UV4L
Relatively good performance, but the motion with Netcat is much more fluent)
– Camera side:
wget http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc sudo apt-key add ./lrkey.asc
sudo nano /etc/apt/sources.list
add the following line to /etc/apt/sources.list
deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main
update
sudo apt-get update
install uv4l
sudo apt-get install uv4l uv4l-raspicam uv4l-raspicam-extras uv4l-server uv4l-uvc uv4l-xscreen uv4l-mjpegstream
reboot
and then start the server
sudo pkill uv4l sudo uv4l -nopreview --auto-video_nr --driver raspicam --encoding mjpeg --width 640 --height 480 --framerate 20 --server-option '--port=9090' --server-option '--max-queued-connections=30' --server-option '--max-streams=25' --server-option '--max-threads=29'
Recieving side. In Internet Browser use the following address:
http://<Your public IP>:9090/stream
Streaming RPi to RPi using GStreamer (bad frame-rate and image quality)
– Installing gstreamer1.0
Add the Following line to /etc/apt/sources.list (to open editor: sudo nano /etc/apt/sources.list)
deb http://vontaene.de/raspbian-updates/ . main
Then update rpi again
sudo apt-get update
Install gstreamer
sudo apt-get install gstreamer1.0
For proper Installing of Gstreamer on the receiving side (Debian Jessie in my case). This is essential to have all components of matching versions and to avoid segmentation faults (SIGSEGV)
apt-get install libgstreamer1.0-0 libgstreamer1.0-0-dbg libgstreamer1.0-dev liborc-0.4-0 liborc-0.4-0-dbg liborc-0.4-dev liborc-0.4-doc gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-doc gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-bad-dbg gstreamer1.0-plugins-bad-doc gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-base-dbg gstreamer1.0-plugins-base-doc gstreamer1.0-plugins-good gstreamer1.0-plugins-good-dbg gstreamer1.0-plugins-good-doc gstreamer1.0-plugins-ugly gstreamer1.0-plugins-ugly-dbg gstreamer1.0-plugins-ugly-doc gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-x libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-0 libgstreamer-plugins-base1.0-dev
Streaming side on the RPi camera:
raspivid -t 0 -b 5500000 -n -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! udpsink port=5000 host=HOST_IP_ADDR
Receiving side on the RPi HDMI display:
gst-launch-1.0 -v udpsrc address=HOST_IP_ADDR port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false
!!! DON’T FORGET: before you publish that RPi_Web_IP, change your router’s password to some value known only to you to prevent intervention of strangers.
Recommended References:
- Camera Setup and Command Line Interface
- Python: pycamera module API
- Video Capturing: command line
- Video Streaming with VLC (http/rtsp): summary
- Video with HTML5
- Reference project: surveillance camera (details)
- Reference project: Solar WiFi camera
- Reference project: 1 2 3 4 5 6
Pingback: Raspberry Pi Experiment 03: Streaming to Web | My Hobby of 'Making'
Pingback: Raspberry Pi Experiment 01: PiCam Video Streaming via WiFi | My Hobby of 'Making'
Pingback: Raspberry Pi Experiment 02: PiCam video streaming through cellular network 3G/GSM | My Hobby of 'Making'
Pingback: Raspberry Pi Experiment 03: Streaming using HTTP | My Hobby of 'Making'
Pingback: Raspberry Pi Experiment 04: Adaptive streaming | My Hobby of 'Making'