RPi Quadcopter blog

RPi Quadcopter blog
Click to open
Showing posts with label web-cam. Show all posts
Showing posts with label web-cam. Show all posts

Apr 28, 2013

Raspberry PI webcam streaming


How to stream webcam from Raspberry Pi with Raspbian(wheezy) installed.

1. Update apt-get:

$ sudo apt-get update


2. Install required packages:

$ sudo apt-get install libv4l-dev libjpeg8-dev subversion imagemagick uvcdynctrl -y


3. Copy mjpg-streamer code from svn and compile it

$ svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer
$ make USE_LIBV4L2=true clean all
$ sudo make DESTDIR=/usr install


4a. To get the best performing capture and streaming, change cpu governor setting to performance
$ sudo nano /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
erase "ondemand" -row and write "performance" (without quotes)
save and exit with ctrl+o (enter), ctrl+x


4b. Optionally you can set a script to change the cpu governor to performance on boot, because the governor will always change back to ondemand after shutdown

$ sudo nano /etc/local.rc

copy and paste "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" (without quotes)
save and exit with ctrl+o (enter), ctrl+x

do a $ sudo reboot, if you skipped setp 4a.


5. Plug in your USB webcam, if you haven't done so yet and use uvcdynctrl to list it's supported formats.

$ uvcdynctrl -f

To get the best performance, you should only use the formats you see in this list. even fullHD @30fps is using about 5% cpu.


6. Start streaming

Use this, if you did see mjpg listed in the supported formats:

$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
else, add -y flag to the input string:

$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n -y" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"

7. Test it

open http://<RPi IP ADDRESS>:8090/?action=stream with your browser or VLC

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!