Re: Motion - MMAL camera
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...
Which script should I use for sending the mail after I have installed the proper libraries...
thanks for any help...
Re: Motion - MMAL camera
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
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: 17
- Joined: Wed Aug 01, 2012 5:23 pm
Re: Motion - MMAL camera
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.
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: 4
- Joined: Sat Feb 18, 2012 10:26 am
Re: Motion - MMAL camera
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.
I do have libjpeg62 installed:
Suggestions? Anyone know what package libmmal_core.so is in?
EDIT: Fixed by running sudo apt-get upgrade
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
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 $
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: 17
- Joined: Wed Aug 01, 2012 5:23 pm
Re: Motion - MMAL camera
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 &
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: 4
- Joined: Sat Feb 18, 2012 10:26 am
Re: Motion - MMAL camera
I am now able to run Motion MMAL, but I get the following error:
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?
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
Any suggestions?
Re: Motion - MMAL camera
You should make your camera work as per instructions first, then afterwards try motionflatline403 wrote:I am now able to run Motion MMAL, but I get the following error: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>".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
Any suggestions?

- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
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.
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:
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).
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).
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
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':
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...?
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
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...?
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
A note on image resolution...
Currently, only certain resolutions work. My personal testing has shown the following work:
If you try a resolution and start getting a lot of log messages of the form:
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.
Currently, only certain resolutions work. My personal testing has shown the following work:
- 352x288
- 640x480
- 1024x576
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
I'm looking into a fix that may allow a greater range of resolutions to work.
Re: Motion - MMAL camera
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:
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:
Would it be possible to get very high resolution stills from the camera when the preview detects motion? That would be a real winner!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.
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
The source in GitHub now builds with the MySQL and PostgreSQL libraries, so database logging should be available.
https://github.com/dozencrows/motion
https://github.com/dozencrows/motion
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
You're welcome. There is a disclaimer, though: I am in no way connected with the Foundation.lowflyer wrote:Thanks for this superb work! The Foundation should be very proud of you (as well as being proud of themselves!!)
That's something I intend to try - will keep you posted. It may be a while, though.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!
Re: Motion - MMAL camera
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.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.
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.
Re: Motion - MMAL camera
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 ....
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 ....
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
@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 

Re: Motion - MMAL camera
512 x 288 also works and seems to use little CPU.dozencrows wrote:A note on image resolution...
Currently, only certain resolutions work. My personal testing has shown the following work:
- 352x288
- 640x480
- 1024x576
Re: Motion - MMAL camera
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.
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.

Re: Motion - MMAL camera
Hi,
my problem is :
The camera is enabled. Motion is version 3.2.12
Is something else? Thanks for answer & help
Rabis1848
my problem is :
- [1] Failed to open video device /dev/video0: No such file or directory
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
Rabis1848
Re: Motion - MMAL camera
Hi,
I think thats better:
Rabis1848
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
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
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!
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!
- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
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...
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...

Re: Motion - MMAL camera
Thanks for your answer ! I'll try it out and let you know. 

Re: Motion - MMAL camera
Me again
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.

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.

- dozencrows
- Posts: 172
- Joined: Sat Aug 04, 2012 6:02 pm
Re: Motion - MMAL camera
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 http://www.raspberrypi.org/phpBB3/viewt ... ew#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 http://www.raspberrypi.org/phpBB3/viewt ... 43&t=46706
I hope to find some time this weekend to look into this and other possible suggestions kindly posted to this forum.
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 http://www.raspberrypi.org/phpBB3/viewt ... 43&t=46706
I hope to find some time this weekend to look into this and other possible suggestions kindly posted to this forum.