Raspberry pi streaming webcam

How to build a streaming server with a webcam and a Raspberry pi

Here is described how to obtain a live streaming server with ffmpeg and ffserver using a webcam and a Raspberry; it’ s easy enough. Unfortunately AFAIK, the default ffmpeg should segfault if used for streaming live video feed. For this reason we need to compile it ourselves.

It takes some times (the make command) so be sure to have sufficient time.

Here is the recipe:


  • Configured webcam
  • ffmpeg
  • ffserver.

ffmpeg verbose and streaming window
ffmpeg verbose and streaming window

How to cook:

We need to install ffmpeg, but as told we need to compile from sources, and for this reason we need to modify the aptitude package manager sources list files:
Add the following lines into /etc/apt/sources.list

deb-src http://www.deb-multimedia.org wheezy main
deb http://www.deb-multimedia.org wheezy main non-free

In a previous article the first of the two apt repos listed in the modifications above was pointing to Sid. I have done the procedure again and this time i used Wheezy, it works, so i updated this part. And the reader is invited to do so.

then run:

apt-get install deb-multimedia-keyring
apt-get update

Remove or comment the second line from /etc/apt/sources.list

#deb http://www.deb-multimedia.org wheezy main non-free

then run:

apt-get source ffmpeg-dmo

Check for the actual version and go into the newly created dir:

cd ffmpeg-dmo-0.11


Now (2013-01-15) is:

cd ffmpeg-dmo-1.0.1

then run

./configure --enable-filter=movie --enable-avfilter
sudo make install

If you concatenate the commands together and use them as root, you have enough time to get a coffee…outside.
Concatenated commands (if you used the three commands before you don’t need to do this!)

./configure --enable-filter=movie --enable-avfilter && make && make install


Sudo is needed if you are NOT root.
We need to create a configuration file for ffserver, we will place it in /etc/ and call it ffserver.conf

The content of this file will be as follows:

Port 80
MaxClients 10
MaxBandwidth 50000
CustomLog -
<Feed feed1.ffm>
file /tmp/webcam.ffm
FileMaxSize 10M
#We are going to use flash format (sorry internet explorer and iphone/pad/pod/whatever)
<Stream test.swf>
Feed feed1.ffm
Format swf
VideoFrameRate 4
VideoSize 320x240
VideoBitRate 64
VideoBufferSize 10
VideoQMin 6
VideoQMax 31

<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow
#FaviconURL http://blog.giuseppeurso.net/favicon.ico

# Redirect index.html to the appropriate site

<Redirect index.html>
URL http://blog.giuseppeurso.net/

Please, note the port 80 is in use, you can change it for a more convenient port if, 8080 for example, you already have a webserver instance running listening on that port.
Although the producer claims a resolution of 720, i know for sure it is interpolated by the poor chip of the camera, degradating the resulting quality. That’s why you will have better results if you use a resolution as close as possible with the camera native resolution.
Also, keep in mind that this parameter and the framerate & bitrate values can determine a bad quality stream.

Now it’s time to start ffserver with the command

ffserver -f /etc/ffserver.conf &

executed as root: this will start ffserver and send it in background.

Then we need to start capturing the video with ffmpeg and transmit the feed to ffserver with the configured path

ffmpeg -v verbose -r 15 -s 320x240 -f video4linux2 -i /dev/video0 http://localhost/feed1.ffm &

You are advised to save this command into an .sh shell script file , chmod +x and then you can use a single word command to star streaming or, better, you can do a startup script for this task.

An ideal startup shell script would do:

killall ffserver
killall ffmpeg
ffserver -f /etc/ffserver.conf
ffmpeg -v verbose -r 10 -s 352x240 -f video4linux2 -i /dev/video0 http://localhost/feed1.ffm &

Last step:
Point your browser to the Raspberry IP address specifying protocol and port as follows:



(Visited 16,268 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

11 thoughts on “Raspberry pi streaming webcam”

  1. Hi,
    I really liked your article and would like to replicate it. However, I’m having trouble building ffmpeg..it takes waaay too long. I was wondering if you could perhaps upload your prebuilt binaries?

  2. Thanks for this great tutorial. Any suggestions on how to mux in a live stream from a microphone as well?

  3. Hi thank you for your great tutorial.
    Little question,Is it possible to stream with another format than swf?

  4. Hi, Thanks for your tutorial☺. I’m trying to stream video and sound from a USB webcam, conected to my raspberry pi, to youtube and record the output video into the sd card. To do this I’m using ffmpeg but the result it’s not good because de quality video is low. I’m wondering that it’s possible make these at the same time?? Can you help me please? Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.