PiJay
Posts: 6
Joined: Mon Mar 07, 2016 7:08 pm

Re: MMAL Motion - tuning & optimisations

Sat Mar 12, 2016 10:07 pm

Thanks for your response! My question is how to display the video on the LCD I have connected to the Pi. Is this possible as well as running motion simultaneously?

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

Re: MMAL Motion - tuning & optimisations

Sun Mar 13, 2016 8:53 am

@PiJay

I don't use a display on my raspberry pi, so can't be much use to you.

First of all make sure that you have got motion to stream properly to another computer as I said in my last post.

Then, if your LCD is displaying a normal desktop on your raspberry pi (i.e. you are using X), are you saying that the web browser can't open http://localhost:8081?

Or if you are in text mode, have you looked at omxplayer, either playing that URL directly, or after creating a pipe. Google search is your friend.

Good luck!

eponymous
Posts: 3
Joined: Sat Apr 09, 2016 3:53 am

Re: MMAL Motion - tuning & optimisations

Tue Apr 26, 2016 5:54 am

Two questions:
  1. I am currently using motion (built from https://github.com/Mr-Dave/motion.git at 9b4c16c) on my Raspberry Pi to monitor the stream from an ipcam vis RTSP. Would I see performance improvements (work with higher frame rates for same CPU usage or lower CPU usage at same framerate) by switch to this MMAL build, or are those benefits only available when using the Pi's own camera?
  2. If I do switch, do I remove the existing version just by deleting /usr/local/bin/motion ?
Thanks!

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

Re: MMAL Motion - tuning & optimisations

Tue Apr 26, 2016 7:52 am

@eponymous

No, MMAL motion is a very clever way of using the Pi camera and the Graphics Processing Unit. It will probably work for RTSP, but all the processing will be done in the CPU, so won't offer any benefit.

If you get a Pi camera and want to run MMAL motion, you can leave your original version if you want, so long as it you stop it from starting automatically. Just make sure that you run the new version of motion with the right config file. See viewtopic.php?p=864996#p864996 and in particular the suggestion to run it with:

Code: Select all

/home/pi/motion/motion -c /home/pi/motion/configs/motion-mmalcam-both.conf
If you want the new motion to start automatically you can add it to /etc/rc.local.

Hope this helps.

eponymous
Posts: 3
Joined: Sat Apr 09, 2016 3:53 am

Re: MMAL Motion - tuning & optimisations

Sun May 01, 2016 5:31 am

Thanks @lowflyer.

Do you know of any Motion forks that use the RPi GPU when processing RTSP streams?

Thanks

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

Re: MMAL Motion - tuning & optimisations

Wed May 04, 2016 8:07 am

@eponymous

Sorry, I have never tried to use RTSP, so I don't know. At least the newer Pis are have a lot more CPU power.

Good luck!

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

Re: MMAL Motion - tuning & optimisations

Sun Feb 05, 2017 7:18 pm

I'd lost my pi for 3 years and when I found it again I couldn't get the camera working again. I got both the 8081 issue and the Video0 issue alternately.

Code: Select all

ps -ef | grep
motion showed that the daemon was already running.

Code: Select all

sudo service motion stop
resolved all issues

kiwi_cam
Posts: 2
Joined: Thu Feb 23, 2017 3:13 am

Re: MMAL Motion - tuning & optimisations

Fri Jul 21, 2017 1:00 am

I run a RasPi with Motion at the moment using a USB camera. It works great but the framerate sucks. I'm very interested in the optimisations discussed here but I don't have a RasPi Camera. Can I install MMAL Motion and implement the same optimisations (i.e. the secondary stream) using my existing USB camera?

ricklir
Posts: 1
Joined: Mon Oct 30, 2017 7:55 pm

Re: MMAL Motion - tuning & optimisations

Mon Oct 30, 2017 8:03 pm

I've been using dozencrows' binary for years on my own home surveilance system (3 PIs & central serve. An example herer: https://youtu.be/g5iid1o3eOU)

As the official Raspian motion package supports mmal now, I gave it a try on a RPI3. It works ok, but I couldn't find the secondary image buffer feature. Does anyone know, whether this was implemented or not? I had 1.5% CPU usage on the old PI, but now have much higher CPU usage with similar settings on the new system...

PaulGuijt
Posts: 4
Joined: Wed Sep 30, 2015 12:24 pm

Re: MMAL Motion - tuning & optimisations

Sun Apr 08, 2018 8:32 pm

I am trying to compile the motion-mmal branch on my Pi /w Raspbian stretch, following the BUILD-HOWTO.
I installed the required tools and dependencies, and cloned the branch.

This is the outcome of make:

Code: Select all

[  3%] Building C object CMakeFiles/motion.dir/alg.c.o
[  6%] Building ASM object CMakeFiles/motion.dir/alg_arm.s.o
[  9%] Building C object CMakeFiles/motion.dir/conf.c.o
[ 12%] Building C object CMakeFiles/motion.dir/draw.c.o
[ 15%] Building C object CMakeFiles/motion.dir/event.c.o
[ 18%] Building C object CMakeFiles/motion.dir/ffmpeg.c.o
/usr/src/motion/ffmpeg.c:27:10: warning: #warning ************************************************** [-Wcpp]
 #        warning **************************************************
          ^~~~~~~
/usr/src/motion/ffmpeg.c:28:10: warning: #warning Your version of FFmpeg is newer than version 0.4.8 [-Wcpp]
 #        warning Your version of FFmpeg is newer than version 0.4.8
          ^~~~~~~
/usr/src/motion/ffmpeg.c:29:10: warning: #warning Newer versions of ffmpeg do not support MPEG1 with [-Wcpp]
 #        warning Newer versions of ffmpeg do not support MPEG1 with
          ^~~~~~~
/usr/src/motion/ffmpeg.c:30:10: warning: #warning non-standard framerate. MPEG1 will be disabled for [-Wcpp]
 #        warning non-standard framerate. MPEG1 will be disabled for
          ^~~~~~~
/usr/src/motion/ffmpeg.c:31:10: warning: #warning normal video output. You can still use mpeg4 and [-Wcpp]
 #        warning normal video output. You can still use mpeg4 and
          ^~~~~~~
/usr/src/motion/ffmpeg.c:32:10: warning: #warning and mpeg4ms which are both better in terms of size [-Wcpp]
 #        warning and mpeg4ms which are both better in terms of size
          ^~~~~~~
/usr/src/motion/ffmpeg.c:33:10: warning: #warning and quality. MPEG1 is always used for timelapse. [-Wcpp]
 #        warning and quality. MPEG1 is always used for timelapse.
          ^~~~~~~
/usr/src/motion/ffmpeg.c:34:10: warning: #warning Please read the Motion Guide for more information. [-Wcpp]
 #        warning Please read the Motion Guide for more information.
          ^~~~~~~
/usr/src/motion/ffmpeg.c:35:10: warning: #warning Note that this is not an error message! [-Wcpp]
 #        warning Note that this is not an error message!
          ^~~~~~~
/usr/src/motion/ffmpeg.c:36:10: warning: #warning ************************************************** [-Wcpp]
 #        warning **************************************************
          ^~~~~~~
/usr/src/motion/ffmpeg.c: In function ‘get_oformat’:
/usr/src/motion/ffmpeg.c:377:31: error: ‘CODEC_ID_MSMPEG4V2’ undeclared (first use in this function)
             of->video_codec = CODEC_ID_MSMPEG4V2;
                               ^~~~~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:377:31: note: each undeclared identifier is reported only once for each function it appears in
/usr/src/motion/ffmpeg.c:393:27: error: ‘CODEC_ID_FLV1’ undeclared (first use in this function)
         of->video_codec = CODEC_ID_FLV1;
                           ^~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:406:31: error: ‘CODEC_ID_FFV1’ undeclared (first use in this function)
             of->video_codec = CODEC_ID_FFV1;
                               ^~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_open’:
/usr/src/motion/ffmpeg.c:502:45: error: ‘CODEC_ID_NONE’ undeclared (first use in this function)
     if (ffmpeg->oc->oformat->video_codec != CODEC_ID_NONE) {
                                             ^~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:522:5: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
     ffmpeg->c     = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st);
     ^~~~~~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c:529:36: error: ‘CODEC_ID_MPEG1VIDEO’ undeclared (first use in this function)
     is_mpeg1      = c->codec_id == CODEC_ID_MPEG1VIDEO;
                                    ^~~~~~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:598:18: error: ‘PIX_FMT_YUV420P’ undeclared (first use in this function)
     c->pix_fmt = PIX_FMT_YUV420P;
                  ^~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:635:23: warning: implicit declaration of function ‘avcodec_alloc_frame’ [-Wimplicit-function-declaration]
     ffmpeg->picture = avcodec_alloc_frame();
                       ^~~~~~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:635:21: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     ffmpeg->picture = avcodec_alloc_frame();
                     ^
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_cleanups’:
/usr/src/motion/ffmpeg.c:740:9: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
         if (ffmpeg->video_st->codec->priv_data != NULL)
         ^~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c:742:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
             avcodec_close(AVSTREAM_CODEC_PTR(ffmpeg->video_st));
             ^~~~~~~~~~~~~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_close’:
/usr/src/motion/ffmpeg.c:774:9: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
         avcodec_close(AVSTREAM_CODEC_PTR(ffmpeg->video_st));
         ^~~~~~~~~~~~~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_put_frame’:
/usr/src/motion/ffmpeg.c:886:9: warning: ‘avcodec_encode_video2’ is deprecated [-Wdeprecated-declarations]
         out_size = avcodec_encode_video2(AVSTREAM_CODEC_PTR(ffmpeg->video_st),
         ^~~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:5333:5: note: declared here
 int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
     ^~~~~~~~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:886:9: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
         out_size = avcodec_encode_video2(AVSTREAM_CODEC_PTR(ffmpeg->video_st),
         ^~~~~~~~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c:905:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
             pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts;
             ^~~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c:905:13: warning: ‘coded_frame’ is deprecated [-Wdeprecated-declarations]
             pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts;
             ^~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3109:35: note: declared here
     attribute_deprecated AVFrame *coded_frame;
                                   ^~~~~~~~~~~
/usr/src/motion/ffmpeg.c:907:13: warning: ‘codec’ is deprecated [-Wdeprecated-declarations]
             if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame)
             ^~
In file included from /usr/src/motion/ffmpeg.h:8:0,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavformat/avformat.h:893:21: note: declared here
     AVCodecContext *codec;
                     ^~~~~
/usr/src/motion/ffmpeg.c:907:13: warning: ‘coded_frame’ is deprecated [-Wdeprecated-declarations]
             if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame)
             ^~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3109:35: note: declared here
     attribute_deprecated AVFrame *coded_frame;
                                   ^~~~~~~~~~~
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_prepare_frame’:
/usr/src/motion/ffmpeg.c:952:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     picture = avcodec_alloc_frame();
             ^
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_deinterlace’:
/usr/src/motion/ffmpeg.c:993:5: warning: ‘data’ is deprecated [-Wdeprecated-declarations]
     picture.data[0] = img;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3902:14: note: declared here
     uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes
              ^~~~
/usr/src/motion/ffmpeg.c:994:5: warning: ‘data’ is deprecated [-Wdeprecated-declarations]
     picture.data[1] = img + width * height;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3902:14: note: declared here
     uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes
              ^~~~
/usr/src/motion/ffmpeg.c:995:5: warning: ‘data’ is deprecated [-Wdeprecated-declarations]
     picture.data[2] = picture.data[1] + (width * height) / 4;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3902:14: note: declared here
     uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes
              ^~~~
/usr/src/motion/ffmpeg.c:995:5: warning: ‘data’ is deprecated [-Wdeprecated-declarations]
     picture.data[2] = picture.data[1] + (width * height) / 4;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3902:14: note: declared here
     uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes
              ^~~~
/usr/src/motion/ffmpeg.c:996:5: warning: ‘linesize’ is deprecated [-Wdeprecated-declarations]
     picture.linesize[0] = width;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3904:9: note: declared here
     int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line
         ^~~~~~~~
/usr/src/motion/ffmpeg.c:997:5: warning: ‘linesize’ is deprecated [-Wdeprecated-declarations]
     picture.linesize[1] = width2;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3904:9: note: declared here
     int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line
         ^~~~~~~~
/usr/src/motion/ffmpeg.c:998:5: warning: ‘linesize’ is deprecated [-Wdeprecated-declarations]
     picture.linesize[2] = width2;
     ^~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/libavformat/avformat.h:319:0,
                 from /usr/src/motion/ffmpeg.h:8,
                 from /usr/src/motion/ffmpeg.c:15:
/usr/include/arm-linux-gnueabihf/libavcodec/avcodec.h:3904:9: note: declared here
     int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line
         ^~~~~~~~
/usr/src/motion/ffmpeg.c:1001:5: warning: implicit declaration of function ‘avpicture_deinterlace’ [-Wimplicit-function-declaration]
     avpicture_deinterlace(&picture, &picture, PIX_FMT_YUV420P, width, height);
     ^~~~~~~~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c:1001:47: error: ‘PIX_FMT_YUV420P’ undeclared (first use in this function)
     avpicture_deinterlace(&picture, &picture, PIX_FMT_YUV420P, width, height);
                                               ^~~~~~~~~~~~~~~
/usr/src/motion/ffmpeg.c: In function ‘ffmpeg_open’:
/usr/src/motion/ffmpeg.c:718:5: warning: ignoring return value of ‘avformat_write_header’, declared with attribute warn_unused_result [-Wunused-result]
     avformat_write_header(ffmpeg->oc, NULL);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CMakeFiles/motion.dir/build.make:174: recipe for target 'CMakeFiles/motion.dir/ffmpeg.c.o' failed
make[2]: *** [CMakeFiles/motion.dir/ffmpeg.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/motion.dir/all' failed
make[1]: *** [CMakeFiles/motion.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
What to do now?
Paul

informed
Posts: 124
Joined: Mon Oct 26, 2015 6:24 pm

Re: MMAL Motion - tuning & optimisations

Wed Oct 31, 2018 7:32 pm

Hi,

Is there a way to capture the byte array of the image without saving is to disk?

I have tried intercepting the code here:

/// <summary>
/// The callback function to carry out.
/// </summary>
/// <param name="buffer">The working buffer header.</param>
public override void Callback(
MMALBufferImpl buffer )
{
base.Callback( buffer );

var data = buffer.GetBufferData();
if ( data.Length > 0 )
{
Console.WriteLine(DateTime.Now + " Callback " + data.Length);
ImageProcessing.HeartBeat.ProcessFrame(data);
this.WorkingPort.ComponentReference.Handler?.Process(data);
}
}


but all i get are incomplete images.

So, i am guessing that I need to read the EOF. But what is it please?

techyian
Posts: 63
Joined: Mon Jan 22, 2018 11:40 am

Re: MMAL Motion - tuning & optimisations

Thu Nov 01, 2018 9:01 pm

@informed - MMAL Motion is a different project to MMALSharp. I have replied to your query in the MMALSharp thread.
MMALSharp - C# API for the Raspberry Pi camera module

https://github.com/techyian/MMALSharp

Return to “Camera board”