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

Re: Motion - MMAL camera

Tue Jul 02, 2013 1:11 pm

dozencrows wrote:Time for a code update!
  • 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.
I've tested the stills mode using the following changes to the conf file. The min frame time is set to force the FPS to 0.2 as you specified

Code: Select all

mmalcam_use_still on
minimum_frame_time 5
Initiall the images were much larger FoV and filesize. However, after running for a few minutes the exposure calculations started to fail and the images went increasingly black.
copy of my conf file
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

JanBlomqvist
Posts: 12
Joined: Thu Aug 23, 2012 4:48 pm

Re: Motion - MMAL camera

Tue Jul 02, 2013 7:09 pm

I have a problem:
root@raspberrypi:/home/pi# ./motion -n -c motion-mmalcam.conf
./motion: error while loading shared libraries: : cannot open shared object file: No such file or directory
I have done everything according to this thread, but I can't get it to work.

After failing all I tried the mega version by mmiller installing the entire rasbian lib base (almost):
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

But still no luck.
Please, if someone have some ideas give them to me.

/Jan

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

Re: Motion - MMAL camera

Tue Jul 02, 2013 7:48 pm

Jan
You're post implies you've logged in as root rather than using sudo. I assume you've modifed your basic install to permit this or you're using a different OS. If its the latter then you're missing some libraries.

I suggest, a vanilla image of Raspian and retrying, the process posted previously works every time for me.

I don't know all the dependecies for motion, but you could try 'sudo apt-get -s motion' to simulate the install and find any missing packages.
Once you have the missing libs, install those manually and you should be good to go.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

JanBlomqvist
Posts: 12
Joined: Thu Aug 23, 2012 4:48 pm

Re: Motion - MMAL camera

Wed Jul 03, 2013 3:55 pm

Hi thanks for the answer, but it is a vanilla raspbian, I just used "sudo su" so I don't have to write sudo before every command, is there a catch with that?

Yours sincerely,
Jan

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

Re: Motion - MMAL camera

Wed Jul 03, 2013 9:17 pm

Hi Jan!
You shouldn't need to use root or sudo to run this version of motion - the default "pi" user should work fine. If you try that and get an error about "/dev/vchiq" and permissions, try adding the "pi" user to the "video" group like this:

Code: Select all

sudo usermod -a -G video pi
sudo shutdown -r now
The restart is to ensure the group membership takes effect.

If you still have a shared object error, try this on your Pi to see if it tells you what it can't find:

Code: Select all

ldd motion

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

Re: Motion - MMAL camera

Thu Jul 04, 2013 6:27 pm

I was able to get mine working good and it appears to be stable. Is there a way to un-mirror the image so that it looks correct?

Thanks

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

Re: Motion - MMAL camera

Thu Jul 04, 2013 6:33 pm

whowantspi wrote:I was able to get mine working good and it appears to be stable. Is there a way to un-mirror the image so that it looks correct?

Thanks
the mirror image was fixed with a firmware update. do a 'rpi-update' to get the latest firmware.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

JanBlomqvist
Posts: 12
Joined: Thu Aug 23, 2012 4:48 pm

Re: Motion - MMAL camera

Fri Jul 05, 2013 12:14 pm

When I ran added the user pi to video group and ran ./motion -h it still said:

Code: Select all

pi@raspberrypi ~ $ ./motion -h
./motion: error while loading shared libraries: : cannot open shared object fil: No such file or directory
So I tried the ldd motion option and I had the following answer in my face:

Code: Select all

pi@raspberrypi ~ $ ldd motion
./motion: /usr/lib/arm-linux-gnueabihf/libavcodec.so.53: unsupported version 48416 of Verdef record
./motion: /usr/lib/arm-linux-gnueabihf/libavcodec.so.53: unsupported version 48416 of Verdef record
./motion: error while loading shared libraries: /usr/lib/arm-linux-gnueabihf/libavcodec.so.53: unsupported version 48456 of Verneed record

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

Re: Motion - MMAL camera

Sat Jul 06, 2013 10:25 am

Thanks for trying that, Jan.

