Motion - MMAL camera


469 posts   Page 3 of 19   1, 2, 3, 4, 5, 6 ... 19
by dpguest » Thu May 30, 2013 3:44 pm
What libraries do I have to install in order to send emails when motion detects movement?

Which script should I use for sending the mail after I have installed the proper libraries...

thanks for any help...
Posts: 28
Joined: Wed Feb 06, 2013 4:17 pm
by Nu7s » Thu May 30, 2013 7:07 pm
Thanks, it's working great!
There are alot of people asking how to do stuff, I would suggest reading the motion guide:
http://www.lavrsen.dk/foswiki/bin/view/ ... otionGuide
Posts: 57
Joined: Wed Jul 25, 2012 9:14 am
by adayforgotten » Thu May 30, 2013 8:00 pm
I cloned your git and compiled it without issue. I read through your build readme and installed the dependencies before attempting to make sure it went smooth.

I edited very few conf settings as I am only doing the preliminary testing but GOOD JOB. Runs smoothly so far set to 720p25 @ 750kbps. I am able to pull up the feed no problem.

So far so good, I'll post more details later. I can't test most stuff as I am remote and the camera is in a fairly dark and empty room.
Posts: 17
Joined: Wed Aug 01, 2012 5:23 pm
by flatline403 » Thu May 30, 2013 10:00 pm
I unzipped the tar to a folder, but I'm unable to run motion (mmal). I get an error that libmmal_core.so cannot be loaded. Did extensive Google searching for that and can't find a package to install with apt-get.
Code: Select all
pi@raspberrypi ~/motion-MMAL $ ls
motion  motion-mmalcam.conf
pi@raspberrypi ~/motion-MMAL $ ./motion -h
./motion: error while loading shared libraries: libmmal_core.so: cannot open shared object file: No such file or directory


I do have libjpeg62 installed:
Code: Select all
pi@raspberrypi ~/motion-MMAL $ sudo apt-get install libjpeg62
Reading package lists... Done
Building dependency tree
Reading state information... Done
libjpeg62 is already the newest version.
The following package was automatically installed and is no longer required:
  icelib
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 290 not upgraded.
pi@raspberrypi ~/motion-MMAL $


Suggestions? Anyone know what package libmmal_core.so is in?

EDIT: Fixed by running sudo apt-get upgrade
Last edited by flatline403 on Fri May 31, 2013 12:32 am, edited 1 time in total.
Posts: 4
Joined: Sat Feb 18, 2012 10:26 am
by adayforgotten » Thu May 30, 2013 10:24 pm
In configs/motion-mmalcam.conf:
The 'daemon on' directive has NO effect.

I did this as a workaround:
nohup ./motion -n -c configs/motion-mmalcam.conf 1>/dev/null 2>&1 </dev/null &
Posts: 17
Joined: Wed Aug 01, 2012 5:23 pm
by flatline403 » Fri May 31, 2013 12:35 am
I am now able to run Motion MMAL, but I get the following error:
Code: Select all
pi@raspberrypi ~/motion-MMAL $ ./motion -n -c motion-mmalcam.conf
[-1238584480] [NTC] [ALL] conf_load: Processing thread 0 - config file motion-mmalcam.conf
[-1238584480] [NTC] [ALL] motion_startup: Motion trunkREV557 Started
[-1238584480] [NTC] [ALL] motion_startup: Logging to syslog
[-1238584480] [NTC] [ALL] motion_startup: Using log type (ALL) log level (WRN)
[1] [ALR] [VID] mmalcam_start: MMAL Camera thread starting... for camera (vc.ril.camera) of 1024 x 576 at 5 fps
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
[1] [ERR] [VID] Failed to create MMAL camera component create_camera_component
[1] [ALR] [VID] MMAL Camera cleanup


The only time the light on the camera comes on is when the Pi is booting. In a web browser at the Pi's ip:8081 I see "Unable to open video device since <date>".

Any suggestions?

