commander_data
Posts: 6
Joined: Sat Jun 16, 2012 8:32 am

Re: Motion - MMAL camera

Sat Jun 15, 2013 9:06 am

Hi, just wanted to echo the other posters and say thanks to dozencrows for this! It's awesome and works great, I had no problems setting it up. The quality is great from the pi cam, so much better than usb webcams. Motion works great with it and for my purposes the motion detection is spot on, with no modifications it doesn't get activated by trees swaying etc, but people are captured straight away.

Cheers!

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

Re: Motion - MMAL camera

Sat Jun 15, 2013 11:52 am

FYI I've moved the temporary binary build to Dropbox from Google Drive. This should hopefully be even easier for everyone!

It is now at this location: https://www.dropbox.com/s/xdfcxm5hu71s9 ... mal.tar.gz
You shouldn't need to sign up for or install Dropbox to access it - use the link in a browser, or use wget on a Pi command line to load it directly onto a Pi.

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

Re: Motion - MMAL camera

Sun Jun 16, 2013 6:48 pm

dozencrows wrote:FYI I've moved the temporary binary build to Dropbox from Google Drive. This should hopefully be even easier for everyone!

It is now at this location: https://www.dropbox.com/s/xdfcxm5hu71s9 ... mal.tar.gz
You shouldn't need to sign up for or install Dropbox to access it - use the link in a browser, or use wget on a Pi command line to load it directly onto a Pi.
Thanks! :)

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

Re: Motion - MMAL camera

Sun Jun 16, 2013 7:13 pm

Tentative promising news on the performance front...

I've been able to double the speed of the basic image differencing algorithm using some hand-coded ARM assembly. This is good evidence that progress can be made! Because of all the other processing going on, this translates to only about a 10% to 12% speedup - but it's encouraging that I can make a difference, and am keen to try more over the coming weeks.

I can't make this public quite yet, as it needs more testing and I haven't got time left this weekend to tidy up enough loose ends to push the source to GitHub.

whowantspi
Posts: 32
Joined: Mon Feb 11, 2013 12:00 am
Location: USA Alabama

Re: Motion - MMAL camera

Tue Jun 18, 2013 1:50 am

So what is the trick to viewing the video stream? My laptop is running Windows 7 with IE 9. When I browse to the Raspberry PI address and port 8081, Internet Explorer wants to know if I want to open or save the output. Neither choice will show me the video. Is it my browser or do I not have something configured correctly?

craigc
Posts: 8
Joined: Mon Jan 23, 2012 12:17 pm
Location: Berkshire, UK

Re: Motion - MMAL camera

Tue Jun 18, 2013 11:51 am

whowantspi wrote:So what is the trick to viewing the video stream? My laptop is running Windows 7 with IE 9. When I browse to the Raspberry PI address and port 8081, Internet Explorer wants to know if I want to open or save the output. Neither choice will show me the video. Is it my browser or do I not have something configured correctly?
Just tried with IE 10 on 7 and it does the same for me. I've always used VLC to open a network stream or Firefox/Chrome and they both just display the feed. I believes it a motion-jpg.

Craig.

User avatar
leol
Posts: 145
Joined: Fri Jan 13, 2012 4:27 pm
Location: Reading, England

Re: Motion - MMAL camera

Tue Jun 18, 2013 1:19 pm

Internet Explorer does not support motion jpeg.

Leo

whowantspi
Posts: 32
Joined: Mon Feb 11, 2013 12:00 am
Location: USA Alabama

Re: Motion - MMAL camera

Tue Jun 18, 2013 7:12 pm

So what are my choices for viewing the video on a Windows 7 machine?

bjornatic
Posts: 20
Joined: Wed May 15, 2013 4:44 pm

Re: Motion - MMAL camera

Wed Jun 19, 2013 10:49 am

Alternatives to IE ?

Firefox, or Chrome.

But the smoothest way in my opinion is to use VLC

Rob_Quads
Posts: 9
Joined: Sat Jul 07, 2012 10:57 pm

Re: Motion - MMAL camera

Wed Jun 19, 2013 12:41 pm

This looks to work quite well. It worked quite well while testing it with the RPi in a room but then I moved it so it was showing an outside picture. After this due to the high brightness the picture seems to cycle in brightness i.e. start at black, brigher..brighter, very bright and then back to black.

Any ideas how to solve this?

I've tried turning on autobrightness but this made no difference.

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

Re: Motion - MMAL camera

Fri Jun 21, 2013 12:12 pm

Please try using the raspivid program to capture video in the same environment (with the same mmalcam parameters) and see if that is stable or not - this will help determine if it is a camera-side issue or an issue with motion.

