jayslovak
Posts: 3
Joined: Mon Feb 15, 2016 11:32 am

Re: Motion - MMAL camera

Mon Feb 15, 2016 11:43 am

Thank you @lowflyer for making the necessary changes to make the mmal version of motion compatible with Jessie. I have been using your motion version with my own, debootstrap generated images for the past few months without issues.

But yesterday, as I have built a new OS image with debootstrap, I am unable to start motion anymore:

Code: Select all

./motion -h
Illegal instruction

uname -a
Linux 000000007afd24fc 4.1.17+ #841 Sun Feb 14 16:27:21 GMT 2016 armv6l GNU/Linux
I have compiled motion myself, and also tried your pre-built binary with the same result.
The previous OS image was built 2 weeks ago, and it doesn't look like there were any major changes since (kernel or libraries...).

I am using the ARMv6 Raspberries (Models A+ and B+).

Has anyone encountered this issue as well?

Edit: Stock Motion binary (from Raspbian repositories), works ok on the same system...

Thanks!

jayslovak
Posts: 3
Joined: Mon Feb 15, 2016 11:32 am

Re: Motion - MMAL camera

Mon Feb 15, 2016 8:55 pm

Please disregard my previous post. I have re-built the OS image and now everything works as before. I am not sure if there was a bug/issue in one of the packages, or some other fault (assembling the image?).

All is good now :)

AndyDoania
Posts: 1
Joined: Tue Feb 23, 2016 1:49 am

Re: Motion - MMAL camera

Tue Feb 23, 2016 1:55 am

@lowflyer

Thank-you!

It's been a 5 day learning odyssey. Finally success. Thank-you for you patience and your intelligence. True class! Cheers!

boyfleming
Posts: 1
Joined: Sat Jan 02, 2016 5:23 pm

Re: Motion - MMAL camera

Sun Feb 28, 2016 7:53 pm

lowflyer wrote:@maya I have put a copy of my version of motion here
https://www.dropbox.com/s/6ruqgv1h65zuf ... 114.tar.gz

It should work if you do this:

Code: Select all

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

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

tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz

./motion -c motion-mmalcam-both.conf
Hope it works also for you. I just tested it using a fresh SDcard with jessie lite on an old Pi - and it is the same binary that I tested a few weeks ago on a Pi 2 with the full version of jessie.

I look forward to hearing how you get on with it.

If you can you should learn about how to download and compile code from github. This works for me:

Code: Select all

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

sudo apt-get install git
sudo apt-get install cmake
git clone https://github.com/raspberrypi/userland
git clone https://github.com/lowflyerUK/motion.git
cd motion/
git checkout mmal-test
USERLANDPATH=/home/pi/userland cmake .
make
After a while you should have a newly created binary "motion" in the directory also called "motion". You can run it with:

Code: Select all

/home/pi/motion/motion -c /home/pi/motion/configs/motion-mmalcam-both.conf
You may well have to adjust the config file for your needs.

Good luck!

*******Edited on 23 December 2015 to correct the compilation instructions. Thanks to Kreachers for noticing that it didn't work*******
Hello. When I tried to run this, I received confirmation that the packages would be loaded but the an error message for (I think) every component like this ones, which was the last in the list:
E: Failed to fetch http://mirrordirector.raspbian.org/rasp ... u2_all.deb Could not resolve 'mirrordirector.raspbian.org'

Plus this suggestion afterwards:

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Any idea what is wrong please? I ran it as sudo to avoid access permissions to the file problems.

Thanks, Andrew.

lowflyer
Posts: 75
Joined: Sat Jun 01, 2013 2:27 pm

Re: Motion - MMAL camera

Mon Feb 29, 2016 1:04 pm

@boyfleming

Hi! I think those errors mean that your Raspberry Pi isn't connected to the internet (or if it is, it can't reach a nameserver). You could try searching on the internet for those errors - for example:

Code: Select all

Could not resolve 'mirrordirector.raspbian.org'
Hope this helps.

Iman_Hindi
Posts: 1
Joined: Thu Mar 10, 2016 6:49 am

