Skip to content

September 26, 2012

53

Raspberry Pi – Webcam streaming

Now it’s time to make my old Creative Live! Cam Vista IM (VF0260) Webcam work on the RasPi, I also tried a new Logitech C270 HD Webcam and they both work flawlessly out of the box.
I have tried three softwares for the webcam, which I previously tested on my desktop machine running Fedora and I wanted to try them also on the Pi. These are:

  • fswebcam
  • motion
  • mjpeg-streamer

Let’s now have a look at them.

Note: Since some kernel updates, it’s required to boot the system with a kernel parameter that lets the webcam work again instead of taking just black pictures. Thanks to WebS1821 for this precious insight!

Proceed by editing the kernel parameters file:
# nano /boot/cmdline.txt
and append:
dwc_otg.fiq_split_enable=0
Don’t forget to reboot after adding the parameter.

  • fswebcam:

    fswebcam is the simplest and easiest way to have your webcam capture single frames, also programmatically at a specified timer interval. Of course it’s also possible to call fswebcam from a bash script anytime it’s required, but this is another story.
    To install fswebcam simply run:

    # apt-get install fswebcam

    One of the nice features of fswebcam is that it’s possible to add a footer to the capture, where you can specify your text of choice.
    For instance, this is the command I ran fswebcam with:

    $ fswebcam -r 640x480 -S 15 --flip h --jpeg 95 --shadow --title "SLB Labs" --subtitle "Home" --info "Monitor: Active @ 1 fpm" --save home.jpg -q -l 60

    switches:
    -r: frame resolution width*height
    -S: numbers of frame to skip for the webcam to capture a stable and well illuminated frame
    --flip: frame flipping, in this case horizontal
    --jpeg: jpeg compression quality
    --shadow: adds a drop shadow to the footer text
    --title, --subtitle, --info: different fields of the footer text
    --save: path and file name where to saved the frame to
    -q: leaves the process running in background
    -l: takes a snapshoot every specified number of seconds

    Many more options are described in the man pages of fswebcam
    $ man fswebcam

    This is the output frame sample given by the previous command:

    Okay, this wasn’t exactly streaming, so let’s get into more serious stuff.

  • motion:

    motion is a rather complete surveillance system with no fancy stuff and straight to the point, yet very customizable. Among what it can do, it is capable of motion detection, frame recording, video recording, timelapse.
    Its installation is as simple as usual:

    # apt-get install motion

    It comes with a plain web configuration interface, but first of all we need to specify which port motion will run on. Let’s now edit its configuration file:

    # nano /etc/motion/motion.conf

    and look for the settings webcontrol_port (default 8080) and stream_port (default 8081), which refers to the web configuration interface and the streaming port, respectively. Change them as needed or simply get aware of their default values.
    To start motion run:

    # motion

    You can now access to the web configuration interface by pointing your browser to:

    http://RPI-IP:webcontrol_port

    where RPI-IP is the local IP address of your RasPi and webcontrol_port is the same port set in the config file.
    That said, it’s now possible to browse all the available settings.
    Some of them that are worth a mention are:
    width and height: frame dimensions, camera dependent
    framerate: maximum number of frames to be captured per second
    threshold: number of pixels in the image that must change to trigger the motion detection
    quality: compression level for frame capture
    ffmpeg_timelapse: number of seconds between which to take a frame shoot for timelapse recording
    ffmpeg_bps: constant bitrate for video encoding (ignored for timelapses)
    ffmpeg_variable_bitrate: variable bitrate for video encoding (using a variable bitrate is the only way to get decent timelapse videos, this setting is used for both video motion recording and timelapses)
    and of course the different images/video/timelapses paths where to save the captures to are among the settings you might want to customize.
    Another important feature of motion is that it’s possible to execute any particular command anytime an event starts and/or a picture is captured, this is achieved by the setting on_event_start and on_picture_save.
    For instance it’s possible to send an email and upload the saved picture to an ftp server by setting on_event_start and on_picture_save as follows:

    on_event_start sendmail -f YOURFROMEMAIL@gmail.com -t YOURTOEMAIL@gmail.com -u \"SUBJECT\" -m \"Movement has been detected on: %d %m %Y. The time of the movement was: %H:%M (Hour:Minute). The Pictures have been uploaded to your FTP account.\" -s smtp.gmail.com:25 -xu YOURGMAIL@gmail.com -xp YOURGMAILPASSWORD

    on_picture_save wput ftp://USERNAME:PASSWORD@YOUTFTP.COM %f

    Like said above, the video stream will be available pointing the browser here:

    http://RPI-IP:stream_port

  • mjpeg-streamer:

    Another streaming software that I tried was mjpeg-streamer, which is not as features complete as motion, but it is perfect if you just need a video stream. It also provides a web interface to display the stream. I couldn’t find a binary version of mjpeg-streamer for arm processor, so I had to compile it myself as follows.

    First off we need mjpg-streamer source code from > here < and save it in your folder of choice. I usually save and extract the source packages under /usr/local/src.
    Position yourself whichever folder the archive has been saved into, and extract the archive with the command:

    # tar xvzf mjpg-streamer-r63.tar.gz

    In order to compile mjpg-streamer, we need the libjpeg8-dev libraries, so let's install them first:

    # apt-get install libjpeg8-dev

    I also needed to create a symbolic link of one header file which, to me, resulted missing:

    # ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h

    Now everything should be set to proceed with the compilation process. Switch to mjpg-streamer newly created folder and compile it with:

    # cd mjpg-streamer-r63
    # CFLAGS+="-O2 -march=armv6 -mfpu=vfp -mfloat-abi=hard" make

    And that's it. To run mpjg-streamer type the following command:

    $ export LD_LIBRARY_PATH=.
    $ ./mjpg_streamer -i './input_uvc.so -d /dev/video0 -r 640x480 -f 15' -o './output_http.so -w ./www -p 8080'

    switches:
    -i: configure the input section
    -d: device selection, in case of multiple webcams
    -r: frame resolution width*height
    -f: frame per seconds
    -o: configure the output section
    -w: website folder
    -p: port

    It's now possible to get access to the web interface at the address:

    http://RPI-IP:8080

