-
- Posts: 4
- Joined: Wed May 15, 2013 12:03 pm
Motion - Ip Camera Possible
Havent used the pi for a while but ordered a camera module yesterday and should be here tommorrow
Been waiting for it for a while tbh
Basically all I want to do is set up a basic IP cam to capture movement and pump the stream out to the web
Does motion do this - I know its picks up usb ok, just not sure if it will pick up the camera board??
I assume this will be a popular project so info will come soon enough - will have a tinker anyway
Thanks for any Info
Been waiting for it for a while tbh
Basically all I want to do is set up a basic IP cam to capture movement and pump the stream out to the web
Does motion do this - I know its picks up usb ok, just not sure if it will pick up the camera board??
I assume this will be a popular project so info will come soon enough - will have a tinker anyway
Thanks for any Info
Re: Motion - Ip Camera Possible
Every time recently I've tried Motion on a Pi I've had a segmentation fault.
Re: Motion - Ip Camera Possible
You can use the command-line in the camera post for that.
No , motion won't detect the camera. No Linux application will
recognize the Raspi camera as webcam , if it is not written
beforehand to work with it.
ghans
No , motion won't detect the camera. No Linux application will
recognize the Raspi camera as webcam , if it is not written
beforehand to work with it.
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Re: Motion - Ip Camera Possible
Motion is actually quite flexible on input, as well as using the normal V4L and UVC camera input
it can also use IP cameras by putting netcam_url in motion.conf:
So, we can workaround the lack of V4L driver by making a "local" ip camera out of the raspi camera.
motion.conf:
- get the Raspi camera to dump jpegs into a local webserver running on the pi:
/usr/lib/cgi-bin/raspicam
it can also use IP cameras by putting netcam_url in motion.conf:
So, we can workaround the lack of V4L driver by making a "local" ip camera out of the raspi camera.
motion.conf:
Code: Select all
netcam_url http://127.0.0.1/cgi-bin/raspicam
/usr/lib/cgi-bin/raspicam
Code: Select all
raspistill -o -
Last edited by mikerr on Fri May 17, 2013 8:00 am, edited 1 time in total.
Android app - Raspi Card Imager - download and image SD cards - No PC required !
Re: Motion - Ip Camera Possible
mikerr, can you explain in more details how to do that? When I run raspistill it sends garbage on the screenmikerr wrote:
- get the Raspi camera to dump jpegs into a local webserver running on the pi:
/home/www/cgi-bin/raspicamCode: Select all
raspistill -o -
Re: Motion - Ip Camera Possible
mikerr ,
that's a nice solution !
But should raspicam be a bash script ?
Like this , perhaps :
ghans
that's a nice solution !
But should raspicam be a bash script ?
Like this , perhaps :
Code: Select all
#!/bin/bash
raspistill -o
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Re: Motion - Ip Camera Possible
Yes, the full script to put in cgi-bin is a bit more expanded than that too:
/usr/lib/cgi-bin/raspicam
motion can't handle the full 2592x1944 frame, so I'm reducing it there, and -t 0 captures a frame immediately.
You may need this too:
I can confirm motion does actually work with that !
Note that's only about 2 fps, due to starting/stopping raspistill per image.
Motion doesn't support h264 that raspivid outputs, it only supports jpeg or mjpeg.
/usr/lib/cgi-bin/raspicam
Code: Select all
#!/bin/bash
echo "Content-type: image/jpeg"
echo
raspistill -t 0 -w 1024 -h 768 -o -
You may need this too:
Code: Select all
sudo chmod 777 /dev/vchiq
Note that's only about 2 fps, due to starting/stopping raspistill per image.
Motion doesn't support h264 that raspivid outputs, it only supports jpeg or mjpeg.
Android app - Raspi Card Imager - download and image SD cards - No PC required !
Re: Motion - Ip Camera Possible
a simple solution to the flickering on the screen (because -nopreview is broken) is to make the preview size very small and place it to the left and above the screen so only ONE pixel is updated on the console like so
/opt/vc/bin/raspistill -t 0 -w 1024 -h 768 -p -31,-23,32,24 -o -
/opt/vc/bin/raspistill -t 0 -w 1024 -h 768 -p -31,-23,32,24 -o -
Re: Motion - Ip Camera Possible
If you are up for recompiling, there is a fix for the preview issue in the thread about it.SN wrote:a simple solution to the flickering on the screen (because -nopreview is broken) is to make the preview size very small and place it to the left and above the screen so only ONE pixel is updated on the console like so
/opt/vc/bin/raspistill -t 0 -w 1024 -h 768 -p -31,-23,32,24 -o -
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.
Re: Motion - Ip Camera Possible
I know, but sadly I'm not 'up for it'jamesh wrote:If you are up for recompiling, there is a fix for the preview issue in the thread about it.SN wrote:a simple solution to the flickering on the screen (because -nopreview is broken) is to make the preview size very small and place it to the left and above the screen so only ONE pixel is updated on the console like so
/opt/vc/bin/raspistill -t 0 -w 1024 -h 768 -p -31,-23,32,24 -o -