My suspicion from the ldd output is that something's got corrupted on your system - possibly motion, possibly libavcodec. That error message isn't something I've seen before. If someone else knows more, it'd be great to hear from them!

Did you use the prebuilt version from Drop Box? If so, it might be worth starting completely from scratch with a fresh install of Raspbian, and downloading the tarball from Drop Box again.

Do you have reliable power supply and SD card for your Pi that are known to be compatible? Either or both of these can cause subtle problems if they're not up to it. There are lots of posts all over this site about the need for stable power and reliable fast storage.

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

Re: Motion - MMAL camera

Sun Jul 07, 2013 5:57 am

Just in case anyone else runs into this problem- was having a tough time getting any images out of my 'motion' system that had been working before. Then I realized that my image dimensions were not an integer multiple of 16. Apparently that is needed by something in the image chain. Going back to 320 x 240 pixels worked OK.

I was trying to get closer to the 16:9 native aspect ratio of the RPi camera in video mode, to get the widest field of view available (without using stills capture instead), so I was trying 428 x 240, but it seems that doesn't work. The closest divisible-by-16 numbers would be 432 x 240.

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

Re: Motion - MMAL camera

Sun Jul 07, 2013 5:15 pm

jbeale wrote:Just in case anyone else runs into this problem- was having a tough time getting any images out of my 'motion' system that had been working before. Then I realized that my image dimensions were not an integer multiple of 16. Apparently that is needed by something in the image chain. Going back to 320 x 240 pixels worked OK.

I was trying to get closer to the 16:9 native aspect ratio of the RPi camera in video mode, to get the widest field of view available (without using stills capture instead), so I was trying 428 x 240, but it seems that doesn't work. The closest divisible-by-16 numbers would be 432 x 240.
I've had up 1920x720 running when saving to the SD card. 1280x720 should work too although I think the RPi may struggle to push these to the web port.
I've definitely had 1024x576 streaming to the web port when testing my set-up.
Image
http://wiki.raspberrytorte.com/images/6 ... mg3044.jpg

Be aware that large image formats will rapidly fill even an 8GB SD card after a few hours.
For example at 100% quality my 1920x720 images are ~1.1MB each.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

jum
Posts: 19
Joined: Wed Mar 20, 2013 12:18 pm

Re: Motion - MMAL camera

Fri Jul 19, 2013 5:20 pm

jum wrote: 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).
In case anyone else is getting the "horizontal banding" problem, I fixed it by using a powered USB hub ("Unitek") which says it can supply 2A. Note that the Pi is powered by the USB hub, and the USB Wifi module I use ("ZyXEL") is plugged into the hub (NOT the Pi). Possibly the banding could also have been caused by having the wifi module plugged into the Pi.

User avatar
SteveDee
Posts: 342
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Motion - MMAL camera

Sat Jul 20, 2013 12:26 pm

Wow! Groovy Baby!

Many thanks to Ken Lavrsen, a dozencrows and cat (just think what could be achieved with twodozencrows and an extra pussy!)