Re: Motion - MMAL camera

Thu Mar 10, 2016 7:18 am

@lowflyer thanks alot ... i flow ur instruction but when i run motion.. give me this error:

Code: Select all

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

[0] [NTC] [ALL] conf_load: Processing thread 0 - config file motion-mmalcam-both.conf

[0] [NTC] [ALL] motion_startup: Motion mmaltest Started

[0] [NTC] [ALL] motion_startup: Logging to syslog

[0] [NTC] [ALL] motion_startup: Using log type (ALL) log level (INF)

[0] [NTC] [ALL] become_daemon: Motion going to daemon mode

[0] [ERR] [ALL] myfopen: Error opening file /var/run/motion/motion.pid with mode w+:
 
[0] [EMG] [ALL] become_daemon: Exit motion, cannot create process id file (pid file) /var/run/motion/motion.pid: 
any solution for that plz :)

lowflyer
Posts: 75
Joined: Sat Jun 01, 2013 2:27 pm

Re: Motion - MMAL camera

Thu Mar 10, 2016 9:46 am

@Iman_Hindi

Did you change the config file? I always have:

Code: Select all

daemon off
and have never seen that error.

If you want to use daemon mode, you have to change the location of the pid file (or in theory you could fiddle with permissions or run as root, but I think that isn't recommended). You could try this:

Code: Select all

daemon on
process_id_file /run/shm/motion.pid
Hope this helps, good luck!

nichis
Posts: 5
Joined: Sat Mar 19, 2016 9:39 pm

Re: Motion - MMAL camera

Sat Mar 19, 2016 9:43 pm

Hi, is it possible to set motion to do a timelapse saving frame every Nth second EXCEPT in the night? if yes, what have to be modified in .conf file?

andies
Posts: 138
Joined: Mon Nov 11, 2013 8:12 pm
Location: Berlin

Re: Motion - MMAL camera

Sun Mar 20, 2016 7:07 am

The easiest way is probably to run a cronjob and use simple wget-commands to stop and start motion using localhost-web-access like

Code: Select all

http://localhost:8086/0/detection/pause
or

Code: Select all

http://localhost:8086/0/detection/start
.

I am using precisely

Code: Select all

 wget -O - http://localhost:8086/0/detection/pause > /dev/null 2>&1
in order to avoid error messages.
raspberry B, Noir camera, Mac Book Air, iPhone, Bezzera

nichis
Posts: 5
Joined: Sat Mar 19, 2016 9:39 pm

Re: Motion - MMAL camera

Sun Mar 20, 2016 10:07 am

ok, I was hoping to use the "threshold" parameter, but it affects only motion, not timelapse

lowflyer
Posts: 75
Joined: Sat Jun 01, 2013 2:27 pm

Re: Motion - MMAL camera

Thu Mar 24, 2016 5:09 pm

@dozencrows

Good idea of yours to merge motion-mmal. I am honoured! For some reason I can't PM you on this forum, but I have issued a github pull request. Please let me know if there is anything else I should do.

Best regards and thanks for your super work!!

nichis
Posts: 5
Joined: Sat Mar 19, 2016 9:39 pm

Re: Motion - MMAL camera

Mon Mar 28, 2016 6:07 pm

Is it possible to set a dynamic target_dir? I mean something like this:

Code: Select all

target_dir /home/pi/%d-%m-%Y
so that the output of the "ffmpeg_output_movies" changes target_dir every day.

Johnny_quattro
Posts: 5
Joined: Sat Apr 09, 2016 5:39 pm

Re: Motion - MMAL camera

Sat Apr 09, 2016 5:49 pm

You need to do the following in order to achieve your goal. Note use of the so-called back ticks.

/home/pi/`date +%d%m%Y`

Back tick is located in top left hand side of keyboard and is NOT a single quote mark.

nichis
Posts: 5
Joined: Sat Mar 19, 2016 9:39 pm

Re: Motion - MMAL camera

Tue Apr 12, 2016 8:14 pm

Johnny_quattro wrote:You need to do the following in order to achieve your goal. Note use of the so-called back ticks.

/home/pi/`date +%d%m%Y`

Back tick is located in top left hand side of keyboard and is NOT a single quote mark.
I'm sorry but the result is a folder with the name: `date +%d%m%Y`

Johnny_quattro
Posts: 5
Joined: Sat Apr 09, 2016 5:39 pm

Re: Motion - MMAL camera

Tue Apr 12, 2016 9:13 pm

My error, apologies. It's a generic Linux/Unix command.
Perhaps that is something that the config file won't recognise.
I use that command regularly from the shell and also in scripts that I use when managing/sorting out photos produced by the Pi.

Johnny_quattro
Posts: 5
Joined: Sat Apr 09, 2016 5:39 pm

Re: Motion - MMAL camera

Tue Apr 12, 2016 9:20 pm

You can work around your current issue with the judicious use of crontab, if the config file doesn't understand that command.
I tend to grab all the output from the camera shortly after midnight each day when the camera is not active, and dump the contents into a date/time-stamped folder. I remove the files afterwards so that the Pi doesn't fill up. This enables me to have the last 31 days of JPGs/AVIs and timelapse MPGs. These files also get pruned with another cron job that performs a find on files that were last modified one month ago.

I have 4 Pi units, and the above solution (for me) works like a dream. The author of the config file may choose to add such functionality at some point, but my workaround bypasses this issue.

jayslovak
Posts: 3
Joined: Mon Feb 15, 2016 11:32 am

Re: Motion - MMAL camera

Wed Apr 13, 2016 2:26 pm

Try the following. The key is to encode the needed date/time in the file names themselves. Motion will create the needed directory structure automatically :D

Code: Select all

target_dir /mnt/somepath
~~~
snapshot_filename %Y/%m/%d/%H%M%S-%q_snap
This will work for all related directives, such as movie_filename...

nichis
Posts: 5
Joined: Sat Mar 19, 2016 9:39 pm

Re: Motion - MMAL camera

Fri Apr 15, 2016 6:52 pm

jayslovak wrote:Try the following. The key is to encode the needed date/time in the file names themselves. Motion will create the needed directory structure automatically :D

Code: Select all

target_dir /mnt/somepath
~~~
snapshot_filename %Y/%m/%d/%H%M%S-%q_snap
This will work for all related directives, such as movie_filename...
Fantastic jayslovak!! It works perfectly!! :D Thanks!!

paulpoco
Posts: 14
Joined: Sat Apr 16, 2016 11:58 pm

Re: Motion - MMAL camera

Sun Apr 17, 2016 1:49 am

lowflyer wrote:@maya I have put a copy of my version of motion here
https://www.dropbox.com/s/6ruqgv1h65zuf ... 114.tar.gz

It should work if you do this:

Code: Select all

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

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

tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz

./motion -c motion-mmalcam-both.conf
Hope it works also for you. I just tested it using a fresh SDcard with jessie lite on an old Pi - and it is the same binary that I tested a few weeks ago on a Pi 2 with the full version of jessie.

I look forward to hearing how you get on with it.

If you can you should learn about how to download and compile code from github. This works for me:

Code: Select all

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

sudo apt-get install git
sudo apt-get install cmake
git clone https://github.com/raspberrypi/userland
git clone https://github.com/lowflyerUK/motion.git
cd motion/
git checkout mmal-test
USERLANDPATH=/home/pi/userland cmake .
make
After a while you should have a newly created binary "motion" in the directory also called "motion". You can run it with:

Code: Select all

/home/pi/motion/motion -c /home/pi/motion/configs/motion-mmalcam-both.conf
You may well have to adjust the config file for your needs.

Good luck!

*******Edited on 23 December 2015 to correct the compilation instructions. Thanks to Kreachers for noticing that it didn't work*******

Thanks for figuring this out for Rasbian Jessie. My SD card packed it in on Friday and I had to start over again on my Garage Door Video Opener. http://www.instructables.com/id/Raspber ... aming-vid/

Working on updating my Instructable.

User avatar
pi-anazazi
Posts: 497
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: Motion - MMAL camera

Sun May 15, 2016 5:39 pm

Hi!

I installed motion successfully according to this guide on new raspi 2 with jessie light , many thanks!

I can start it manually in /home/pi with

./motion -c motion.conf

(as I have my estabilshed motion in "motion.conf" configuration file), I'm using older versions of motion on older raspian for years now, made it work to start on boot on these, but I can't get it up and running on boot with jessie/systemd.

I tried the initd file for motion provided here:

http://www.instructables.com/id/Raspber ... /?ALLSTEPS

which provides this initd file

Code: Select all

#!/bin/sh -e
#
# /etc/init.d/motion: Start the motion detection
#
### BEGIN INIT INFO
# Provides:	  motion
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Motion detection
# Description: loads motion and assigns privileges
### END INIT INFO

# Ported to new debian way using sh and /lib/lsb/init-functions
# by Angel Carpintero <[email protected]>
# Modified by : Juan Angulo Moreno <[email protected]>
#               Eddy Petrisor <[email protected]>
#               ArAge <[email protected]>

NAME=motion
PATH_BIN=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/motion
PIDFILE=/var/run/$NAME.pid
DEFAULTS=/etc/default/$NAME
DESC="motion detection daemon"

ENV="env -i LANG=C PATH=$PATH_BIN"

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

RET=0

[ -r "$DEFAULTS" ] && . "$DEFAULTS" || start_motion_daemon=yes


check_daemon_enabled () {
    if [ "$start_motion_daemon" = "yes" ] ; then
        return 0
    else
        log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
        return 1
    fi

}


case "$1" in
  start)
    if check_daemon_enabled ; then
        if ! [ -d /var/run/motion ]; then
                mkdir /var/run/motion
        fi
        chown motion:motion /var/run/motion
        chmod 775 /var/run/motion
    # this is the fix we've added to allow the network share to be connected first before we try to start motion:
	sleep 30
	log_daemon_msg "Starting $DESC" "$NAME" 