Top ^

53 Comments Post a comment
  1. Ken Garland
    Sep 26 2012

    Thanks, well written and to the point with great copy/paste – just the way I like it! Adding this on my TODO list.

    Reply
    • SLB
      Sep 26 2012

      Thanks Ken for the feedback, most appreciated!

  2. NealC
    Oct 7 2012

    Thanks for the mjpg-streamer how-to – that’s exactly what I needed, the official pages didn’t go into nearly enough detail for a compiling-noob like me!

    Reply
    • SLB
      Oct 7 2012

      You’re welcome, glad it helped :)

  3. Johann
    Nov 4 2012

    Thanks for the great How-To. Just got my Pi and I just have the same logitech cam. I will try it out right away.

    Reply
    • Nov 4 2012

      You’re welcome, have fun with it :)

  4. awx09
    Nov 9 2012

    Hi, thanks for your tutorials, but on my side i can´t get running the C270 on the RasPi:

    The Raspbian “wheezy” has no built-in support for UVC webcams like the C270?!

    Arch Linux has UVC support “out of the box” but with ‘motion’ the max. resolution is 352×288 – any higher resolution will not work.

    So my question is: did you perform some other steps, also? Can you please post your motion.conf? Do you have any other idea what might be the reason that its working on your side but not on my?

    Thanks in advance.

    Reply
  5. Noob.
    Nov 11 2012

    Motion returns ‘Illegal instruction’ and mjpg-streamer returns:

    libv4l2: error dequeuing buf: Input/output error
    Unable to dequeue buffer: Input/output error
    i: Error grabbing frames

    among other things.

    Is there a foolproof way of getting a webcam to work?! I sure haven’t found it yet.

    Reply
  6. awx09
    Nov 11 2012

    OK, with C270 and mjpg-streamer its possible now to stream 960×720 with 1-2 fps over the internet :-) This is very nice … Thanks for the tutorial!

    But with motion there is no way to have a bigger image than 352×288… Its not a real problem for me, but I am still nosy what causes this issue…

    Reply
  7. Nov 25 2012

    Possibly you cannot imagine how much time I wasted, dealing with video stream from Raspberry. MJPEG-streamer from your tutorial works great, thank’s so much;)

    Reply
  8. newbie2005
    Nov 27 2012

    I have same error i:Error grabbing frames, please try
    mjpg_streamer -i “input_uvc.so -f 1 -r 1280×1024″ -o “output_http.so -w /usr/www”

    Reply
  9. Dec 3 2012

    sudo nano /etc/motion/motion.conf

    # Restrict webcam connections to localhost only (default: on)
    #webcam_localhost on
    webcam_localhost off

    Reply
  10. Ahsan Ebrahim
    Jan 21 2013

    Hey, i need a help, i have got An A4Tech PK-130MJ, when i switch on my raspberry pi, it even shows me the details about the camera which mean it has detected it and supports it i guess, but when i type motion to start the software, it stucks on
    [1] Failed to open video devices /dev/video0:
    [1] Retrying until successful connection with camera

    and these lines continue to go on until i exit it, can you please help me, Thanks, Ahsan.

    Reply
    • Ahsan Ebrahim
      Jan 21 2013

      and even when i write
      $ fswebcam -r 640×480 -S 15 –flip h –jpeg 95 –shadow –title “SLB Labs” –subtitle “Home” –info “Monitor: Active @ 1 fpm” –save home.jpg -q -l 60
      to capture a shot, it gives me an error as below
      Error opening device : /dev/video0
      open: Unkown error 4008
      Error opening device : /dev/video0
      open: Unkown error 4008
      Unable to find a souce module that can read /dev/video0.

      all written in red, help me please.

  11. Bartek
    Jan 30 2013

    Hi, I have a problem,
    After typing “./mjpg_streamer -i ‘./input_uvc.so -d /dev/video0 -r 640×480 -f 15′ -o ‘./output_http.so -w ./www -p 8080′”
    my consol show:
    -bash: ./mjpg_streamer: no such fil or directory

    Why?

    Reply
  12. Xylic
    Feb 7 2013

    You need to run that line from the directory that you compiled your source. I had the same issue.

    Reply
  13. chaitanyabysani
    Feb 8 2013

    hi sir,
    my main aim is to capture the images/video from webcam and those videos/images send to my friends email.these total function can do by raspberry pi. is any program required to doing these things or above process is enough?

    Reply
  14. chaitanyabysani
    Feb 8 2013

    Hello,

    I have to create webcam server system that consist USB web camera, raspberry pi. The system will function like this :

    1. Raspberry Pi will take a pictures every 30 seconds.
    2. raspberry pi have to send the pictures (MMS of the picture) to the owner mobile phone and email ID.

    i just want to ask several question.

    1. can raspberry pi send MMS? i think i want to connect raspberry pie to the wireless broadband modem, so it will send MMS thru email. possible or not? or there is another alternative to do this thing?

    2. Is there any chances owner can reply via mobile phone or email? how the owner mobile phone want to confirm back to raspberry pi? reply the email or what?

    i hope anybody can help me. and also can provide me any website link that can help me to understand more about all of this.

    Reply
  15. Feb 27 2013

    Thanks for the info. I have it working using a C270 webcam.
    I am new to Linux and RasPi, but your instructions worked for me. Thanks again!

    Reply
    • Aug 6 2013

      You’re welcome : )

  16. Adrian
    Mar 25 2013

    Hi, Excellent write up. I have a query i’m hoping you could assist with. I have two RPi’s and am trying to use one as an ip webcam input into Motion. Trouble is motion wants the actual stream as input not a URL that returns a web page with an embedded video. Any idea what parameters to use in mpjp-streamer to just get the actual stream?

    Thanks.

    Reply
    • Mar 25 2013

      Hi Adrian, thanks.
      Try running mjpg-streamer as usual but get the stream straight from
      http://ip:port/?action=stream and see if it works.

    • Adrian
      Mar 25 2013

      Thanks, was thinking along the same lines. Will try it and advise.

  17. Adrian
    Mar 25 2013

    Hi, YES !! It works, super. Now have a wireless IP Network camera as input into second RPi running motion, that triggers DSLR camera upon detecting movement. Demo of DSLR/Motion here : https://www.youtube.com/watch?v=10OXagkNRWI

    Need to update that now.

    Many Thanks….

    Adrian.

    Reply
    • Mar 25 2013

      Thanks for the feedback, I saw the video, very nice :) glad that helped, you’re welcome Adrian.

  18. legend
    Mar 31 2013

    thank you very much. great work

    Reply
  19. Bob
    Mar 31 2013

    Thx for nice tutorial. However mjpeg-streamer does not compile on my PI running the latest raspian. I get quite a few errors like this:

    VIDIOCSWIN undeclared
    VIDEO_PALETTE_YUV420P undeclared
    BASE_VIDIOCPRIVATE undeclared

    and so on…

    Maybe someone can shed some light on this? Thx.

    Reply
  20. Alistair
    Apr 6 2013

    Hi

    Great Post !

    I seem to be stuck on the the web browser part, it doesn’t seem to want to connect. any suggestions ?

    Thanks
    Alistair

    Reply
  21. andre
    Apr 17 2013

    I’m having issues with Motion and IE.

    Do you have any suggestions.

    Thank you.

    Reply
    • Russ
      Apr 30 2013

      Try using Chrome or FireFox, or a stream player like VLC.

  22. Marc
    Jul 10 2013

    Thank you for this article!
    I also have an old Creative Labs webcam. Works fine under Windows, but is not detected by the Pi.

    The lsusb command does not list my webcam.

    Any idea on how to continue?

    Thanks in advance.

    Reply
  23. Andrew
    Aug 4 2013

    Awesome! I’ve been trying to get my c270 to work with my pi for a long time, and I finally got it working using your mjpeg-streamer instructions. I’m able to stream full resolution (960×720) at 15fps over my home wi-fi network. Thanks for posting this.

    Reply
    • Aug 6 2013

      Nice, you’re welcome : )

  24. Jason
    Aug 6 2013

    Any idea how to get the same concept to work with the Camera Module?

    Reply
    • Aug 6 2013

      For the Raspberry Camera Module I think you have to use other tools, you should find them already installed, and if not, run an update and they should install. They are raspistill to take snaps and raspivid for video streaming, each of them come with its –help flag.
      I haven’t used them because I don’t have the camera module, hope they works fine for you.

  25. Averell Dalton
    Sep 7 2013

    Hi there,

    I don’t know why I cannot have live video (webcam configuration section). Although I can capture motions (avi and jpg files), but no live streaming.
    Here under is my configuration for that part (default):

    # Live Webcam Server
    ############################################################

    # The mini-http server listens to this port for requests (default: 0 = disabled)
    webcam_port 8080

    # Quality of the jpeg (in percent) images produced (default: 50)
    webcam_quality 50

    # Output frames at 1 fps when no motion is detected and increase to the
    # rate given by webcam_maxrate when motion is detected (default: off)
    webcam_motion off

    # Maximum framerate for webcam streams (default: 1)
    webcam_maxrate 5

    # Restrict webcam connections to localhost only (default: on)
    webcam_localhost off

    # Limits the number of images per connection (default: 0 = unlimited)
    # Number can be defined by multiplying actual webcam rate by desired number of seconds
    # Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
    webcam_limit 0

    Reply
    • Sep 10 2013

      Hi,

      Can you give me more informations about the software and version you are using? Because my config file is much different than yours.

  26. milab
    Oct 17 2013

    Hello ! Great tutorial !
    Since I have exactly same webcam VF0260 I tried to connect it to RPi. Unfortunately no matter what I do I get the same error message: “Bogus Huffman table definition”. The same error is reported by fswebcam and motion. Mjpg-streamer although compiled fine (I had to install imagemagik) streams blank picture. When I try the testpicture input I get properly streamed test image so the problem lays somewhere in capturing data from the webcam.
    I tried changing resolution, changing palette, changing output format – nothing helps.
    The webcam is properly recognised and you can change parameters like contrast, brightness etc.
    And hours of talking with professor Google doesn’t seem help either :(

    Reply
    • Nov 20 2013

      Hi, unfortunately it seems that since some updates to date, something got broken along the way. I just tried it after more requests and indeed I get black frames as well.
      Now I don’t know whether it’s a power issue but I don’t think so, since before it was working fine.
      If i find further informations about the problem, I’ll keep you updated.

  27. Marco
    Nov 16 2013

    Hi! I know it’s a old post but I haven’t found anything better on the web. I have an old Creative Live! Cam Vista IM (VF0260) as well, and i’m trying to make it work with rasperry as well.
    It works fine on my laptop, I tried fswecam on it(debian Wheezy), but as I plug it to the raspberry and try to use it it doesn’t work. It gives me black pics. On my RPi i’m using raspbian.

    So, I’d like to ask you a couple of details that maybe can help me out:
    1) What was you RPi OS? Raspbian as well or something else?
    2) Did you just plug the cam in the RPi USB port, or you use a powered USB hub? I’ve read that some cams requires more power than the one provided by the RPi usb port.

    Thanks man, great job!

    Marco

    Reply
    • Nov 16 2013

      Ciao Marco,

      Yes, I always used raspbian and just plugged the webcam straight into the pi.
      I’m not sure whether since I wrote this post, things have changed in raspbian or rather in its kernel that could’ve broken the webcam.

      When you run fswebcam, does the webcam led blink when taking the picture?
      Please try again with the -S flag if you haven’t already, using a value of at least 15. It lets the webcam “warm up” before taking a pic.

      Please let me know whether it worked, and in case I try the webcam again with the updated raspbian and see if it still works for me or it’s broken here as well.

    • Marco
      Nov 18 2013

      Mmmm I actually didn’t take care of the blinking because I was trying to use it via remote, so the webcam and the RPi were in another place from me, but I’m gonna try again and see what happens.

      If you could try it again with the updated RPi it would be very very helpful!

      Thank you,

      Marco!

    • Nov 20 2013

      Hi, I tried the webcam again and unfortunately it seems that since some updates, something got broken along the way. I indeed get black frames as well. Now I don’t know whether it’s a power issue but I don’t think so, since before it was working fine.
      If i find further informations about the problem, I’ll keep you updated.
      I also downgraded libjpeg from v8 to v6.2 as I found somewhere but didn’t work, so it may be a kernel issue.
      This is the error I’m getting:
      gd-jpeg: JPEG library reports unrecoverable error: Unsupported marker type 0xf5

    • Marco
      Nov 20 2013

      Could it be something like there are no more the drivers in the kernel?

      I think if it would be possibile for you(or tell us which OS and version you used where the cam worked) it would be great to test again the cam with the old configuration. So maybe we can understand what drivers it uses and see if we can install them manually.

      Cheers,

      Marco

    • Dec 11 2013

      Hi! I had the same issue but I found solution on some webpage.
      You need to add dwc_otg.fiq_split_enable=0 to the file /boot/cmdline.txt
      I tried it on Raspian and ArchLinux.

    • Dec 11 2013

      Thank you WebS1821, it worked!
      I’ll update the post with your precious information, thanks again!

  28. pi
    Nov 28 2013

    Unable to get the live video stream on browser or on vlc. My webcam is working fine with guvcview.
    plz reply

    Reply
  29. Filippo
    Jan 19 2014

    Hi
    I’m trying to use raspberry with its camera board but when i starts mjpg-r63 with command:
    > ./mjpg_streamer -i ‘./input_uvc.so -d /dev/video0 -r 640×480 -f 15′ -o ‘./output_http.so -w ./www -p 8080′

    the consol say to me :
    ERROR opening V4L interface: No such file or directory

    Probably because The cameraBoard is not an external device and it’s not seen as usbCamera (/dev/video0).

    So I tried to use the file “input_file.so” as parmater of mjpg, passing to it a streaming of photo maked with raspistill.. but this version of mjpg (mjpg-63) hasn’t this file in its compiled folder.

    The older version of mjpg works but it’s very low and make only 5 fps.
    What do I have to do to use camera board as network camera with a good number of fps ?
    thanks
    F

    Reply
    • Mar 27 2014

      Hi Filippo, sorry for the very late reply!
      I was planning to write an article dedicated to the camera board but I haven’t had the time yet, though, for the raspicam I use this solution, which gives me awesome features and up to 30 fps.
      http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=63276

Trackbacks & Pingbacks

  1. raspberry pi USB web-camera 動画のストリーミング配信(オマケで音声も) | 興味本位の Trial 安堵 Error
  2. Raspberry Pi, Node.js, and a Webcam – Part 1
  3. Raspberry Pi Camera Board | Steve's Project Pages

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

Top ^