Motion MMAL

From SingletonMillerWiki
Jump to: navigation, search


Collated from the Raspberry Pi forum for using Motion with a Raspberry Pi Camera Module


Introduction

The objective of this How To is install a special binary of Motion compiled with support for the Raspberry Pi Camera Module.

A special binary for motion has been compiled by the RPi community. Specifically dozencrows [1]

Before you start these instructions you are assumed to have a configured RPi running an up to date version of Raspian, a RPi Camera module plugged in and working with stock tools such as the raspistill.

Installation (Wheezy)

Install dependencies for Motion

Here we simulate the installation of the standard version of motion which works with USB webcams but not the RPi Camera. The purpose is to determine what packages and dependencies are needed.

 $ sudo apt-get -s install motion

Should return something like

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  ffmpeg libav-tools libavcodec53 libavdevice53 libavfilter2 libavformat53
  libavutil51 libdc1394-22 libdirac-encoder0 libgsm1 libjack-jackd2-0
  libmp3lame0 libmysqlclient18 libopencv-core2.3 libopencv-imgproc2.3
  libpostproc52 libpq5 libraw1394-11 libschroedinger-1.0-0 libspeex1
  libswscale2 libtheora0 libva1 libvpx1 libx264-123 libxvidcore4 mysql-common
Suggested packages:
  jackd2 libraw1394-doc speex mysql-client postgresql-client
The following NEW packages will be installed:
  ffmpeg libav-tools libavcodec53 libavdevice53 libavfilter2 libavformat53
  libavutil51 libdc1394-22 libdirac-encoder0 libgsm1 libjack-jackd2-0
  libmp3lame0 libmysqlclient18 libopencv-core2.3 libopencv-imgproc2.3
  libpostproc52 libpq5 libraw1394-11 libschroedinger-1.0-0 libspeex1
  libswscale2 libtheora0 libva1 libvpx1 libx264-123 libxvidcore4 motion
  mysql-common
0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.

Install the dependcies using

 $ sudo apt-get install -y <list from the above step here> 

on my system this is

 $ sudo apt-get install -y ffmpeg libav-tools libavcodec53 libavdevice53 libavfilter2 libavformat53 libavutil51 libdc1394-22 libdirac-encoder0 libgsm1 libjack-jackd2-0 libmp3lame0 libmysqlclient18 libopencv-core2.3 libopencv-imgproc2.3 libpostproc52 libpq5 libraw1394-11 libschroedinger-1.0-0 libspeex1 libswscale2 libtheora0 libva1 libvpx1 libx264-123 libxvidcore4 motion mysql-common

Wait patiently for the installation to complete.

Download the pre-compiled binary

Download and unzip the binary provided by Dozencrows.

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

Test Run

Run motion with the default configuration file and monitor the output.

$ ./motion -n -c motion-mmalcam.conf

Naviate to <your.RPI.IP>:8081 from anther computer to see the video. Some users have reported issues with this when using InternetExplorer on windows. An alternative browser such as FireFox or Chrome should work.

Adapting the Config File

My test download file can be downloaded and tried using the following

$ wget --output-document=motion.conf_for_motionstills_debug.conf "http://pastebin.com/raw.php?i=tSjgys2q"
$ ./motion -n -c motion.conf_for_motionstills_debug.conf
Example Output running at 1920x720








Installation (Jessie)

Install dependencies for Motion

$ sudo apt-get install -y libjpeg-dev libavformat56 libavformat-dev libavcodec56 libavcodec-dev libavutil54 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev 

Download the pre-compiled binary

Download and unzip the binary provided by lowflyer on the Raspberry Pi Forums (see https://www.raspberrypi.org/forums/viewtopic.php?p=843625#p843625)

$ wget https://www.dropbox.com/s/6ruqgv1h65zufr6/motion-mmal-lowflyerUK-20151114.tar.gz
$ tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz

Test using

$ ./motion -c motion-mmalcam-both.conf

Auto Running at Boot

There are several methods to do this.

cron

TODO

rc.local

edit the rc.local file as superuser and add the command to the end of the file. see http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs

init.d

create a runtime script for motion in the init.d folder

$ sudo nano /etc/init.d/run_motion.sh

add the following lines

#!/bin/sh
/home/pi/motion/./motion

Save the script and exit using Ctrl-X

Initialise the runtime using

$  sudo update-rc.d run_motion.sh defaults

disable init.d

sudo update-rc.d run_motion.sh stop levels .

or

sudo  update-rc.d -f run_motion.sh remove

For temporary disable add a '#' to the call to the motion program, re-save the script and reboot the Pi.

#!/bin/sh
# /home/pi/motion/./motion

TO DO LIST

  1. Add scripts for starting and stopping motion with Cron.
  2. Set up Motion to work with a NAS to record data [2]
  3. Offload Motion to another Pi or Linux PC using streaming (should improve frame rates).

References

  1. Raspberry Pi forum for using Motion with a Raspberry Pi Camera Module
  2. http://rbnrpi.wordpress.com/project-list/setting-up-wireless-motion-detect-cam/