if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; then
            log_end_msg 0
        else
            log_end_msg 1
            RET=1
        fi
    fi
    ;;

  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30 ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  reload|force-reload)
    log_daemon_msg "Reloading $NAME configuration"
    if start-stop-daemon --stop --signal HUP --exec $DAEMON ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  restart-motion)
    if check_daemon_enabled ; then
        log_action_begin_msg "Restarting $NAME"
        if $0 stop && $0 start ; then
            log_action_end_msg 0
        else
            log_action_cont_msg "(failed)"
            RET=1
        fi
    fi
    ;;

  restart)
    $0 restart-motion
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
    RET=1
    ;;
esac


exit $RET
...but it always ends in errors (after adapting to my directories/ file names), as apparently the initd file is not written for systemd/jessie, or?

I tried to modify the file, but with this version

Code: Select all

#!/bin/sh
#
# /etc/init.d/motion: Start the motion detection


### BEGIN INIT INFO
# Provides:	  motion
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Motion detection
# Description: loads motion and assigns privileges
### END INIT INFO

# Ported to new debian way using sh and /lib/lsb/init-functions
# by Angel Carpintero <[email protected]>
# Modified by : Juan Angulo Moreno <[email protected]>
#               Eddy Petrisor <[email protected]>
#               ArAge <[email protected]>
# SD: Angepasst auf jessie 15.05.2016 motion .exe + config in /home/pi!!!elf! 