To detail my interpretation of the current method (on RPi build #506):-
- install motion via Synaptic (will include around 11 dependancies: ffmpeg, libav-tools, libavdevice53, libavfilter2, libavformat53, libdc1394-22, libopencv-core2.3, libopencv-imgproc2.3, libpostproc52, libraw1394-11 & libswscale2)
- Install libjpeg62
- Create new folders: /home/pi/Motion and /home/pi/mVideo
- Download dozencrows zip and unpack to /home/pi/Motion

- Suggested changes to motion-mmalcam.conf:-
width 640
height 480
target_dir /home/pi/mVideo
output_pictures off
text_left PiCam %t

- Navigate to /home/pi/Motion in pcManFM then select menu Tools > Open Current Folder in Terminal
- In terminal: ./motion -n -c motion-mmalcam.conf

Note: Motion cpu load = 65% approx (with conf settings as above, and ethernet network connection)

- Open Firefox on remote computer (no good using IE)
- Enter url as RPi IP address and motion server port. e.g.
192.168.0.31:8081

...you should now see jerky video!

Just for fun, pull out your Android phone:-
- Download CamBuddy
- Add IP Camera: 192.168.0.31:8081
...more jerky video!

rbn
Posts: 133
Joined: Tue Dec 27, 2011 8:32 pm
Location: Near Peterborough
Contact: Website

Re: Motion - MMAL camera

Mon Jul 22, 2013 6:40 pm

This is a great post. I have been playing with it today, downloading dozencrows replacement motion code and got it working without too much difficulty. I have a fixed wifi address on my raspberry pi, and I have connected it via this to my Synology NAS Surveillance module. I have also amended the video store directory so that it is on an nfs mounted share on the NAS. The raspberry pi is also acting as a wifi to wired ethernet router to connect my internet=ready TV to the network, so it is really earning it's keep!
I have written a couple of scripts to start and stop the camera rather than installing it instead original motion program.

I hope to write this all up on my blog http://rbnrpi.wordpress.com

rbn
Posts: 133
Joined: Tue Dec 27, 2011 8:32 pm
Location: Near Peterborough
Contact: Website

Re: Motion - MMAL camera

Wed Jul 24, 2013 12:29 pm

This is a great post. I have been playing with it today, downloading dozencrows replacement motion code and got it working without too much difficulty. I have a fixed wifi address on my raspberry pi, and I have connected it via this to my Synology NAS Surveillance module. I have also amended the video store directory so that it is on an nfs mounted share on the NAS. The raspberry pi is also acting as a wifi to wired ethernet router to connect my internet=ready TV to the network, so it is really earning it's keep!
I have written a couple of scripts to start and stop the camera rather than installing it instead original motion program.

I hope to write this all up on my blog http://rbnrpi.wordpress.com
I have now published my implementation of this project, with full instructions if you want to follow them here http://wp.me/P3KOu1-1L
Alternatively quick install details plus some useful download files are obtainable here http://r.newman.ch/mmal-bits.zip

koufs
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Re: Motion - MMAL camera

Fri Jul 26, 2013 8:28 pm

rbn wrote:I have now published my implementation of this project, with full instructions if you want to follow them here http://wp.me/P3KOu1-1L
Thanks for this; it was super helpful and got me up and running in no time. Huge thanks to dozencrows too!

However, I'm now having an issue:

Code: Select all

[1] [CRT] [STR] [Jul 26 19:54:38] http_bindsock: motion-stream bind() failed, retrying: 
[1] [ERR] [STR] [Jul 26 19:54:38] http_bindsock: motion-stream socket failed, retrying: 
[1] [CRT] [STR] [Jul 26 19:54:38] http_bindsock: motion-stream creating socket/bind ERROR: 
[1] [ERR] [ALL] [Jul 26 19:54:38] motion_init: Problem enabling motion-stream server in port 8081: 
Does anyone know why this could be?

All was going well until I installed ddclient and turned the camera LED off in /boot/config.txt; then when I tried to start motion I got the above output to the log.

I have uninstalled ddclient and reverted /boot/config.txt but the issue still remains.

:(

lancevo3
Posts: 6
Joined: Sat Jul 27, 2013 7:03 am

Re: Motion - MMAL camera

Sat Jul 27, 2013 7:07 am

My first attempt I had the following error: /dev/video0 not found. I have reformatted and will be again attempting tomorrow to make it work. Is there anything I need to double check beforehand that may prevent this issue from reoccurring? When I issue the command to take a picture it works. Thanks.

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

Re: Motion - MMAL camera

Sat Jul 27, 2013 8:46 am

@lancevo3: that sounds like you're running with an incorrect configuration file - "/dev/video0 not found" means motion is trying to use Video4Linux as its camera source, which presumably you don't have set up for use with the Pi camera (and don't need to with motion-mmal).

Double check your command line for launching motion to make sure it's launching my version of motion and not the installed one, and that the correct config file is being used. If you're still stuck, please post a copy of the command line to this thread.

@koufs: those errors suggest that something is up with networking on your Pi, probably not a camera issue in itself. Some other process may be using the port - try this command to list what ports are open on your Pi:

Code: Select all

sudo netstat -tulpn
The third column shows the addresses and port numbers - if 8081 appears as the end of one of these, then something else has that port - you can see the program details in the last column.

koufs
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Re: Motion - MMAL camera

Sat Jul 27, 2013 4:51 pm

@dozencrows: Thanks for the help. In the end I had to restore the Pi to an earlier image due to some other issues. I'm now back up and running with motion and the mmal camera.

Today I've been experimenting with the saving of movies when motion is detected. I'm having an issue where the movie is played back way too fast. This was once addressed in the FAQ on the Motion site:
When an mpeg is created Motion must tell ffmpeg what framerate to use. If Motion then sends much less frames than required the mpegs runs too fast. So we need to help ffmpeg get it right.
If you set 'low_cpu = on' in motion.conf Motion will use the 'framerate' value for the mpeg. So it is important that you set framerate equal to the possible framerate of your camera.
If you set 'low_cpu = off' Motion uses the ACTUAL framerate from the previous finished second. The actual framerate is the lowest number of 'framerate' and the rate the camera can actually deliver.
However, low_cpu has been deprecated according to http://www.lavrsen.dk/foswiki/bin/view/ ... ileOptions

Is there another way to fix this?

lancevo3
Posts: 6
Joined: Sat Jul 27, 2013 7:03 am

Re: Motion - MMAL camera

Sat Jul 27, 2013 4:57 pm

@dozencrows Started with a fresh OS and it seemed to work fine now. Just need to read up on motion, thrilled to have this working. So everytime I want to start motion, I do it with your config file?

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

Re: Motion - MMAL camera

Sat Jul 27, 2013 5:24 pm

@koufs: I don't think there is a fix currently - see this post and the one following for my earlier thoughts on it - http://www.raspberrypi.org/phpBB3/viewt ... 87#p377587. As I get time, I'm trying out some ideas to make it faster however these involve significant changes to the code, so I'm not rushing them! On the CPU side the Pi isn't enormously powerful, and some of motion's image processing steps are quite demanding. When you also factor in movie encoding, writing to SD card and streaming over a network connection, there's a lot for that little ARM box to do!

@lancevo3: Yes, you have to supply the config file each time you launch motion. If you read through earlier posts on this thread, you'll see what others have done to make it easier to start & stop - a good one is http://rbnrpi.wordpress.com/project-lis ... etect-cam/.

koufs
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Re: Motion - MMAL camera

Sat Jul 27, 2013 6:12 pm

I understand it's asking a lot of the little fella :)

FYI, I'm currently using around 85-95% CPU when motion is running with the following options:

* Width: 640
* Height: 400
* Framerate: 25fps
* Bitrate: 400000
* No video or image creation
* Streaming: Yes:
* Streaming quality 50%
* Streaming framerate: 10fps

Dropping it down to 15fps reduces CPU usage to between 75-90%.

Is there any way I can further reduce CPU usage with the options that are currently available?

I'd be happy to half the width and height but I don't think it likes that.

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

Re: Motion - MMAL camera

Sun Jul 28, 2013 11:08 am

Interesting stuff... I think tuning frame rates, image size and quality settings are all you can do right now. Possibly overclocking if you want to get more done? Though that is risky.

My testing with your settings suggests that the actual streaming side causes the biggest CPU hit - when motion starts with no browser connecting to the stream, my CPU is around 25% to 30%. As soon as I point a browser at the stream URL, it jumps up to over 80%. Image capture is definitely active before the stream output (I display the captured image on HDMI for testing).

And you're right - 320 x 200 is a resolution that doesn't work. 352 x 288 and 512 x 288 are known to work.

koufs
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Re: Motion - MMAL camera

Sun Jul 28, 2013 12:59 pm

Thanks, 352 x 288 is much nicer on the CPU; between 30-60% depending on movie output and devices connected to the stream. I can live with that size for now (though it would be nice to use a larger field of view).

Thanks again for all the awesome work on motion-mmal, dozencrows. It's hugely appreciated.

lancevo3
Posts: 6
Joined: Sat Jul 27, 2013 7:03 am

Re: Motion - MMAL camera

Mon Jul 29, 2013 3:30 pm

I am looking to have this record a 15 second video after motion is detected and snap a picture. What are the main config options I should be concerned with modifying to achieve this? Thanks

Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 6 guests