RPi Quadcopter blog

RPi Quadcopter blog
Click to open

May 24, 2011

How to set up a webcam stream in Ubuntu

1. Download and install ffmpeg
2. Edit ffserver.conf
3. Start streaming

1. Download and install ffmpeg

It is important to get the latest (even RC) version of ffmpeg, because version 0.6.3 (the current stable) doesn’t work. I used FFmpeg 0.7-rc1 in this example.

Before installing new version, remove the old one:

$ sudo apt-get remove ffmpeg


Download and extract the tarball.
Open terminal (ctrl+alt+t) and type these commands to install:

$ cd /extracted/folder/ffmpeg-0.7-rc1
$ ./configure
$ make
$ sudo make install



2. Configuring

Open /etc/ffserver.conf with gedit. In this example i used flash to stream:



Port 8090
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
NoDaemon


###############################################################
# FEED

File /tmp/myfeed.ffm
FileMaxSize 5M
# allow only localhost to stream
ACL allow 127.0.0.1

# this starts the stream automaticly:
#Launch ffmpeg -r 15 -s 640x480 -f video4linux2 -i /dev/video0



##################################################################
# FLASH STREAM

Feed myfeed.ffm
Format swf
VideoCodec flv
VideoFrameRate 15
VideoBufferSize 80000
VideoBitRate 100
VideoQMin 1
VideoQMax 5
VideoSize 640x480
PreRoll 0
Noaudio



###################################################################
# Redirect index.html to the appropriate site
URL http://www.ffmpeg.org/


3. Start streaming

Start the ffserver:

$ ffserver


Start ffmpeg:

$ ffmpeg -r 15 -s 640x480 -f video4linux2 -i /dev/video0 http://localhost:8090/myfeed.ffm


-r 15 = frame rate 15fps (must be same as in config)
-s 640x480 = width x height
-f video4linux2 = format
-i /dev/video0 = the location of your web-cam.
http://localhost:8090/myfeed.ffm is the output.

If there were no errors, open the stream: http://localhost:8090/mystream.swf

Optionally you can comment out this row and just run ffserver
#Launch ffmpeg -r 15 -s 640x480 -f video4linux2 -i /dev/video0


Last words

I used several hours googling and trying everything to fix some weird errors without succeeding. Solution was to download the LATEST version. So for “segmentation fault”, “streams doesn’t match” or “pixel format” errors, try installing the latest version of ffmpeg!

3 comments:

  1. how about adding audio

    ReplyDelete
  2. Does not work ....
    ffmpeg version git-2012-10-12-e335658
    [video4linux2,v4l2 @ 0x3764440] Cannot find a proper format for codec_id 0, pix_fmt -1.
    /dev/video0: Input/output error
    Webcam on video0 works flawlesly....

    ReplyDelete
  3. It`s not working, is not a correct how to.
    Just avoid to configure iit.

    ReplyDelete