NAME=motion
PATH_BIN=/home/pi
DAEMON=/home/pi/$NAME
PIDFILE=/var/run/$NAME.pid
DEFAULTS=/etc/default/$NAME
PIDFILE=/var/run/motion/motion.pid
DESC="motion detection daemon"

ENV="env -i LANG=C PATH=$PATH_BIN"

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

RET=0

[ -r "$DEFAULTS" ] && . "$DEFAULTS" || start_motion_daemon=yes


check_daemon_enabled () {
    if [ "$start_motion_daemon" = "yes" ] ; then
        return 0
    else
        log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
        return 1
    fi

}


case "$1" in
  start
    if check_daemon_enabled ; then
        if ! [ -d /var/run/motion ]; then
                mkdir /var/run/motion
        fi
        chown motion:motion /var/run/motion
        chmod 775 /var/run/motion
    # this is the fix we've added to allow the network share to be connected first before we try to start motion:
	sleep 15
	log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --start --oknodo --startas $DAEMON -c motion.conf ; then
            log_end_msg 0
        else
            log_end_msg 1
            RET=1
        fi
    fi
    ;;

  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30 ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  reload|force-reload)
    log_daemon_msg "Reloading $NAME configuration"
    if start-stop-daemon --stop --signal HUP --exec $DAEMON ; then
        log_end_msg 0
    else
        log_end_msg 1
        RET=1
    fi
    ;;

  restart-motion)
    if check_daemon_enabled ; then
        log_daemon_msg "Restarting $NAME"
        if $0 stop && $0 start ; then
            log_action_end_msg 0
        else
            log_action_cont_msg "(failed)"
            RET=1
        fi
    fi
    ;;

  restart)
    $0 restart-motion
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
    RET=1
    ;;