Re: Motion - Ip Camera Possible
Motion isn't recognising my camera. I can capture stills with raspistill but I don't think the cgi script is working properly as I get a broken image link when browsing to /cgi-bin/raspicam. Does anyone have any suggestions?
Thanks
Thanks
Re: Motion - Ip Camera Possible
likewise, I get the same error,
running wget, I can see the file is only 32 bytes.
I tried using nginx and creating a php script to run raspistill as a system call.
<?php
system ("raspistill -t 0 -ex night -hf -o -");
?>
it works as expected when run from the php shell
ie
php raspicam
but when called from a browser or wget I get
* failed to open vchiq instance
running wget, I can see the file is only 32 bytes.
I tried using nginx and creating a php script to run raspistill as a system call.
<?php
system ("raspistill -t 0 -ex night -hf -o -");
?>
it works as expected when run from the php shell
ie
php raspicam
but when called from a browser or wget I get
* failed to open vchiq instance
Re: Motion - Ip Camera Possible
May be
can help
Code: Select all
chmod 777 /dev/vchid
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - Ip Camera Possible
Rather than blanket change the permissions on /dev/vchiq, it might be safer and more robust to add the user account under which the web server runs to the video group, then reboot.
E.g. for me using nginx, this was:
E.g. for me using nginx, this was:
Code: Select all
sudo usermod -a -G video www-data
sudo shutdown -r now
Re: Motion - Ip Camera Possible
yes, brain fade - it was late last night, I eventually just added www-data to the video group in /etc/group.
replacing the bash script seems to finally get it working for me ( opens ok in a browser):
#!/usr/bin/perl
select STDOUT;
$|=1;
print "Content-type: image/jpeg\n\n";
system "raspistill -t 1000 -ex night -hf -o -";
next step configure motion.
Pete
replacing the bash script seems to finally get it working for me ( opens ok in a browser):
#!/usr/bin/perl
select STDOUT;
$|=1;
print "Content-type: image/jpeg\n\n";
system "raspistill -t 1000 -ex night -hf -o -";
next step configure motion.
Pete
Re: Motion - Ip Camera Possible
this was/is a good thread . it got me going on the road to using motion with my raspicamera.
there were some dots for me to connect however, from the discussion above, since I'd never done webservers and thought that "cgi" had something to do with computer graphics.
there is good article on setting up a simple server in the last issue of Magpi by Jason Davies, "Setting up a simple intranet". This will get your apache2 server running.
then I found the following on enabling a cgi scripts for apache
http://www.techrepublic.com/blog/doityo ... rver/1066
and i did need to make the permissions change suggested above
i'm not sure what this permission changes means but suspect i have to do it on every reboot. first i had the raspicam server working, then it wouldn't post pictures, then I eventually figured out that i had to give the permissions again.
now begins the fun with motion.
Sarge

