The Raspberry PI is perfectly equipped to turn your USB based webcam into a fully functional IP webcam that you can have lots of fun with, from there you could use tools such as Python to make your project more unique, I’m having a go at counting passing traffic.
If you’re wanting to something a bit more simple you could just have a webcam that can be accessed from anywhere with an internet connection, which is what you will end up with at the end of this guide.
Your shopping list…
- Raspberry Pi with an OS installed
- USB Powered Hub – Amazon UK – Amazon US
- Important; This one worked for me, however, it’s not worked for others, you will find this is the case with a lot of the powered USB hubs, research before buying.
- We need a hub because the camera’s draw more power than the Raspberry Pi can actually provide, you see the same with some keyboards and USB dongles.
- Web Cam
You could also look at an external power back and WiFi if you want to make it mobile, a few people have put these in a garden or somewhere without a static power/network source.
1. Get the software ready
To start with we’re assuming that you have a working Raspberry Pi on a local network with internet access, the next step is to update your Pi ensuring that you have the latest software and drivers installed.
sudo apt-get update sudo apt-get upgrade
Next, it’s time to install the software, and we’ll be using a fairly lightweight application called Motion, this will do a few things for us including accessing the USB camera, getting the images, and streaming them via a built-in web server. As the name suggests it will also track and trigger events on motion detected in the video frames (more on that later).
sudo apt-get install motion
2. Plug in your webcam
So now the software is on there it’s time to plug in the webcam and ensure that everything is working, ensuring that you plug it into the powered hub, and then into the PI. Otherwise, the webcam will not get enough power to turn on.
When plugged in type the “lsusb” command, you should see a line there with your webcam manufacture, that proves that you have the basic connectivity working.
lsusb .... Bus 001 Device 002: ID 04ea:1142 Microsoft Corp. ....
3. Configure the software
sudo nano /etc/motion/motion.conf
In here there are a few basic changes that you need to perform:
- Daemon = OFF to ON
- webcam_localhost = ON to OFF
You can change other settings but it’s recommended you don’t take more than 2 frames, and you keep the default frame pixel size, for stability.
4. Start the software
To ensure that the motion service will actually start as a daemon we need to change another configuration setting, so enter the following:
sudo nano /etc/default/motion
Then change the value “start_motion_daemon=no” to “yes”
Finally, you can start the motion service to stream the webcam images
sudo service motion start
Then after about 30 seconds browse to the new web interface, which should be at the below URL (where 192.168.0.100 is your Raspberry PI’s IP address)
http://192.168.0.100:8081
5. Final tweaks
Web Port
You could change the web interface port to 80 (from the default 8081), so that you can just browse to the IP address without having to put :8081 at the end, it’s really simple to do, just:
sudo nano /etc/motion/motion.conf
And then change “webcam_port 8081” to “webcam_port 80”, save the file, and restart the motion service.
sudo service motion restart
Port Forwarding
The final suggestion is to enable port forwarding on your home broadband router to the Raspberry PI on port 80, that will mean you can access the webcam from anywhere in the world. There are too many routers in the word to explain how to do it here, but I am sure you will find some help on Google, if not please just leave a comment.
Warning; If you give it internet access via port forwarding this does take up quite a bit of bandwidth, and anyone can see your webcam feed, so only show what you want people to see 😉
168 comments On How To: Raspberry PI Web Cam Server
Many thanks for this, I was almost expecting it not to work as it seemed too simple, but I had it running in 10 mins. Just one point though I had to edit another file as I recieved this error when trying to start the motion service –
pi@raspberrypi ~/c $ sudo service motion start
Not starting motion daemon, disabled via /etc/default/motion … (warning).
I edited /etc/default/motion and all was good.
pi@raspberrypi /etc/default $ more motion
# set to ‘yes’ to enable the motion daemon
start_motion_daemon=no
pi@raspberrypi /etc/default $ sudo nano motion
pi@raspberrypi /etc/default $ sudo service motion start
Starting motion detection daemon: motion.
pi@raspberrypi /etc/default $
Thanks again!
Thank you, forgot that off the post, have updated it 🙂
Hi, thanks! You might want to put 5. Final tweaks before 4. Start the software, because software won’t start without tweak. Cheers !
Thank you so much, like Tony G, I also had to alter /etc/default/motion, but then I was good to go. I used a Logitech C210 ($17 @ RadioShack).
Thanks for the comment, blog post has been updated.
Hi,
What resolution did you choose ? As far, I only succeed with small resolution like 320×240 … :/
I used the default as well, however you should be able to increase if you lower the framerate.
If I don’t port forward is it possible to still use this from an outside IP?
Only if your router has NAT disabled, and the raspberry PI has a public IP address.
You could use a script to upload the images to a web server…
Thanks very much, after a few minutes I had my first RPi streaming video.
Thanks a lot! It works perfectly.
Thanks for the how to! This was exactly the job that I had my second RPi slated for.
Hi I’m making a robot,
I need to stream multiple webcams Simultaneously. I got one cam working with the above steps, is it possible to stream more than one.
The Raspberry PI would probably struggle to process more than one using Motion, however you can try 🙂
Hi there,
Thanks for the instructions – I spent all weekend trying to get this to work and eventually succeeded, but the fault was mine and not the instructions which with the right preparation were perfect! so while this may be totally obvious to others, maybe I could share my experience to save noobs like me the pain.
1)Make sure you are on the latest release – I tried all sorts with no luck until i reflashed my SD and then it worked straight off (update/upgrade wasn’t enough).
2) The website doesn’t work on midori or ie – worked a treat on firefox though
only issue I have now is that it seems to stop intermittently, but I haven’t started to investigate yet
Got a grey image with : “unable to open video device”
Have you tired a powered USB hub? can you see the device on a ‘lsusb’ output via terminal?
My webcam is showing up on lsusb as bus 001 device 016. It is plugged into a powered USB hub. Still, my browser is showing me a gray box saying UNABLE TO OPEN VIDEO DEVICE. I’ve tried changing the device from /dev/video0 to /dev/bus/001/016 but still no luck.
Any ideas?
What make of web cam is it?
I’ve just installed this and have this problem too. However, it worked fine on my Ubuntu desktop. What I have discovered is that if I do ‘sudo motion’ in a terminal window on the pi with ‘daemon on’ in motion.conf then it works ok but if i do ‘sudo service motion start’ I get a grey box with the message ‘cannot open video device’. I guess its something to do with permissions. I did see a post that said to ‘chmod 777 /media’ but I don’t have anything listed in /media on my pi.
I encountered the same hurdle with “sudo motion start”.
I tried “sudo motion” with daemon=On in ‘motion.conf’ and I got ,
‘Motion 3.2.12 started’
‘Motion going to daeman mode’
but my ‘sudo uvcdynctrl -f’ command not found
So I ran with the -n command and am getting a few things that look suspicious. Here’s what shows up:
motion thread 1 restart
thread 1 started
cap.driver: “pac207”
cap.card: “CIF single chip ”
cap.bus_info: “usb-bcm2708_usb-1.2.4”
cap.capabilities = 0x50000001
-VIDEO CAPTURE
-READWRITE
-STREAMING
config palette index 8 (YU12) doesn’t work.
supported palettes:
0: P207 (P207)
Unable to find compatible palette format.
ioctl (VIDIOCGCAP): Inappropriate ioctl for device
Could not fetch initial image from camera
motion continues using width and height from config file(s)
resizing pre_capture buffer to 1 items
bind(): Address already in use
problem enabling stream server in port 8081: address already in use
thread exiting
Sounds like something is already bound to port 8081..
Check using a ‘netstat -lnutp’ to see your network bindings.
Thanks, I’m using port 60080 now and I’m not getting that error message but I’m still getting the p207 issue:
config palette index 8 (YU12) doesn’t work.
supported palettes:
0: P207 (P207)
Unable to find compatible palette format.
ioctl (VIDIOCGCAP): Inappropriate ioctl for device
The thing is, index 0 is not P207, it’s BA81.
So if I understand this correctly, I think my camera wants to use the p207 palette but that isn’t supported by motion. Is there any way to deal with this issue or do I just need to use a different camera that is compatible with one of the other palettes?
Sorry, index 0 is S910. Still not sure how to get it to use p207 since it isn’t one of the palettes listed.
It’s a gearhead quick webcam:
http://www.officedepot.com/a/products/326763/Gear-Head-Quick-WebCam-Pro/#firstTab
Hi, I’ve gone through the above process and get through to the end of Step 4 without any reported problems. But how do I view the webcam image please? Do I go to a web browser on the network, i.e. another PC or a tablet, and type in the ip address? Sorry if it’s a really basic question, but I’m very new to the Pi.
Thanks
No problem; You go to any device on the network and browse to the address http://192.168.0.100:8081 using your normal web browser, that could be another PC, tablet or even the raspberry PI if you have a monitor plugged in to it.
Just remember you need to replace the IP address in the above example (192.168.0.100) with the IP address of your Raspberry PI, you can find that by running the command ‘ifconfig’ on the raspberry PI and looking on the eth0 interface, so if your IP is 192.168.1.20, you would browse to http://192.168.1.20:8081
Hope that helps 🙂
I followed the procedure published except I did not do:
<>
I then do this:
<> I use “http://192.168.0.109:8081” which is my device.
I get a file download (file name is “192.168.0.109”).?
Can anyone tell me what is going on?
Win7 64 Pro, browser IE 10
I’ve found that the only browser that works is firefox.
I’ve also found that I can use the VLC media player: go to Media-> open network stream, then type in the full ip address, including the port.
Thanks Mikeymike
Been trying for days and couldn’t get to work. Tried Chrome and Explorer and both would not function. Chrome tried but just appeared to be busy continuously .This made me think it was something else wrong. Very much appreciated
Performed all of the steps and I can see that my webcam is turning on/off with the “service motion” commands but when I use Internet Explorer to browse to my Pi’s address (with port 8081 added) I get the dialog box that asks if I want to open or save the download. If I say “open”, I can see that it is collecting data but nothing is displayed in the browset window. Same thing with the “save” option. Is there some sort of browser plug-in that is required to actually view the video stream?
Strange it should just display a webpage with an image at the top left, does this happen on all computers/browsers?
A poster on the Raspberry Pi forum said that Internet Explorer requires a plug-in but he didn’t know what it was. Told me to try pretty much any other browser like Foxfire, Chrome, or Opera. I installed Foxfire and it came up as it should. I’d still like to find the proper plug-in for Internet Explorer if I can. By the way, you can add the Hewlett Packard KQ246AA webcam to the list of usable devices. Thanks for this simple install procedure.
It sounds to me like the device might not be sending the correct mime/header type.
Easy as pi. Next step is getting the camera mounted on some servos and tracking movement?
Certainly possible with motion, will give it a go over the next few weeks 🙂
Whenever I go to my Cameras IP, the image only updates for a few seconds, do you know how to fix this?
It could be a few things, frame rate too high? resolution too high? or no USB powered hub between the camera and Raspberry PI.
When I go to my cameras IP, the image only updates for a few seconds, any fix?
# Number can be defined by multiplying actual webcam rate by desired number of $
# Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
webcam_limit 15
Should read
# Number can be defined by multiplying actual webcam rate by desired number of $
# Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
webcam_limit 0
Hi, I managed to get it all up and running with some difficulties from my side (this is the best way to learn though). I have only one (final I think) issue: no image on the webpage. I keep getting the messsage : This webpage is not available, Chromium’s connection attempt to 192.168.0.107 was rejected. I ried Firefox as well, but with the same result. My cam’s on 192.168.0.107:8081.
Can you give me a hint please ?
Fixed it myself: webcam_localhost was still on.
Thanx for the great tutorial !!!
Hi All,
Thanks for the guide, I had the webcam up and running in no time.
I cant seem to get motion to work on port 80. it works fine on other ports. Does anyone have any suggestions?
Thanks in advance.
Ensure that nothing else is already using port 80, check your ‘netstat -lnutp’ output
Port 80 (and anything less than 1024) is a ‘privileged’ port. Only processes currently running as root may bind to those ports.
Since motion runs as the user ‘motion’, it’s restricted to ports 1024-65535.
You can edit /etc/init.d/motion, and remove the ‘–chuid motion’ bits should you want to run motion as root.
Plugged in a different cam (Trust Spacec@m200) and all I get is a grey image saying: unable to open video device. It shows up in Putty though as a Omnivision )V511+ Webcam.
Is the device maybe too old to be recognized ?
Could be too old, or not enough of them around meaning there isn’t a lot of people trying to make drivers for them.
Try updating to the latest software ‘sudo apt-get update’ and ‘sudo apt-get upgrade’
I have also been trying to get motion to run on port 80. I had apache2 running on port 80 but stopped that, modified motion.conf to change the port from 8081 to 80 and restarted the motion service. However I am unable to connect to port 80 using a browser and netstat -lnutp only shows the control port 8080 for motion.
Any ideas please?
Had the same problem with my raspberry pi, fairly sure a reboot fixed it, although guessing you have tried that already?
Lower ports are available only for processes running with root privleges. You can redirect incoming connections from 80 to 8081 port using iptable command, ex:
iptables -t nat -A PREROUTING -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8081
(change wlan0 to real webcam interface)
logitech webcam is not working on port 80, light just keeps flashing, tried the following
iptables -t nat -A PREROUTING -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8081
Bad argument `–dport’
Any other ideas?
Cheers
Dave
A very good description for the Raspberry Webcam.
It works directly and I’m happy with it.
Thank you very much.
FINALLY got motion to run with no errors by installing the imgproc libraries from:
http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/image_processing/
now when type in ip:port in my browser I get a page that says:
Motion 3.2.12 Running [1] Threads
ALL
ALL links to the settings in the config file but I don’t see the actual image anywhere.
There are two ports that you can get responses on.
By default 8081 is the image and 8080 is the control … and it looks like you were going to 8080 (control).
Thank you for the excellent blog post. It got me up and running with my own Raspberry Pi webcam server, which was quite exciting.
I am wrestling with a difficult problem, however. The Microsoft LifeCam goes becomes lost after a few hours of use. I’ve tried everything I can think of to prevent this from happening and having to physically re-connect the camera so that it will be recognized again, but I’m at my wits’ end. So I’ve posted a question up on the Raspberry Pi StackExchange and I’m hoping you might have an idea for what’s going wrong? http://raspberrypi.stackexchange.com/questions/4984/webcam-disconnects-after-a-few-hours-of-running-motion
Hi Weston,
Thanks for the comment, unfortunately there isn’t any easy answer to get it working, however here are a few things I would try in your case;
First off I would try lowering your resolution to something like 320×240 and see if it’s any more stable, basically that should lower any load on the Pi.
You could actually go one step further and change “webcam_port” to zero for one of your tests, that will disable the web server but keep your snapshot functionality running, your not going to get the load much lower than this setup.
Next get out a multimeter (if you have one), check the USB power output before you plug in the web cam, then once it’s in, and finally once its failed. I have heard of a few powered USB hubs out there that don’t really inject enough power, especially if there are a few devices using it.
Finally I would also look at trying a wired network connection for a while instead of WiFi, again just to rule it out.
Hope some of them might help you pin it down 🙂
Tom
What is the cpu usage you guys got? I needed to take down the quality and now i got 60% cpu usage for the motion daemon. If I take al teh default settings the cpu goes to 100%. Someone with the same problem or a solution?
greetz
Try lowering the frame rate instead of the quality, sometimes that helps.
But your correct, it does use quite a lot of CPU on the default.
Hi tom,
Thanks for the post. Helped me a lot 🙂
I would like to save the images acquired from webcam on desktop. I am new to python and reasonably good with C programming. Please let me know how to go about it.
Thanks!
If you mean the desktop on your Raspberry Pi then just change the save directory.
But if you mean onto your desktop computer then instal an FTP server on the Pi, and create a script that collects the images.
Thanks for the tutorial. Everything worked perfectly,even with a $4.99 generic chinese webcam, but I cannot view the images using the Midori browser on the start-up Raspberry image, although google over the network works fine. I have run update and upgrade etc. Instead of a webcam stream, Midori on PRi just displays text.
Any solutions anyone? Thanks, and keep building.
Thank you so much for this great tutorial! It worked right away without any extra configuration! Is there any way to make it have a faster frame rate or at least go faster on the hosted site?
Found that motion puts images in /tmp/motion… Might that fill the
SD card after some time???? Should options be turned off to keep the SD card from becoming full???
You can use “output_normal off” to remove this, it seems
What a great tutorial, thanks! The USB hub may not be necessary; at least, it’s not with this old Microsoft Lifecam I have. OTOH you need a source of USB power anyway so might as well get a proper hub.
To the folks trying to use port 80; on Unix by default you have to be root to bind to ports < 1024, and motion runs as the user motion. Various workarounds here: http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l
I followed your instructions without any problem but think my webcam may be the problem (Logitech E1000 with no drivers) when I try to browse to my PI’s address I just get “the page cannot be loaded”
The webcam is recognised when I use the lsusb command, does motion act as the webserver?
The webcam does work very slowly using CHEESE and it uses 100% CPU resources, any help or advice much appreciated.
Yes motion should act as a web server, do a ‘netstat -lnutp’ and you should be able to check that it’s listening on a port.
When you know the port browse to that using any normal browser, e.g. http://192.168.1.10:8080 if your Pi is 192.168.1.10 and motion is listening on port 8080
Hey I have exactly the same problem. In Midori I get:
Error – http://10.0.0.95:8080/
The page ‘http://10.0.0.95:8080/’ couldn’t be loaded.
Cannot connect to destination (10.0.0.95)
I have a Logitech Quickcam 4000 which is detected when I type lsusb.
If I type netstat -lnutp I get:
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN
Connecting to 127.0.0.1 doesnt help either, nor did changing port to 80. What should I do now?
Same problem here.
Common issue then with Logitech devices?
The port is 8081 if you post is not a typo. 8080 is the control port and you should just see ‘All’ on the screen. Access from a computer other than the pi is controlled by ‘control_localhost off’ for 8080 and ‘webcam_localhost off’ for 8081 in motion.conf. Hope this helps.
Hi, thanks for the instructions and everyone’s comments. But I get the message “the image …:8081 cannot be displayed because it contains errors”. I have a Logitec webcam and I’m using iceweasel. I also tried several different USB ports (all powered).
In my case I have a similar problem. But the indicator led on the can is not on. So I suspect motion not to switch on the cam itself.
Single pictures can be made while motion disabled with ‘fswebcam’.
So cam works, but motion does not switch it on for streaming or motion detection.
Fantastic tutorial! Thanks a lot!
This was a life saver – great tutorial. Had a few issues accessing the webcam from outside the network but i think that was user error mainly.
Follow the advice above and it’ll work.
Logitech QuickCAM 9000pro works perfekt!
http://canonversteher.de/webcam
Thanks for letting us know!
Since todays system-updates motion crashes after less than a minute….
For me it up running fine, i am using Logitech Webcam C110
Below is my configuration
daemon=on
norm=3
input=8
auto_brightness=on
framerate=300
height=640width=480
jpeg_filename=motion/%Y%m%d/%v-%H%M%S-%q
noise_tune=on
output_all=off
output_motion=on
output_normal=on
quality=1000
snapshot_interval=500
target_dir=/home/pi/motion
text_left=(c) Nestcam
text_right=%d %b %Y\n%k:%M:%S
threshold=500
v4l2_palette=6
videodevice=/dev/video0
webcam_localhost=off
webcam_maxrate=50
webcam_port=8080
wecam_quality=100
I am getting the gray image with “UNABLE TO OPEN VIDEO DEVICE” message, so I tried running motion from the CLI to gather clues…
Of interest, I see:
[1] Supported palettes:
[1] 0: PWC2 (Raw Philips Webcam)
[1] 1: YU12 (4:2:0, planar, Y-Cb-Cr)
[1] Selected palette YU12
[1] Test palette YU12 (320×240)
[1] Error setting pixel format VIDIOC_S_FMT: Device or resource busy
[1] VIDIOC_TRY_FMT failed for format YU12: Device or resource busy
[1] Unable to find a compatible palette format.
However, I *am* able to run:
v4l2-ctl –set-fmt-video=width=320,height=240,pixelformat=1
without error.
Suspecting permission problems, I checked:
pi@raspberrypi:/etc/motion# ll /dev/vid*
crw-rw—T 1 root video 81, 0 Dec 31 1969 /dev/video0
and:
pi@raspberrypi:/etc/motion# grep motion /etc/group
video:x:44:pi,motion
motion:x:119:
Any suggestions will be greatly appreciated!
http://192.168.0.4:8081/ was my server, not the one you mentioned. If you can’t access your server with one mentioned, type on your pi:
ifconfig
Then find your ip address 🙂
Is there a way (preferably with motion) to stream audio as well?
I’m using the above setup as a “crib cam” and would like to include audio as well so that I can use the Raspberry Pi and a smartphone as a universal baby monitor
Yes. I would like to know this as well.
Just wanted to let you know that this worked perfectly! I rigged up my Microsoft LifeCam under an overturned Tupperware container that I hot-glued to a board, then secured the board under a porch window. It is now suspended above a bird nest that is being built on a ledge below the window. Now we can watch mama bird lay her eggs and hopefully we’ll see them hatch!
Thanks for the detailed instructions. The set up went really smooth!
It doesn’t work in Midori though. The feed is coming through but Midori fails to display the image. Instead, it show a bunch of letters and numbers, similar to when reading a binary file with an editor.
I’m running wheezy and it the motion feed works great in Chromium, but this sends the CPU running at 100%.
Any ideas for an alternative browser will be really helpful.
Thanks
I get this when I do “sudo motion -n”:
[0] Thread 1 – Watchdog timeout, trying to do a graceful restart
[0] Thread 1 – Watchdog timeout, did NOT restart graceful,killing it!
It is constantly doing it.
I have a Cisco VT webcam and I do not get any error whil it is initializing it.I am using port 8080.
This is cosole messages:
pi@raspberrypi /etc/motion $ sudo motion -n
[0] Processing thread 0 – config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] Thread 1 is from /etc/motion/motion.conf
[0] motion-httpd/3.2.12 running, accepting connections
[1] Thread 1 started
[0] motion-httpd: waiting for data on port TCP 8080
[1] cap.driver: “pwc”
[1] cap.card: “Cisco VT Camera”
[1] cap.bus_info: “usb-bcm2708_usb-1.3.3”
[1] cap.capabilities=0x85000001
[1] – VIDEO_CAPTURE
[1] – READWRITE
[1] – STREAMING
[1] Test palette YU12 (320×240)
[1] Using palette YU12 (320×240) bytesperlines 320 sizeimage 115200 colorspace 00000008
[1] found control 0x00980900, “Brightness”, range 0,127
[1] “Brightness”, default 66, current 12
[1] found control 0x00980901, “Contrast”, range 0,63
[1] “Contrast”, default 16, current 16
[1] found control 0x00980902, “Saturation”, range -100,100
[1] “Saturation”, default -8, current -8
[1] found control 0x0098090e, “Red Balance”, range 0,255
[1] “Red Balance”, default 128, current 32
[1] found control 0x0098090f, “Blue Balance”, range 0,255
[1] “Blue Balance”, default 128, current 36
[1] found control 0x00980910, “Gamma”, range 0,31
[1] “Gamma”, default 1, current 1
[1] found control 0x00980911, “Exposure”, range 0,255
[1] “Exposure”, default 241, current 236
[1] found control 0x00980912, “Gain, Automatic”, range 0,1
[1] “Gain, Automatic”, default 1, current 1
[1] found control 0x00980913, “Gain”, range 0,63
[1] “Gain”, default 34, current 43
[1] found control 0x08000000, “Auto contour”, range 0,1
[1] “Auto contour”, default 0, current 0
[1] found control 0x08000001, “Contour”, range 0,63
[1] “Contour”, default 32, current 32
[1] mmap information:
[1] frames=4
[1] 0 length=462848
[1] 1 length=462848
[1] 2 length=462848
[1] 3 length=462848
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[0] Thread 1 – Watchdog timeout, trying to do a graceful restart
[0] httpd – Finishing
[0] httpd Closing
[0] httpd thread exit
[0] Thread 1 – Watchdog timeout, did NOT restart graceful,killing it!
[0] Calling vid_close() from motion_cleanup
[0] Closing video device /dev/video0
[0] Motion thread 1 restart
[1] Thread 1 started
[1] cap.driver: “pwc”
[1] cap.card: “Cisco VT Camera”
[1] cap.bus_info: “usb-bcm2708_usb-1
Great tutorial. 15 mins – up and running.
Now I want to store the stream on my NAS. Can u pls point me at some tutorial for doing this. Thx
I did that by mounting a nfs shared directory in wheezy filesystem (edit /etc/fstab with this line “:/shared/nfs/dir /mnt/nfs nfs rw 0 0” then mount it and in /etc/cron.hourly i added a simple script to move all data from /tmp/motion in a directory on the nas.
I have attached a usb camera to my raspberry pi, and it works well except for one thing: the size is of the image is half of devices’ specs. The specs say that can effective resolution is Up to 352 x 288. The image I get when I use the browser on port 8081, is 176 x 144. I have set the width and height of the motion.conf respectively. Is there a reason it’s not working as expected, and is there a way to make it work?
Great tutorial. I have tried using ffmpeg to stream from my 3D-stereo webcam (a cheap “EnVivo”) but it seems unreliable.
Using ‘motion’ it works perfectly (using only one camera, though).
Would it be possible to have ‘motion’ capture from both cameras? The register nicely as /dev/video0 and video1. ffmpeg plus some filter setting can output the images next to each other as standard 3D-stereo, preferrably as Right-Left.
This works on a windows-box with .mp4 files as input (but I haven’t been able to make it work on the RasPi):
ffmpeg.exe -i c:\temp\outL.mp4 -vf “[in] scale=iw/2:ih/2, pad=2*iw:ih [left] movie=c:\temp\outR.mp4, scale=iw/3:ih/3, fade=out:300:30:alpha=1 [right] [left][right] overlay=main_w/2:0 [out]” -b:v 768k OutSBS.mp4
Would like to have found this thread before…
Anyway I figured out (not without some problems) how to get an IR-modded PS3 Eye camera equipped with 70 LED emitters to work with Motion and have the video stream accessible over the local network from my mobile phone running Firefox for Android.
Next steps: email alerts from the Raspberry Pi at motion detections (sure it’s quite immediate) and find the easier way to get the access to the stream from anywhere (not sure if possible without a static IP address).
Hello Tom,
I have 2 questions:
1: I get stuck in step 3:
“In here there are a few basic changes that you need to perform:
Daemon = OFF to ON
webcam_localhost = ON to OFF”
How do I do this? I can’t find this in the text file. Please explain in more detail so that dummies like me can understand it.
2: “You can change other settings but it’s recommend you don’t take more than 2 frames” Do you mean the webcam can only make ‘video’ of 2 frames/s? that’s not video but pictures…
Thanks!
Jan
1)If you type in the below command from terminal it should ask you for a password, after typing that in you should be able to navigate around the text document (using your keyboard) and change the settings like any text file.
sudo nano /etc/motion/motion.conf
When you have done changing the configuration close the file and save the changes, by holding ctrl and then pressing ‘x’, this will prompt you to save the changes, simply press ‘y’ followed by enter/return.
2) That figure is frames per second, not static pictures, you can increase that it just adds more processing load on the device.
Hello Tom,
Two questions:
1. “In here there are a few basic changes that you need to perform:
Daemon = OFF to ON
webcam_localhost = ON to OFF”
Could you explain for dummies like me how to do this?
2. “You can change other settings but it’s recommend you don’t take more than 2 frames…” Does this mean the webcam can only take 2 pics/s, so not real video?
hello Tom,
thanks for the quick reply. Sorry for posting twice, the website doesn’t confirm my post so I tried again.
I’ve done step 3 now. But I’m not sure what the IP adress is. As you suggested in one of your answers, I typed ifconfig with the result:
etho: HW addr: b8:27 etc…
lo: inet addr: 127.0.0.1
wlan0: inet addr: 192.168.1.35
the result at eth0 is not a valid Ip adress, so should I use the one listed at lo?
something else: I want to put the PI on a (not yet built) robot. Any ideas how to make a powered USB hub (do I really need one?) on batteries?
Thanks for al the help,
Jan
Hi Tom,
Great tutorial, thanks! My new Microsoft LifeCam Camera works fine for a few minutes then stops responding. starting the deamon as motion -n produces the following, when the website returns “Unable to open video device” and the console shows:
[1] Retrying until successful connection with camera
[1] cap.driver: “uvcvideo”
[1] cap.card: “Microsoft® LifeCam Cinema(TM)”
[1] cap.bus_info: “usb-bcm2708_usb-1.3.2.1”
[1] cap.capabilities=0x04000001
[1] – VIDEO_CAPTURE
[1] – STREAMING
[1] Error selecting input 0 VIDIOC_S_INPUT: Device or resource busy
[1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device
and then it repeats.
Do you have any ideas? I’ve tried reinstalling. If I stop/start the daemon it often comes good.
Thanks
Graham
Did you resolve this? I have exactly the same camera and problem 🙂
Has anyone tried this with a pi cam? I want to take stills and save to the sd card?
actually change port command should be
iptables -A PREROUTING -t nat -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8080
but I got
ERROR: could not insert ‘ip_tables’: Operation not permitted
iptables v1.4.14: can’t initialize iptables table `nat’: Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
did you run it as root?
This worked like a champ! I didn’t know about motion before.
I used a cheap-o Hercules web cam with Rasberrian and everything worked right out of the box.
Thanks for the write up.
Hi Tom,
Thanks for the great tutorial. I have got everything working and can pull up a picture on my desktop computer which is on my home network. The picture does not refresh and when I try to refresh the browser I can no longer see the picture unless I reboot my Pi. Any idea why this might happen?
How can I get the new Raspberry Pi camera to work with this setup?
Is there a way to use the new raspberry pi camera?
Yes, I have not got one so can’t write a more basic guide, however have a look here: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=43844&p=354051
Is there a way to get this to work with the new raspberry pi camera?
Can this be used with the new raspberry pi camera?
What would have to be changed?
Have a look here: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=43844&p=354051
HI
Thx for configuration.everything is working perfect with the port 8081 and without.I opened port in my router.But could u tell me why I cant get connection using mobile network???
Can this work by plugging a camera into the Ethernet connection rather than the USB to receive data and the send to the web via USB dongle?
Great post – I got my webcam working in minutes. Do you know how to embed the stream in a web page? I tried using iframes, but couldn’t get it to work in Chrome.
Javascript and just poll the static PNG/JPG image every few second via HTTP?
Had problems and port 8081 was not listed after running command netstat -lnutp. The solution was to run the command motion.
How I can capture video and save it to the directory ?
Hi,
I followed the guidelines on this page but it seems something is wrong for me.
When browsing to the web interface (using Midori), I get instead of images a webpage with strange characters which updates continuously (probably every time a new frame is received).
This is the sort of things I get: “”–BoundaryString Content-type: image/jpeg Content-Length: 3944 ÿØÿà?JFIF????ÿÛC????? ?? ??????(?????1#%?(:3=Mqypdx\egcÿÛC???????/??/cB8BccccccccccccccccccccccccccccccccccccccccccccccccccÿÀ??ð?@??”??????ÿÄ????????????????? ?ÿĵ?????????????}???????!1A??Qa?”q?2‘¡?#B±Á?RÑð$3br‚ ?????%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤”” and it continues on and on.
This is when using the 8081 port. When modifying the port to 80 and typing only the IP, I get an error saying “the page couldn`t be loaded”.
I am running on a Raspberry PI connected to monitor, keyboard and mouse and trying to access it directly from the PI. I tried using both “eth0” and “wlan0” IPs just to make sure (the one sending me the characters is the eth0 one, the wlan0 IP address gives me error).
I managed to get images on my PC which is in the same network as the PI, but ideally I would manage to access it directly from the PI as this is what I will need it for later on. Please can anyone help me with this?
Thank you,
Silviu
This will not work over the internet at all for me. If I try to view it locally, it works intermittently and I have to restart the pi or my computer for it to work again. Refreshing the page causes it to stop working.
Thanks you for your posting!
Is it posible to use motion with the RaspberryPi cameraboard?
T
I’m using raspiberry pi camera and used latest raspbian 2013-07-26.
On raspi. I opened midor’s browseri and typed 192.168.X.X:8081, and I got dummy characters, but still? running.
On pc, I typed 192.168.x.x:8081 on google chrome’s browser.I got grey screen stating that Unable to open video device
I went 8080 to set configuration for both pc and pi, but no available on video.
Is there something wrong for using raspi camera?
I appreciate ur helping
Supra
hey, Thx for the very nice discription!
Sorry for my english:
Is it possibile to detecting Motion and send an alert mail ?
Thx
Thanks for the instructions.
I have noticed one thing though. I’m able to view the feed in Firefox only.
IE treets the address like a file to download but it never finishes.
Chrome doesn’t do anything at all. This is particularly strange as it doesn’t report an error, doesn’t start downloading just a new blank tab.
Has anyone else seen this behavior?
I too am experiencing this. Even on my android it just wants to download a file. Any help would be great.
Hi, thank you for your post, it is brill. Webcam is working and now busy looking at the front door. Is there a way i can send the output to my google drive account every hour of so, or alternatively save the files locally onto the raspberry pi and then FTP it to the web. Purpose is I would like to keep 24 hrs work on images.
Thanks
+1
I would be very interested in knowing how to send/save images to gDrive or gMail.
Cheers.
Hi. Thanks for the post. I followed the instructions exactly, but even though motion is running, when I try to access the pi, all I get in Chrome is the message “This webpage is not available”.
Just can’t access the webpage. What could be the problem?
I followed the directions but when I go to the page in chrome, Nothing happens. It just stays on the current page. When I try in internet explorer or on my android using the internet app, it downloads a file of indefinite size. Any suggestions?
I read somewhere that it works best on Firefox…
Most things work better in firefox 🙂
Hi,
Thanks for post. I have some troubles…
My cam works on internal 8081 port, but when I change 8081 -> 80 and set forwarding in router there is only 404
I’ve forward in router correctly, becouse my RPI wworked as PHP server.
I have no idea to fix this problem….
Motion comes with it’s own light weight web server that does not run PHP, so I assume that you have another web server installed on the RPi if you also have PHP functionality on there? Your not trying to start both of these on TCP Port 8081 are you?
I would suggest using “netstat -lnutp” to get a list of all the processes on your box and their network bindings, ensure that the Motion web server is successfully bound to the port you think it should be on.
As your getting a 404 I would guess your hitting that other web server process, either stop it for a while and re-test, or check the access/error logs on the PHP web server and see if there’s any entires for your 404, if there is then you defiantly have some kind of binding issue.
Hope that helps!
This worked a treat. However I notice it occasionally saves a swf file in the tmp folder. What’s this for?
From the motion configuration file:
# swf – gives you a flash film with extension .swf
Unfortunatelly it works only with many ports eq. 8005, 8081, 8070 (in thise case camera LED light) etc but not with 80, 95 etc (camera LED blinking).
The second problem is with my mobile phone… (lenovo A800)… when I put myIPadres:8081 , I can see that browser download file but not see like on laptop or computer. Instead of normal cam-view it download any *** file…
Hi Tom,
Thanks for your guide, I’m had error: “unable to open video device” when I access address http://raspberryIP:8081. Can you tell me solution for this?
Thank you!
Are you using a powered USB hub and a known working webcam?
Got this working using the following:
Rpi (duh!)
Microsoft Lifecam
Belkin Wireless Adapter
Samsung 2 amp Cell Phone Charger (it is slimmer to plug in anywhere)
I have 640×480 video and it looks good! Little choppy but good for monitoring my back yard! And I did not need a usb hub.
I’ve checked all the settings and it appears to be in order. Web Browser does not connect to 192.168.0.100:8081. Says it cannot connect.
If I stop the service and just type “motion” something starts up and begins to take rapid fire pictures with my webcam and store them in the home folder.
I’m using a Hercules WebCam Model WC04.
this is the output from netstat:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN –
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN –
udp 0 0 0.0.0.0:26252 0.0.0.0:* –
udp 0 0 0.0.0.0:68 0.0.0.0:* –
udp 0 0 192.168.11.20:123 0.0.0.0:* –
udp 0 0 127.0.0.1:123 0.0.0.0:* –
udp 0 0 0.0.0.0:123 0.0.0.0:*
Can’t connect to 192.168.1.16:8081 from any browser FF included. Any suggestions?
try 192.168.1.16:8081/
How can I change the default DHCP IP address to a static IP?
Anyway to limit how many pictures are taken or to change the directory for the saved images?
Thanks for the tutorial….web cam up and running.
Hi Tom,
I have connected a USB wifi dongle to the pi. It is configured as a wifi access point and has been given a static ip address by me. Now in my laptop I see a wifi connection as PI_AP, i connect to it and try to view the video feed caputured by the camera connected to the pi. In the web browser i enter 192.168.42.1:8081 (where 192.168.42.1 is the static ip address given to my USB wifi). I’m NOT connected to the internet, its just a wifi connection between my laptop and the USB wifi on the pi. I’m not able to see the video feed. Are there any changes I need to make in the \motion\motion.conf file? Everything works fine when my pi is connected to the internet via ethernet cable and my laptop is also on the same internet network, this way i can view the video feed, but not int he case when I just have a wifi network (NO Inernet) connectivity between my PC and the pi.
Any help would be appreiable.
Thanks
thanks it is working …. could i take pictures??? i want to take pictures and save it in rpi …. can any one help me??
Thanks ! It works for me ! The only problem is that my webcam isn’t compatible =P ! I’ll but one on Amazon soon as I can !
Help! When I go to sudo nano /ect/motion/motion.config the config file appears empty. Therefore I cannot perform any changes?
U misspelled sudo nano /ect/motion/motion.config
It is :
sudo nano /etc/motion/motion.config
Change ect to etc
Tom, I’ve been wanting to build one of these for a long time, however, I would like to use a camera module instead. (http://store.cutedigi.com/raspberry-pi-camera-module-5mp-wide-angle-160-degree/)
Can you see a problem with this?
Hi Alex, that should work fine 🙂
Everything is fine following you directions, except the video feed seems to only be active for about 24 hours. Is there something in the software that prevents the feed from going 24/7? I have to unplug the RPi and plug back, then the video feed returns for about 24 hrs.
Hi,
I am working on streaming webcam images over internet since a week but its not done yet.
I tried all the steps mentioned above.
When I start the service, LED on Webcam gets turned on. However I can’t see data on Webpage.
I tried to open webpage on Pi Board and instead of image, I am getting weird characters instead of image.
I tried this device:
0ac8:307b Z-Star Microelectronics Corp. USB 1.1 Webcam
and it works.
I used VLC to see the stream.
instead of trying to edit /etc/motion/motion.conf
do a sudo -s
then
motion
and you should see output from motion
then either from a vnc session or on your hdmi connection
and kb fire up the pi desktop browser and goto 127.0.0.1:8080
you will see
Motion 3.2.12 Running [1] Threads
All
click All
then config
then list
and you will see
daemon = on
process_id_file = /var/run/motion/motion.pid
setup_mode = off
videodevice = /dev/video0
v4l2_palette = 8
input = 8
…….
click each setting to change it
and the end click back
then write
and say yes
will write changes to motion.conf
rerun motion
when i type sudo service motion start i get
etc/init.d/motion: l: /etc/default/motion: X#: not found
I’ve had success with a webcam plugged directly into the Pi – no powered hub. I think this might have worked because I had already unplugged mouse, keyboard and screen.
I now have an Edimax wifi adapter and a HP HD2300 webcam running just fine.
Yes, also depends on how good the power source to the Raspberry Pi is, most setups however will end up needing some kind of powered hub in there.
I’m having trouble as I don’t care about saving any image taken, all I want is the stream. I’ve tried setting target_dir to /dev/null but it doesn’t like it. I would throw in a usb flash but 1 usb is for wifi, the other is the webcam. Any suggestions?
Unfortunately the Rpi is so very flaky that this only works like a toy. In order to actually make it useful for any real-world application, the files would have to be able to be written to someplace besides “/tmp/motion”. Changing that on Rpi B+ with Raspbian 05_05_2015 results in no files saved anywhere, and the orignal ‘target_dir’ vanishes.
One would like, for example, to be able to save them to a large USB stick. This is so fraught with mind-numbing permissions problems as to make the whole idea of ‘security monitoring’ practically impossible.
The ‘Largest’ SD card that works in Rpi is a measly 32 GB. This will not last long. As explained above, another USB stick, say 64 or 128 GB, simply won’t work.
A good idea, but no practical use.
jr
I’ve got two of them setup without any stability issues, one’s been up for over 3 months, and the files are saved off to a NAS on the network.
Hello, I’m a linux/RPi newb. How would I set this start automatically when the RPi boots?
This is what I have been looking for, however, I am not able to use a webcam. I have a 5mp camera that installs directly to the mobo of the pi. Is there any alteration of the instruction where a webcam is not required, only the Rasp Pi camera board? PlI look forward to your feedback.
Thank you,
TechGeek
Here is link for picamera:
http://www.home-automation-community.com/surveillance-with-raspberry-pi-noir-camera-howto/
I haven\t attempt this. But will attempt later.
Anyone got any idea if there is an easy way to turn this on and off on demand through the web interface? My Pi is a webserver and I don’t want the CPU active all the time.
Many thanks. It is took me 10 minutes. I had no problem. I had to followed step by step. I also tested my laptop, pc and another pc
So fortunately, I can work with robot, opencv3, etc. BTW, I’m am using compliant python3. Using latest Raspbian Wheezy(2015-05-05)