esac


exit $RET
I always get

Code: Select all

motion.service - LSB: Start Motion detection
   Loaded: loaded (/etc/init.d/motion)
   Active: failed (Result: exit-code) since Sun 2016-05-15 19:08:49 CEST; 6s ago
  Process: 3824 ExecStart=/etc/init.d/motion start (code=exited, status=2)
I'm definitely not experienced in systemd etc., does any pro have a clue how to make this work, so motion is started on booting the raspi
Kind regards

anazazi

lowflyer
Posts: 75
Joined: Sat Jun 01, 2013 2:27 pm

Re: Motion - MMAL camera

Sun May 15, 2016 5:45 pm

Hi @pi-anazazi

Until someone does it properly for systemd, I put this in /etc/rc.local and it works fine.

Code: Select all

## startup motion
DAEMON='/home/pi/motion'
DAEMONARGS=" -c /home/pi/motion.conf" # Important : leave space before first argument
start-stop-daemon --start -b --exec $DAEMON --chuid pi --$DAEMONARGS

User avatar
pi-anazazi
Posts: 497
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: Motion - MMAL camera

Sun May 15, 2016 6:48 pm

Hi @ lowflyer!

Many, many thanx, for your quick reply, you ended hours of pain with your rc.local ! :-D

...just added sleep 15 to be sure the network share (for .jpgs and .avis) is mounted before motions starts and moved the pid file to /home/pi in the motion.config...

DONE!

very cool to have this forum
Kind regards

anazazi

User avatar
pi-anazazi
Posts: 497
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: Motion - MMAL camera

Tue May 17, 2016 5:34 pm

Hi again!

OK, this forum doesn't like screen shots, so we will have to go without...

I have here 2 Raspi 1B with a cam and motion, one with the old motion, one with the MMAL motion on jessie light, with identical montion.conf.

The old motion has 3-4% CPU time, the MMAL between 40% and 70%. That totally blocks the rest of the applications running.

Any advice how to reduce CPU usage of the MMAL motion?

Kind regards
Kind regards

anazazi

lowflyer
Posts: 75
Joined: Sat Jun 01, 2013 2:27 pm

Re: Motion - MMAL camera

Tue May 17, 2016 6:01 pm

Hi @pi-anazazi

What would probably be most useful would be to know the contents of your config file and to see the log from motion. You can increase the verbosity level of the motion log in the config file. Try increasing the verbosity level until it gives something interesting - or at least a difference between the 2 installations.

I find it the easiest way to do this is to launch motion in a terminal - not from /etc/rc.local. As long as daemon is off (the default setting), the log is printed to your screen.

Hope this helps!

User avatar
pi-anazazi
Posts: 497
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: Motion - MMAL camera

Wed May 18, 2016 9:22 am

Hi again!

Will test asap! :-)

I always use motion in daemon mode, is that a problem?

kind regards
Kind regards

anazazi

Return to “Camera board”