Posts: 4
Joined: Sat Feb 18, 2012 10:26 am
by TarjeiB » Fri May 31, 2013 6:40 am
flatline403 wrote:I am now able to run Motion MMAL, but I get the following error:
Code: Select all
pi@raspberrypi ~/motion-MMAL $ ./motion -n -c motion-mmalcam.conf
[-1238584480] [NTC] [ALL] conf_load: Processing thread 0 - config file motion-mmalcam.conf
[-1238584480] [NTC] [ALL] motion_startup: Motion trunkREV557 Started
[-1238584480] [NTC] [ALL] motion_startup: Logging to syslog
[-1238584480] [NTC] [ALL] motion_startup: Using log type (ALL) log level (WRN)
[1] [ALR] [VID] mmalcam_start: MMAL Camera thread starting... for camera (vc.ril.camera) of 1024 x 576 at 5 fps
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
[1] [ERR] [VID] Failed to create MMAL camera component create_camera_component
[1] [ALR] [VID] MMAL Camera cleanup


The only time the light on the camera comes on is when the Pi is booting. In a web browser at the Pi's ip:8081 I see "Unable to open video device since <date>".

Any suggestions?

You should make your camera work as per instructions first, then afterwards try motion :) Hint: Did you apt-get upgrade and enable it in raspi-config?
Posts: 149
Joined: Thu Jul 12, 2012 3:33 pm
by dozencrows » Sat Jun 01, 2013 12:39 pm
A note on performance...

Prompted by some of the discussion above, I've done some experiments to compare my motion build with the Raspbian package, and to compare a USB camera with the Pi camera - purely looking at CPU load as reported by top.

The evidence I have from this suggests that the performance bottleneck when running motion on the Pi is the image processing carried out by motion itself, rather than the capture device chosen.

  • CPU load for either version of motion and a USB camera is pretty much the same - tried at resolutions 352x288 (~20%) and 800x600 (~98%)
  • CPU load for the Pi camera version at 352x288 is around 18% and at 1024x576 is around 98% (800x600 didn't work).
Your exact mileage may vary - I'm only using the Pi for motion, and am accessing the web stream over a wireless connection at the same time.

I've got a few ideas that might be worth trying to improve the performance and thus quality - I'll post the results if I get the time to try these:

  • Hand optimise some of motion's processing on the Pi (look at inner loops in ARM assembler, look at CPU cache usage).
  • Use the Pi camera's preview capture port at low resolution to detect motion; then use the main capture port at higher resolution to record images.
  • Try porting the image processing to the GPU using Open GL ES (likely to be hard work and risk not gaining anything due to image transfer to GPU).
Any other suggestions welcome!
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by dozencrows » Sat Jun 01, 2013 2:10 pm
A note on daemon support...

If you set the config file options as follows, the MMAL build of motion should run as a daemon when logged in as user 'pi':
Code: Select all
# Start in daemon (background) mode and release terminal (default: off)
daemon on

# File to store the process ID, also called pid file. (default: not defined)
process_id_file /home/pi/motion.pid

The key part is to make sure the user account running the application has write permission to the pid file.

And make sure you run motion without the -n option!

As there isn't currently a proper package or install process, there isn't any set of scripts that can run my motion build on startup. These are areas I don't yet have much experience with for Linux, so if anyone with greater knowledge wants to contribute...?
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by dozencrows » Sat Jun 01, 2013 2:16 pm
A note on image resolution...

Currently, only certain resolutions work. My personal testing has shown the following work:

  • 352x288
  • 640x480
  • 1024x576

The higher the resolution, the greater the CPU cost - and the risk you might lock up your Pi, depending on the power supply stability and what other devices and applications you are running.

If you try a resolution and start getting a lot of log messages of the form:
Code: Select all
[1] [ERR] [VID] mmalcam_next: cmd 0 flags 00000004 size 512256/512256 at b2f5b020

then that resolution isn't going to behave correctly at the moment.

I'm looking into a fix that may allow a greater range of resolutions to work.
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by lowflyer » Sat Jun 01, 2013 2:36 pm
Hi!

Thanks for this superb work! The Foundation should be very proud of you (as well as being proud of themselves!!).

It works fine for me :)

I like the concept of doing this:
Use the Pi camera's preview capture port at low resolution to detect motion; then use the main capture port at higher resolution to record images.

Would it be possible to get very high resolution stills from the camera when the preview detects motion? That would be a real winner!
Posts: 70
Joined: Sat Jun 01, 2013 2:27 pm
by dozencrows » Sat Jun 01, 2013 3:11 pm
The source in GitHub now builds with the MySQL and PostgreSQL libraries, so database logging should be available.
https://github.com/dozencrows/motion
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by dozencrows » Sat Jun 01, 2013 4:47 pm
lowflyer wrote:Thanks for this superb work! The Foundation should be very proud of you (as well as being proud of themselves!!)
You're welcome. There is a disclaimer, though: I am in no way connected with the Foundation.

