kiteboywales
Posts: 4
Joined: Wed May 15, 2013 12:03 pm

Motion - Ip Camera Possible

Wed May 15, 2013 12:09 pm

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

User avatar
piglet
Posts: 909
Joined: Sat Aug 27, 2011 1:16 pm

Re: Motion - Ip Camera Possible

Wed May 15, 2013 12:16 pm

Every time recently I've tried Motion on a Pi I've had a segmentation fault.

ghans
Posts: 7873
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Motion - Ip Camera Possible

Wed May 15, 2013 12:57 pm

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
• 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

mikerr
Posts: 2778
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Motion - Ip Camera Possible

Wed May 15, 2013 1:27 pm

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:

Code: Select all

netcam_url http://127.0.0.1/cgi-bin/raspicam 
- get the Raspi camera to dump jpegs into a local webserver running on the pi:

/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 !

scorp
Posts: 96
Joined: Tue May 29, 2012 6:21 pm

Re: Motion - Ip Camera Possible

Thu May 16, 2013 5:44 pm

mikerr wrote:
- get the Raspi camera to dump jpegs into a local webserver running on the pi:

/home/www/cgi-bin/raspicam

Code: Select all

raspistill -o -
mikerr, can you explain in more details how to do that? When I run raspistill it sends garbage on the screen

ghans
Posts: 7873
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Motion - Ip Camera Possible

Fri May 17, 2013 5:13 am

mikerr ,
that's a nice solution !

But should raspicam be a bash script ?

Like this , perhaps :

Code: Select all

#!/bin/bash
raspistill -o
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

mikerr
Posts: 2778
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Motion - Ip Camera Possible

Fri May 17, 2013 7:41 am

Yes, the full script to put in cgi-bin is a bit more expanded than that too:

/usr/lib/cgi-bin/raspicam

Code: Select all

#!/bin/bash
echo "Content-type: image/jpeg"
echo
raspistill -t 0 -w 1024 -h 768 -o -
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:

Code: Select all

 sudo chmod 777 /dev/vchiq
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.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Motion - Ip Camera Possible

Fri May 17, 2013 3:06 pm

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 -
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23682
Joined: Sat Jul 30, 2011 7:41 pm

Re: Motion - Ip Camera Possible

Fri May 17, 2013 3:33 pm

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 -
If you are up for recompiling, there is a fix for the preview issue in the thread about it.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Motion - Ip Camera Possible

Fri May 17, 2013 3:36 pm

jamesh wrote:
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 -
If you are up for recompiling, there is a fix for the preview issue in the thread about it.
I know, but sadly I'm not 'up for it' ;-)
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

mjb
Posts: 1
Joined: Sat May 18, 2013 3:00 pm

Re: Motion - Ip Camera Possible

Sat May 18, 2013 3:10 pm

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

peewee2
Posts: 61
Joined: Sun Apr 14, 2013 7:04 pm

Re: Motion - Ip Camera Possible

Sat May 18, 2013 11:53 pm

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

scorp
Posts: 96
Joined: Tue May 29, 2012 6:21 pm

Re: Motion - Ip Camera Possible

Sun May 19, 2013 8:48 am

May be

Code: Select all

chmod 777 /dev/vchid
can help

User avatar
dozencrows
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm

Re: Motion - Ip Camera Possible

Sun May 19, 2013 11:39 am

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:

Code: Select all

sudo usermod -a -G video www-data
sudo shutdown -r now

peewee2
Posts: 61
Joined: Sun Apr 14, 2013 7:04 pm

Re: Motion - Ip Camera Possible

Sun May 19, 2013 1:32 pm

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

User avatar
Sarge
Posts: 34
Joined: Sun Jan 13, 2013 4:57 pm

Re: Motion - Ip Camera Possible

Tue May 21, 2013 1:36 am

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

Code: Select all

sudo chmod 777 /dev/vchiq
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

decrot
Posts: 10
Joined: Sat Mar 16, 2013 3:47 pm

Re: Motion - Ip Camera Possible

Tue May 21, 2013 3:12 am

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?

Nu7s
Posts: 57
Joined: Wed Jul 25, 2012 9:14 am

Re: Motion - Ip Camera Possible

Tue May 21, 2013 9:18 am

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.

kevsan2402
Posts: 17
Joined: Mon Jan 30, 2012 9:57 am

Re: Motion - Ip Camera Possible

Tue May 21, 2013 10:00 am

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.

User avatar
Sarge
Posts: 34
Joined: Sun Jan 13, 2013 4:57 pm

Re: Motion - Ip Camera Possible

Tue May 21, 2013 5:33 pm

@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.

User avatar
dozencrows
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm

Re: Motion - Ip Camera Possible

Tue May 21, 2013 10:22 pm

@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.

User avatar
dozencrows
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm

Re: Motion - Ip Camera Possible

Thu May 23, 2013 3:36 pm

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).
Last edited by dozencrows on Mon Jun 24, 2013 1:06 pm, edited 1 time in total.

kmdm
Posts: 2
Joined: Thu May 23, 2013 5:01 pm

Re: Motion - Ip Camera Possible

Thu May 23, 2013 5:02 pm

Hi,

Thanks for motion-mmal, please could I get a copy of the source code?

Thanks,
Kenny

mikerr
Posts: 2778
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Motion - Ip Camera Possible

Thu May 23, 2013 5:43 pm

Well that's fantastic work, thanks !
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
dozencrows
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm

Re: Motion - Ip Camera Possible

Thu May 23, 2013 7:25 pm

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.

Return to “Camera board”