there were some dots for me to connect however, from the discussion above, since I'd never done webservers and thought that "cgi" had something to do with computer graphics.
there is good article on setting up a simple server in the last issue of Magpi by Jason Davies, "Setting up a simple intranet". This will get your apache2 server running.
then I found the following on enabling a cgi scripts for apache
http://www.techrepublic.com/blog/doityo ... rver/1066
and i did need to make the permissions change suggested above
Code: Select all
sudo chmod 777 /dev/vchiq
now begins the fun with motion.
Sarge
Re: Motion - Ip Camera Possible
Are we opposed to using external hardware sensors? Because why wouldn't you guys just wire a motion detector
http://compare.ebay.com/like/1810526712 ... s&var=sbar
and wire it up via gpio and write a bash script to toggle the camera on/off with the motion detector?
http://compare.ebay.com/like/1810526712 ... s&var=sbar
and wire it up via gpio and write a bash script to toggle the camera on/off with the motion detector?
Re: Motion - Ip Camera Possible
Isn't the following aproach easier:
You let the raspicam take pictures every x msec and store it into 1 folder.
When there is motion, you copy these pictures to a seperate "locked" folder.
When space on the first folder gets low, you delete the oldest pictures. The interesting pictures remain safe in the second folder until you review them manually.
This is how the G-sensor in a car-sensor goes about it, to make sure in case of an accident the images are stored safely.
You let the raspicam take pictures every x msec and store it into 1 folder.
When there is motion, you copy these pictures to a seperate "locked" folder.
When space on the first folder gets low, you delete the oldest pictures. The interesting pictures remain safe in the second folder until you review them manually.
This is how the G-sensor in a car-sensor goes about it, to make sure in case of an accident the images are stored safely.
-
- Posts: 17
- Joined: Mon Jan 30, 2012 9:57 am
Re: Motion - Ip Camera Possible
What I have been doing that seems to work well is;
Use motion with a 'normal' webcam at low res, when motion is triggered, use the 'on_motion_detected' hook to call the raspistill command which then stores a full res image.
not the most elegant solution, but works well so far.
Use motion with a 'normal' webcam at low res, when motion is triggered, use the 'on_motion_detected' hook to call the raspistill command which then stores a full res image.
not the most elegant solution, but works well so far.
Re: Motion - Ip Camera Possible
@decrot,
yep, I was thinking along those lines as well but was steered to the motion solution by others on the forum.
my guess is the camera is going to have a larger field of view and certainly a greater range.
the typical PIR sensor has a maximum sensing range of 5 - 7m, the long range version Panasonic sensors have 12m range. I think the camera should be better.
also, motion is continuously taking pictures and comparing pixels to determine change/motion. since it holds on to frames, it is theoretically* able to rewind and capture the whole sequence of events.
since my goal is to view wildlife across an open field, these features would be nice.
S
* I mean the documented features say it is possible. I just haven't implemented it yet.
yep, I was thinking along those lines as well but was steered to the motion solution by others on the forum.
my guess is the camera is going to have a larger field of view and certainly a greater range.
the typical PIR sensor has a maximum sensing range of 5 - 7m, the long range version Panasonic sensors have 12m range. I think the camera should be better.
also, motion is continuously taking pictures and comparing pixels to determine change/motion. since it holds on to frames, it is theoretically* able to rewind and capture the whole sequence of events.
since my goal is to view wildlife across an open field, these features would be nice.
S
* I mean the documented features say it is possible. I just haven't implemented it yet.
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - Ip Camera Possible
@Sarge - if you add the web server's user account (usually www-data) to the video group as described above, that will ensure you have the correct permissions even after a reboot.
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - Ip Camera Possible
I've had some initial success creating a version of motion which has an "MMAL" camera module and options - if you want to try using it, I've shared it here: https://www.dropbox.com/s/xdfcxm5hu71s9 ... mal.tar.gz
Please be aware this is very early and experimental:
[*] Based on motion SVN trunk at revision 557 - note that conf file syntax is different to the release version.
[*] There is an included config file which works for me.
[*] None of the camera setting options from raspivid/raspistill are currently supported (but hflip is on by default)
[*] You may well run out of memory if you try adjusting the image size and framerate (ENOSPC error)
[*] MySQL and PostgreSQL support are not present.
[*] Should work with the usual motion required packages as available in the Raspbian repos (see http://www.lavrsen.dk/foswiki/bin/view/ ... stallation)
Let me know how you get on if you try it! And whether it'll be worth me putting in more effort (more options, optimisation, packaging properly and sharing the source).
Please be aware this is very early and experimental:
[*] Based on motion SVN trunk at revision 557 - note that conf file syntax is different to the release version.
[*] There is an included config file which works for me.
[*] None of the camera setting options from raspivid/raspistill are currently supported (but hflip is on by default)
[*] You may well run out of memory if you try adjusting the image size and framerate (ENOSPC error)
[*] MySQL and PostgreSQL support are not present.
[*] Should work with the usual motion required packages as available in the Raspbian repos (see http://www.lavrsen.dk/foswiki/bin/view/ ... stallation)
Let me know how you get on if you try it! And whether it'll be worth me putting in more effort (more options, optimisation, packaging properly and sharing the source).
Last edited by dozencrows on Mon Jun 24, 2013 1:06 pm, edited 1 time in total.
Re: Motion - Ip Camera Possible
Hi,
Thanks for motion-mmal, please could I get a copy of the source code?
Thanks,
Kenny
Thanks for motion-mmal, please could I get a copy of the source code?
Thanks,
Kenny
Re: Motion - Ip Camera Possible
Well that's fantastic work, thanks !
Android app - Raspi Card Imager - download and image SD cards - No PC required !
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - Ip Camera Possible
Thanks for the replies!
I'll look into getting the source up on to Github over the next few days (something I've not done before). I also need to sort out the build process; I've currently got it cross-compiling through Eclipse which won't suit everyone. The additional Pi Videocore libs & headers have made it a bit awkward for me personally to use autotools; I'll have a look at cmake as per the rest of the Pi userland stuff.
I'll also do some profiling - the performance is only a bit better than the cgi approach, and some quick experimentation suggests that the ffmpeg and jpeg encoding in software might be proving costly - and I may be doing something "unperformant" in my own code too!
There may be a way to use MMAL to do image encoding from motion via the Pi's GPU to improve speed, but that might mean messing with how motion works. The current implementation fits in quite nicely with motion's architecture and main loop, even down to the MMAL interface returning image frames in the format that motion uses internally.
I'll look into getting the source up on to Github over the next few days (something I've not done before). I also need to sort out the build process; I've currently got it cross-compiling through Eclipse which won't suit everyone. The additional Pi Videocore libs & headers have made it a bit awkward for me personally to use autotools; I'll have a look at cmake as per the rest of the Pi userland stuff.
I'll also do some profiling - the performance is only a bit better than the cgi approach, and some quick experimentation suggests that the ffmpeg and jpeg encoding in software might be proving costly - and I may be doing something "unperformant" in my own code too!
There may be a way to use MMAL to do image encoding from motion via the Pi's GPU to improve speed, but that might mean messing with how motion works. The current implementation fits in quite nicely with motion's architecture and main loop, even down to the MMAL interface returning image frames in the format that motion uses internally.