lowflyer wrote:Would it be possible to get very high resolution stills from the camera when the preview detects motion? That would be a real winner!
That's something I intend to try - will keep you posted. It may be a while, though.
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by jum » Sun Jun 02, 2013 3:41 pm
craigc wrote:As an suggetion try dropping the resolution down to 768x576 (or 640x480) and see if its a bit more stable. I had mine up high to start with but I found it very slow to do anything else on the machine. Overclocking might be your friend if its more stable at the lower resolution.


Thanks craigc - I have had better luck at 640x480. Also dozencrows post above about resolution vs CPU usage is very informing, basically there is more work to be done before motion and the camera board will work reliably at higher resolutions.

I've also noticed that the RPi power LED and the camera board LED both dim when a picture is being taken, even if I use a "2 amp" USB power supply. (Also get some slight horizontal banding in the pictures taken).

Also when using 640x480 res (4:3 aspect), you do not get full horizontal field of view. Would need a 640x400 or 640x360 mode to use full sensor width.
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm
by dpguest » Sun Jun 02, 2013 6:14 pm
dozencrews ...

thanks for the great work .. your modifications are working like a charm. I finally figured out that the semicolon at the beginning of the line of external commands was turning them into comments...

Now Motion is informing me when it starts an event and then sends me the movie when it is saved....

Using a 1.5 amp power supply, a class 10 SD and overclocking to 950 is working well ... and lets me run a continuous pipresents presentation simultaneously.

Nice job ....
Posts: 28
Joined: Wed Feb 06, 2013 4:17 pm
by dozencrows » Sun Jun 02, 2013 8:25 pm
@dpguest - great to hear that it's working well for you! It's quite rewarding to find my little "scratch an own itch" project is helpful to others - I started this originally just to spy on my cat ;)
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by jum » Mon Jun 03, 2013 10:30 am
dozencrows wrote:A note on image resolution...

Currently, only certain resolutions work. My personal testing has shown the following work:

  • 352x288
  • 640x480
  • 1024x576



512 x 288 also works and seems to use little CPU.
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm
by bjornatic » Wed Jun 05, 2013 3:53 pm
I'm using 768x432 (16:9) wich gives me the widest field of view using motion MMAL, but not the biggest. If I use 4:3 resolutions, the field of view narrows...

With Raspistill I can get a full frame image (with the biggest field of view) using 3456 × 2592 (4:3) resolution.

Does anyone managed to reach the biggest field of view but at lower resolution using Motion MMAL ?

And, bonus question :
Motion MMAL is generating a video on motion detect. Now I would like to restrict movie creation when motion is detectect in specific areas defined "area_detect". Sure I can launch an command with "on_area_detected", but as long as there is motion anywhere on the pic, a movie is created...

On the Motion main site, they say " ffmpeg_cap_new" controls this behavior... but the parameter is not present in the Motion-MMAL config file....

Is there maybe another way to archive this ?

I'm actually so sorry to ask you this, dozencrows... I'm sure your cat doesnt ask so much questions. :)
Posts: 20
Joined: Wed May 15, 2013 4:44 pm
by Rabis1848 » Fri Jun 07, 2013 8:59 pm
Hi,

my problem is :
    [1] Failed to open video device /dev/video0: No such file or directory
with the config file "motion-mmalcam.conf" from github motion-mmal-test.
The camera is enabled. Motion is version 3.2.12
Code: Select all
pi@fileserverpi ~/motion-mmal-test $ sudo motion -n -c ./configs/motion-mmalcam.conf

Is something else? Thanks for answer & help

