User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Webcam Server

Thu Aug 02, 2012 1:50 pm

Hi all,

I'm running the latest version of Debian Wheezy, with apache2 and php5 installed.

I want to put my webcam, /dev/video0, onto localhost:port.

Aim:
In a webpage hosted by the pi, have the video feed, <img src=localhost:port>
Be able to view the webcam from any PC by typing into the browser http://"ip address:port"

Obviously replace localhost, port and ip address with some numbers!

This is do-able with ffstream but far too complicated for my ability. mjpg-streamer is ideal, I have used this in ubuntu, but I can't get it to compile from source from the pi, "fatal error: videodev.h not found", or find it in apt-get.

Any ideas/help?

Cheers,

Simon

Shdwdrgn
Posts: 39
Joined: Sun Jul 29, 2012 3:13 am

Re: Webcam Server

Thu Aug 02, 2012 10:35 pm

You want to install "motion". Setup is real easy with a cheap USB webcam, and it has it's own webserver built in. By default it will play the camera video on http://localhost:8081 but you can change the port number in the config file, and enable the port to be accessed from other computers. Video capture can be saved in a number of formats and also made available.

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Re: Webcam Server

Fri Aug 03, 2012 6:57 am

Thanks for the reply. Motion works fine but its unbelievably slow, using most of the bandwidth for motion detection...getting 1.5-2Hz.

I need something considerably quicker. Ive had a suggestion to use deb-multimedia ffmpeg source and use this guide? http://sirlagz.net/?p=357

User avatar
joan
Posts: 14892
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Webcam Server

Fri Aug 03, 2012 7:45 am

Can you just switch off motion detection in motion? I had a feeling you could but it's years since I've used the package.

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Re: Webcam Server

Fri Aug 03, 2012 8:18 am

You can turn off the output, but the programme still executes the motion code all the time...irritating.

I'm trying to build ffstream from source now (to overcome the seg fault on wheezy):
THIS:
http://www.raspberrypi.org/phpBB3/viewt ... =66&t=9045
THEN:
http://sirlagz.net/?p=357

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Webcam Server

Fri Aug 03, 2012 1:59 pm

How is this going for you ?
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Webcam Server

Sun Aug 05, 2012 4:04 pm

Can't edit the last post, but for anyone who wants to do this - I have written up a new guide.
http://sirlagz.net/?p=493
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 7:49 am

Nice one. Going OK, getting about a 14 sec delay and its only stable at qvga. Pretty poor considering the pi can do HD for videos.
I'll post my config and execute when I get to work. I browsed through the ffmpeg documentation, position of flags in the execute stream is much more important than first thought. Buffer sizes I've been playing about with too and makes a big difference to delay.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 8:02 am

buffer and bit rate made a huuuuuge difference on mine.
mine had a delay of about an hour for a while before I played around with my settings :D

I ended up with a bitrate of 2000 ? I think it was, with qvga resolution.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 11:04 am

Getting about a 14s delay. Any ideas how to improve?

Here is my ffserver.conf:

Code: Select all

Port 8080
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon

<Feed webcamFeed.ffm>
        file /tmp/webcam.ffm
        FileMaxSize 512k
        acl allow 127.0.0.1
</Feed>

<Stream webcamStream.mpg>
        Feed webcamFeed.ffm
        Format mpeg
        VideoBitRate 64
        VideoSize qvga
        NoAudio
</Stream>
and the executable:

Code: Select all

ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -r pal -f video4linux2 -i /dev/video0 -r pal -bufsize 1835k -an http://localhost:8080/webcamFeed.ffm

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 12:25 pm

I am making some slow progress.

The video runs very smooth for about 1sec, then pauses for about 3s while it buffers, then smooth for 1s...and so on. There doesn't seem to be any continuous streaming, just discrete large packets every 4 secs. Makes me think this is an ffserver problem rather than ffmpeg??

Any thoughts?

ffserver.conf:

Code: Select all

Port 8080
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 10000
NoDaemon

<Feed webcamFeed.ffm>
        file /tmp/webcam.ffm
        FileMaxSize 10M
        acl allow 127.0.0.1
</Feed>

<Stream webcamStream.mpg>
        Feed webcamFeed.ffm
        Format mpeg
        VideoBitRate 5000
        VideoSize 640x480
        VideoQMin 10
        VideoQMax 20
        NoAudio
</Stream>
Executable:

Code: Select all

ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -an -f video4linux2 -i /dev/video0 -r pal -b:v 10M -an -q:v 15 http://localhost:8080/webcamFeed.ffm
Echo after about 20secs running (ignoring the first 20sec):

Code: Select all

*** 9 dup!7 fps=8.5 q=2.0 size=    1436kB time=00:00:24.50 bitrate= 480.2kbits/s dup=656 drop=0
*** 26 dup! fps=8.5 q=2.0 size=    1460kB time=00:00:24.83 bitrate= 481.6kbits/s dup=665 drop=0
*** 39 dup! fps=8.4 q=2.0 size=    1512kB time=00:00:25.76 bitrate= 480.7kbits/s dup=691 drop=0
*** 10 dup!
*** 95 dup! fps=8.6 q=2.0 size=    1596kB time=00:00:27.46 bitrate= 476.0kbits/s dup=740 drop=0
*** 7 dup!2 fps=9.4 q=2.0 size=    1756kB time=00:00:30.66 bitrate= 469.1kbits/s dup=835 drop=0
*** 38 dup! fps=8.6 q=2.0 size=    1780kB time=00:00:30.93 bitrate= 471.4kbits/s dup=842 drop=0
*** 104 dup!fps=8.9 q=2.0 size=    1844kB time=00:00:32.23 bitrate= 468.6kbits/s dup=880 drop=0
*** 10 dup! fps=9.4 q=2.0 size=    2028kB time=00:00:35.73 bitrate= 464.9kbits/s dup=984 drop=0
*** 74 dup! fps=8.7 q=2.0 size=    2048kB time=00:00:36.10 bitrate= 464.7kbits/s dup=994 drop=0
*** 129 dup!fps=9.2 q=2.0 size=    2172kB time=00:00:38.60 bitrate= 461.0kbits/s dup=1068 drop=0
*** 105 dup!fps=9.6 q=2.0 size=    2388kB time=00:00:42.93 bitrate= 455.6kbits/s dup=1197 drop=0

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 1:50 pm

try this to see if it's ffmpeg or ffserver

Code: Select all

ffmpeg -v verbose -an -f video4linux2 -i /dev/video0 -r pal -b:v 10M -an -q:v 15 temp.mpeg
let that go for about a minute, then play it back on another computer and see if it's smooth...
When I was streaming, I was using mjpeg so maybe that's easier for the Pi to use ?
Hows the CPU usage when you're trying to stream ?
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Webcam Server

Mon Aug 06, 2012 2:32 pm

Can't edit last post =/
Maybe try a lower VideoQMin and a lower resolution as well just to see if we can get it smooth first.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Return to “Beginners”