It might also be worth trying out the different metering and exposure settings detailed in the Pi camera documentation.

Some have also experienced exposure stability problems with the timelapse mode of raspistill - if you haven't read it, there might be some useful info in this thread: http://www.raspberrypi.org/phpBB3/viewt ... 18#p361518

Globalidentity
Posts: 2
Joined: Wed Jun 05, 2013 2:31 pm

Re: Motion - MMAL camera

Sat Jun 22, 2013 7:50 pm

Hi dozencows.

I haven't really got a question - I probably will have in the future.. I just wanted to say how amazed I am by this forum and this post. I intend to use my pi and camera and motion to catch fly-tippers in a local lane. I don't get much time to play so it might take some time. Next big step is getting motion to work - and to understand how to use it, then I will to work out how to run the pi on batteries or solar.... Good job everyone posting here though - not like other forums where novices like me get totally torched.

User avatar
mmiller
Posts: 22
Joined: Wed Nov 16, 2011 8:38 pm
Contact: Website

Re: Motion - MMAL camera

Sun Jun 23, 2013 12:44 am

Globalidentity wrote:Hi dozencows.

Next big step is getting motion to work
The following 4 steps are collated from the excellent posts so far. They cover installing the depedencies (some my be overkill but it worked for me), downloading the prebuilt binary, unziping the archive and running with the MMAL config provided.

Code: Select all

$ sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev

$ wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz

$ tar -zxvf motion-mmal.tar.gz

$ ./motion -n -c motion-mmalcam.conf
this should 'just work' leaving understanding and modification of the config file.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

User avatar
jbeale
Posts: 3302
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Motion - MMAL camera

Mon Jun 24, 2013 6:20 am

great work, without knowing anything about 'motion' I followed the above instructions and it worked the first time. Great!

WIth one exception, this command fails on my install

Code: Select all

tar -zxvf motion-mmal.tar.gz
I had to remove the dash, like so:

Code: Select all

tar zxvf motion-mmal.tar.gz
and I made a small change to the .conf file like so:

Code: Select all

############################################################
# OpenMax/MMAL camera support for Raspberry Pi
############################################################
mmalcam_name vc.ril.camera
mmalcam_control_params -mm matrix -rot 180

User avatar
jbeale
Posts: 3302
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Motion - MMAL camera

Wed Jun 26, 2013 5:59 am

Ok, I have to correct my glowing review above. What I see in my home directory, after running './motion -n -c motion-mmalcam.conf' are a set of .jpg files, with long number-names that indicate year-month-day-hour-minute-second-frame, and also a set of .avi files. The JPEG files are exactly as I expect, I see about one frame per second (sometimes 2 in the same second) where something new appeared in the frame. Now I assume the avi files are supposed to be a combined set of the stills, grouped together by when a continuous motion was detected, but when I try to play them, they are all frozen at the first frame. However they are of various, fairly large sizes and they do last a variable number of seconds, proportional to how long the motion event was, so I think they are not simply 1-frame videos.

I wonder if there is some problem with ffmpeg, I presume that is what motion is calling to generate the avi.

craigc
Posts: 8
Joined: Mon Jan 23, 2012 12:17 pm
Location: Berkshire, UK

Re: Motion - MMAL camera

Wed Jun 26, 2013 12:36 pm

jbeale wrote:Ok, I have to correct my glowing review above. What I see in my home directory, after running './motion -n -c motion-mmalcam.conf' are a set of .jpg files, with long number-names that indicate year-month-day-hour-minute-second-frame, and also a set of .avi files. The JPEG files are exactly as I expect, I see about one frame per second (sometimes 2 in the same second) where something new appeared in the frame. Now I assume the avi files are supposed to be a combined set of the stills, grouped together by when a continuous motion was detected, but when I try to play them, they are all frozen at the first frame. However they are of various, fairly large sizes and they do last a variable number of seconds, proportional to how long the motion event was, so I think they are not simply 1-frame videos.

I wonder if there is some problem with ffmpeg, I presume that is what motion is calling to generate the avi.
Hi, I had something similar when I try and play the videos via VLC, first frame and no more, playing them via windows media player showed the full video. I didn't dig much further as I just blamed by setup, if I get a chance tonight I'll try and dig deeper unless someone else knows sooner.

Craig.

zoukimando
Posts: 17
Joined: Mon Jan 07, 2013 5:45 pm

Re: Motion - MMAL camera

Wed Jun 26, 2013 12:38 pm

