Streaming video with a Raspberry PI and a Logitech C270

Hi,

I wanted to setup a live webcam using a Raspberry Pi (model B, first rev. with 256M RAM) so after checking and happily finding out that my camera is suported I went along. First I installed the support packages:

[cce_bash]
sudo apt-get install gstreamer-tools gstreamer0.10-plugins-bad gstreamer0.10-plugins-good v4l-utils

[/cce_bash]

After that I wrote a small script that would start the stream:

[cce_bash]

#!/bin/bash
# set below your Raspberry PI IP address
myip=”192.168.xxx.xxx”
port=”5000″

gst-launch
-v v4l2src !
“image/jpeg,width=1280,height=720,framerate=30/1” !
multipartmux !
tcpserversink host=$myip port=$port sync=false
[/cce_bash]

Save this to a script and set it to start on boot (if you want).

After the stream is running you could check it with VLC for example:

[cce_bash]

vlc tcp://192.168.xxx.xxx:5000

[/cce_bash]

Notes:

  • I got my inspiration from here (the author also has a simple android app for viewing the stream)
  • Yes, I can stream HD with low CPU usage (it starts to hickup after running 7 clients)
  • I couldn’t get audio to work. Maybe it has something to do with this camera as CPU usage is very low. The source blog has details on how to enable audio but I couldn’t get it to work
  • I tried using ffmpeg (if you want audio support remember to install libasound2-dev before compiling ffmpeg) but audio still didn’t work
  • The camera would randomly fail after a few minutes and gstreamer would crash. Because I didn’t want to use a powered USB hub I bridged the polyfuses as described here. If you have the newer rev. 2 (with 512M RAM) that might not be necessary. Do note that this PI has no keyboard, wi-fi dongle or video out and uses a 2A power supply. Now the stream remains stable.

Regenerate SSH keys

I’m a big fan of virtualization. I find it very useful both on my workstation as for the servers. What this means is that I often clone virtual machines to repurpose, run tests or simply add web capacity for load balanced sites. One of the steps is that you have to regenerate the ssh keys (besides the usual suspects that are changing IP, hostname and so on) so you don’t have multiple hosts with the same ssh keys. At least on CentOS and RHEL this simply means removing all the keys from /etc/ssh

[cce_bash]
cd /etc/ssh/
/bin/rm *key*
[/cce_bash]

The init script for SSH will detect that the host keys are missing and will regenerate them. Comment below if this works for other distros!