Rabis1848
Posts: 2
Joined: Fri Jun 07, 2013 8:41 pm
by Rabis1848 » Fri Jun 07, 2013 9:08 pm
Hi,
I think thats better:

    pi@fileserverpi ~/motion-mmal-test $ sudo motion -n -c ./configs/motion-mmalcam.conf
    [0] Processing thread 0 - config file ./configs/motion-mmalcam.conf
    [0] Unknown config option "log_level"
    [0] Unknown config option "log_type"
    [0] Unknown config option "netcam_keepalive"
    [0] Unknown config option "mmalcam_name"
    [0] Unknown config option "mmalcam_control_params"
    [0] Unknown config option "despeckle_filter"
    [0] Unknown config option "event_gap"
    [0] Unknown config option "max_movie_time"
    [0] Unknown config option "emulate_motion"
    [0] Unknown config option "output_pictures"
    [0] Unknown config option "output_debug_pictures"
    [0] Unknown config option "picture_type"
    [0] Unknown config option "ffmpeg_output_movies"
    [0] Unknown config option "ffmpeg_output_debug_movies"
    [0] Unknown config option "use_extpipe"
    [0] Unknown config option "locate_motion_mode"
    [0] Unknown config option "locate_motion_style"
    [0] Unknown config option "picture_filename"
    [0] Unknown config option "ipv6_enabled"
    [0] Unknown config option "stream_port"
    [0] Unknown config option "stream_quality"
    [0] Unknown config option "stream_motion"
    [0] Unknown config option "stream_maxrate"
    [0] Unknown config option "stream_localhost"
    [0] Unknown config option "stream_limit"
    [0] Unknown config option "stream_auth_method"
    [0] Unknown config option "webcontrol_port"
    [0] Unknown config option "webcontrol_localhost"
    [0] Unknown config option "webcontrol_html_output"
    [0] Motion 3.2.12 Started
    [0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
    [0] Thread 1 is from ./configs/motion-mmalcam.conf
    [1] Thread 1 started
    [1] Failed to open video device /dev/video0: No such file or directory
    [1] Could not fetch initial image from camera
    [1] Motion continues using width and height from config file(s)
    [1] Resizing pre_capture buffer to 1 items
    [1] Retrying until successful connection with camera
    [1] Failed to open video device /dev/video0: No such file or directory
;)
Rabis1848
Posts: 2
Joined: Fri Jun 07, 2013 8:41 pm
by dozencrows » Sat Jun 08, 2013 9:12 am
Hi @Rabis1848

Have you installed the original motion package from the Raspbian repositories? If so, I suspect you may be running this original motion with the MMAL configuration file, which it will not understand.

You need to ensure you run either the motion executable built from the source in Github where you got the config file, or from the tarball I shared on Google Drive. As mentioned in some previous posts, this can be done by typing ./motion -n -c motion_mmalcam.config in the same directory as the updated binary and config file. The ./ suffix is critical as it will ensure your local copy of motion is run, rather than the installed package.

The MMAL motion binary is built from a more up to date copy of the source, where the motion developers changed the names of some of the config file options - hence the messages in your post about "unknown config option".

Hope that helps!
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by dozencrows » Sat Jun 08, 2013 2:16 pm
Hi @bjornatic

Thanks for the resolution tip!

I think for restricting the area in which motion is detected you could try the mask_file feature described here: http://www.lavrsen.dk/foswiki/bin/view/ ... #mask_file. Caveat - I've not tested this with the MMAL version, however the option is present and there is code there to handle it.

ffmpeg_cap_new is not present in the latest source for the motion package (which I used for the MMAL version); also ffmpeg_cap_motion is also no longer present. Having read the descriptions of those options, I don't think they would achieve what you're after anyway.

My cat does ask questions a lot - however it's always the same one... ;)
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm
by bjornatic » Sat Jun 08, 2013 5:08 pm
Thanks for your answer ! I'll try it out and let you know. :-)
Posts: 20
Joined: Wed May 15, 2013 4:44 pm
by bjornatic » Mon Jun 10, 2013 11:12 am
Me again :D

So, using the mask option will do, I think.

But, before that I would like to use the full frame image... wich is not the case when using motion.

If you make a snapshop using raspistill at the same definition as you are using on motion, you will notice a bigger field of view.

Do you think this is possible ?

And I think your cat would appreciate being shown full frame. ;)
Posts: 20
Joined: Wed May 15, 2013 4:44 pm
by dozencrows » Mon Jun 10, 2013 8:37 pm
I'm using the video capture "port" on the camera in motion, which has a different field of view than the still capture port - see viewtopic.php?f=43&t=32605&p=359411&hilit=field+of+view#p359411 and various other forum posts about camera characteristics.

FOV is something controlled by the camera's firmware; the only parameters available currently that affect FOV are the horizontal and vertical image resolution, as you've already discovered.

I could provide an option to use the still image port, but according to what I've read elsewhere in this forum, that will scupper any chance of increasing the frame rate certainly at high resolutions - see viewtopic.php?f=43&t=46706

I hope to find some time this weekend to look into this and other possible suggestions kindly posted to this forum.
User avatar
Posts: 172
Joined: Sat Aug 04, 2012 6:02 pm