I'm seeing the same frozen avi's in VLC but not if I open them in Winamp or Irfanview. Not sure why VLC has a problem but I've also seeing the same problem with vanilla Motion avi's

User avatar
jbeale
Posts: 3302
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Motion - MMAL camera

Wed Jun 26, 2013 2:38 pm

Same as the others have reported, VLC locks up on the first frame (and runs 100% CPU) but Windows Media Player, and also Nero ShowTime can play it. The metadata reported by "codec information appliance" GSpot v2.70a says the frame rate is 5 fps. But the actual playback is more like 1 fps, but jerky and inconsistent; sometimes faster. I wonder if that is problem- maybe VLC is expecting to find five frames per second, but the 'motion' process wasn't fast enough to actually record all the frames for the requested rate.

User avatar
mmiller
Posts: 22
Joined: Wed Nov 16, 2011 8:38 pm
Contact: Website

Re: Motion - MMAL camera

Wed Jun 26, 2013 5:26 pm

generation of avi's is part of the motion config.

admittedly I switched this off in the default file before I started

poor quality video will probably be because you're overtaxing the RPI asking for both.
disable in the conf and retest.

I recommend running 'top' in another terminal to monitor performance.

also enable by default (I think) is the web stream. watch this at <your.RPI.IP>:8081 in a webbrower.. on another machine of course.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

User avatar
jbeale
Posts: 3302
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Motion - MMAL camera

Wed Jun 26, 2013 7:17 pm

I expected the movie to be jerky due to the slow, and inconsistent frame rate. I did not expect VLC (running on a Debian install on Dell laptop, not R-Pi) to freeze on the first frame and actually lock up, and require a kill -9 to stop. Maybe there's a problem with the .avi but it also seems to trigger a bug in VLC.

Yes, the live view in the web browser at port 8081 is a nice feature, I can even see it on my Android phone.

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

Re: Motion - MMAL camera

Thu Jun 27, 2013 12:16 pm

The frame rate specified in the "mmal" configuration file is 5 fps at 1024 x 576, which is optimistic...
It might be worth dialling this down to a realistic figure and see if that makes for more stable AVI generation.

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

Re: Motion - MMAL camera

Sat Jun 29, 2013 3:59 pm

Having looked further into the motion code, my suggestion above probably won't make a difference - the actual frame rate used for ffmpeg is calculated based on the real capture frame rate just prior to generating a new AVI file. So there will be differences in frame rate between video files, but the base frame rate for a file should be constant.

I've noticed variability in frame timing not just in the ffmpeg movie generation - the image shown for a given timestamp is often actually a few seconds behind real time, and sometimes there can appear to be big visual jumps that don't tie up with the timestamps. I suspect that much better performance needs to be achieved in order to tackle these by improving the capture frame rate.

The image subjects also play a part here - with the relatively narrow FOV of the video, only relatively low speed objects are going to get captured. My test environment (front bedroom window) means that any vehicle going over about 15mph would at best appear in one frame. And with a rate of 1 fps, it's very easy for a subject to accelerate or decelerate significantly between frames.

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

Re: Motion - MMAL camera

Sat Jun 29, 2013 4:28 pm

Time for a code update!

I've pushed some changes to GitHub and updated the binary build in Dropbox (https://www.dropbox.com/s/xdfcxm5hu71s9 ... mal.tar.gz).

What's changed?
  • First pass assembler optimisations to the image processing "hotspots". Currently only a very small gain in speed, and only if you're not using a mask image or the smart mask option.
  • Option to use the Pi camera's stills mode rather than video. This can give you a wider field of view, but currently exposure control can go a bit wild if you have a frame rate faster than around 0.2 fps. So right now it's not very useful, but I'd be interested to hear others' experiences with it. See the example config file for more info.
  • Some internal changes to make it easier to test changes for correctness and measure performance.

dktak
Posts: 3
Joined: Thu Jun 13, 2013 6:04 pm

Re: Motion - MMAL camera

Sat Jun 29, 2013 8:18 pm

Hi all,
Running as a normal user this solution works perfect.
But if I want to run it as a service (so it will lauch automatically when rebooted), I cannot make it work.
The issue seem, that the service do not start the application with "./motion" in the home-folder, but as "motion" which gives the errors "/dev/video0".
Anybody who have had success turning this application into a service ??
Best regards,
dktak

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

Re: Motion - MMAL camera

Sun Jun 30, 2013 9:32 pm

copy the motion-mmalcam.conf file to /etc/motion.conf,
copy the motion file to /usr/bin

and then you can start motion from /etc/rc.local

Pete

Return to “Camera board”

Who is online

Users browsing this forum: HermannSW and 17 guests