Install Motion-MMAL

The objective of this guide is install a special binary of Motion software compiled and build by the RPi community with support for the Raspberry Pi Camera Module. If you don’t know what the Motion software is then have a look here
Until now there not an official support for this camera module by the Motion software.



(adsbygoogle = window.adsbygoogle || []).push({});

 
 

Before we start

First of all be sure that the Raspberry Pi camera module is connected the proper way with the RPi. Next update and upgrade your version of Raspbian. Finally, have a look if the module is enabled from the configuration window. Type

sudo raspi-config

Find the Enable Camera and press enter

Select Enable using your left-right arrow keys from your keyboard and press Enter. You will automatically jump to the first menu and you have to select Finish. The Raspberry Pi will ask you to do a reboot. Select Yes and the reboot process will start automatically.

 
 

Instal Motion-MMAL

After the reboot process ends, open again a terminal session with the RPi and type:

sudo apt-get install motion

It will ask you if you want to install motion. Press Y, when it is requested, and wait until everything are loaded and installed successfully. This might take from 30sec to 2 minutes depending from your internet connection. When everything finish type:

sudo apt-get remove motion

This command will remove motion! It sounds strange to do that when we just install it with the previous command but the truth is that will left some dependencies untouched and those are the ones that we need! Have in mind that our needed software for this guide is the Motion-MMAL and not the regular Motion.

Now it is time to install the Motion-MMAL. The best way to do that is to download a pre-compiled version of it using the wget command.

wget https://www.dropbox.com/s/0gzxtkxhvwgfocs/motion-mmal.tar.gz

And now unzip the file

tar zxvf motion-mmal.tar.gz

Open the configuration file with the nano editor

sudo nano motion-mmalcam.conf

On your screen you will have a multi pages file like this one

It contains lot of settings that you are free to modify based on your needs. However you must change a few of those in order to have a usable and stable system without freezes and random resets.

-Turn deamon On
-Image resolution 640×480
-output_pictures and ffmpeg_output_movies to Off if you don’t want to store pictures/clips on your SD card
-stream_localhost to Off in order to have access to your full network

Press Ctrl-X, Y and finally Enter. And now its time to run the software

sudo ./motion -c motion-mmalcam.conf

The camera module red led will light. That means that everything are going as suppose to be. Now if you want to see the live stream of the camera open a browser window and type

http://Your_RPi_IP_Address:8081

 
 

A few “bug” fixes

It seems that sometimes the libjpeg.so.9 is missing and the Motion-MMAL is unable to start. You will understand that if you have something like this: error while loading shared libraries: libjpeg.so.9: cannot open shared object file: No such file or directory on your terminal screen. A quick solution to this is to install it

sudo apt-get install libjpeg62

Now run again the software and everything should be OK

 
 

Disable the red LED

Under Construction

92 thoughts on “Install Motion-MMAL

  1. embeddedday says:

    Hi to everyone!

    I am having more than 150 hits every day for this article alone… and not even one like or share!
    If you like it or find it useful, then hit the “Like” button! It helps a lot!!!

    Thanks in advance to everyone!

  2. Francesc says:

    Motion started ok and camera led is on but can’t access to the webbrowser stream, internet explorer asks to download a file and chrome does nothing.

    Help please!

  3. webeixon says:

    Installed without errors, camera led is on but internet explorer asks to download a file with name XGHSNFRD (no extension). Chrome does nothing.

    HELP!!!!

  4. webeixon says:

    Firefox working ok!

  5. embeddedday says:

    Hi webeixon!

    I really don’t know what XGHSNFRD file is! I will investigate and hopefully I will have an answer soon…

    But the problem it seems to be browser oriented if firefox is running fine! What Chrome version as you using?

    • webeixon says:

      Latest version of each web browser in win7 x64. Chrome says 404. Iexplorer asks to download a file with a random name each time i refresh the page and firefox works ok. Chrome for android says 404. Native web browser works ok. I’ve a galaxy s4.

  6. Jacob says:

    Hi,

    tested and work as mentioned (I am using Windows 7 + Firefox 34.0)
    Had just the problem with libjpeg62, but the “apt-get install …” command solve the problem.

    Thanks for your article, it’s a great help to start.

  7. Anonymous says:

    To get the image stream to work with Chrome:

    mkdir /var/motion
    cd /var/motion
    echo “” > index.html
    python -m SimpleHTTPServer 8001 &

    Then point Chrome at:

    http://ip of raspberry pi:8001/

    • embeddedday says:

      Thats great news!!! Many thanks!!!

    • I was initially getting “cannot create directory: Permission denied” error for mkdir.. Tried it with sudo. Worked. But then I’m getting an error “bash: index.html: Permission denied”.. Any fix?

      • anon2 says:

        Don’t waste your time. Python -m SimpleHTTPServer simply makes available the current working directory via HTTP. Having an empty (“” > index.html) results in a blank default page and always will. But the permission issue you’re having is because you just created a directory with sudo and that won’t give your user the permissions to write to that directory.

  8. Anonymous says:

    hi,
    many thanks from France for your greatfull tutos
    it was the solution for me to make up the camera
    smiles

  9. Tom says:

    Anyone know how to run at startup?

  10. Bryan says:

    What would the stop command be? Normal motion stop is “sudo service motion stop” but I tried a bunch of variations that didn’t seem to work…

  11. cho says:

    Hi. Really thanks for your post. But there is one problem with my practice. I put the command ” netstat -tulpn” and I can’t find the port (8081) which pi-cam is using. All ports are not used. Shouldn’t at least one port be used?
    And is there any way to use in other internet like Chrome and Internet Explorer?

    Thanks.

  12. Works a treat, Thanks!

    Just one question. I think you were going write something about disabling the LED? I’d like to get it so that the LED is on while recording. Any ideas?

    Thanks again.

  13. alex says:

    Hi
    thank u very much for the informative article!
    What is the command to stop motion-mmalcam?
    Where do I put like?
    Regards,
    Alex

  14. Anonymous says:

    Hey Guys,

    I also would like to know how do i stop motion-mmalcam?!

  15. Anonymous says:

    I’m having a problem.

    I did everything in this article as I should have, but when I type in “http://192.168.10.102” into my Firefox browser, it doesn’t connect to the page. It doesn’t make an error message either, it just sits there saying it’s connecting. There is a red light on my pi cam, so I guess that works… Anybody have any ideas? Please help!

  16. Hugh Barnard says:

    Thanks. Looks good, but [this is not a criticism] crashes after about 3k images, if you let it store images. I’m using Raspian Wheezy, I may try ArchLinux if I have time.

  17. Mark says:

    It’s working fine.. for those looking to stop the server and Motion.. Ctrl+c will stop it if you haven’t enabled the daemon. I run motion from a directory inside /home/pi/cam/ .. you have to make sure that pi owns the files. I start and stop from an ssh session. If you want to start motion but still need to work on the pi in some fashion, I suggest installing and using screen, a cli multiplexer. It will allow you to login via ssh, type screen, launch motion, create another cli session for work, leave all running and disconnect from the screen session and close down your ssh session, return later and re-attach to screen and everything that was left running.

    What I’m interested in is, if I can use the original motion.conf file instead of the mmalcam.conf file…. or if I can copy and paste the contents of the original .conf to the new one and have the same items and functionality?

  18. John says:

    Tried this step by step. When i run the final command it seems to execute, but the camera does not turn on (LED does not light) and trying to access the pi there is nothing hosted

    output:
    pi@raspberrypi ~ $ sudo ./motion -c motion-mmalcam.conf
    [-1242238088] [NTC] [ALL] conf_load: Processing thread 0 – config file motion-mmalcam.conf
    [-1242238088] [NTC] [ALL] motion_startup: Motion mmaltest Started
    [-1242238088] [NTC] [ALL] motion_startup: Logging to file (/home/pi/motion.log)
    pi@raspberrypi ~ $

    • Mark says:

      A couple of things.. When you unpacked the tar.gz file was it in its own directory? Second, when you start motion do you “cd” into that directory first? and is your motion-mmalcam.conf located in that same location?. I created a directory called “cam” in my /home/pi. Everything is in /home/pi/cam including another directory called photos where motion-mmalcom.conf stores pics and video (I set this in the .conf file). I found that I can start motion from almost anywhere but without changing directories into /home/pi/cam (my named location) it will start motion but use the default motion.conf not the newer motion-mmalcom.conf and look for a standard webcam, not seeing the pi-cam I have connected.

      • John says:

        i retried using ~/cam and launching from there, same issue. Im not entirely sure how to set the photos directory up in the .conf (sorry im a noob)

        • Mark says:

          No worries. here’s a copy of my motion-mmalcam.conf. I’ve disabled jpg’s and only capture video once motion is detected. This is the camera I’m using. It’s infrared. http://goo.gl/YsLJbN. Note that I don’t use the deamon. I choose to turn motion on and off via ssh. Also everything in my ~/cam directory is owned by pi. That eliminates having to use sudo to start motion. To do that “cd ~/cam”. Then “sudo chown pi:pi * ” .. There is a space between the second pi and *. You also have to be careful when inserting the ribbon cable into the pi. The silver contacts face away from the ethernet port and the amount of silver showing should be equal across the connector. If they are not you might not get power to the camera. Good Luck!

          # motion-mmalcam.conf
          #
          # This config file was generated by motion mmaltest

          ############################################################
          # Daemon
          ############################################################

          # Start in daemon (background) mode and release terminal (default: off)
          daemon off

          #File to store the process ID, also called pid file. (default: not defined)
          process_id_file /var/run/motion/motion.pid

          ############################################################
          # Basic Setup Mode
          ############################################################

          # Start in Setup-Mode, daemon disabled. (default: off)
          setup_mode off

          # Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined)
          logfile /home/pi/cam/motion.log

          # Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 6 / NTC)
          log_level 5

          # Filter to log messages by type (COR, STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)
          log_type all

          ###########################################################
          # Capture device options
          ############################################################

          # Videodevice to be used for capturing (default /dev/video0)
          # for FreeBSD default is /dev/bktr0
          videodevice /dev/video0

          # v4l2_palette allows to choose preferable palette to be use by motion
          # to capture from those supported by your videodevice. (default: 17)
          # E.g. if your videodevice supports both V4L2_PIX_FMT_SBGGR8 and
          # V4L2_PIX_FMT_MJPEG then motion will by default use V4L2_PIX_FMT_MJPEG.
          # Setting v4l2_palette to 2 forces motion to use V4L2_PIX_FMT_SBGGR8
          # instead.
          #
          # Values :
          # V4L2_PIX_FMT_SN9C10X : 0 ‘S910’
          # V4L2_PIX_FMT_SBGGR16 : 1 ‘BYR2’
          # V4L2_PIX_FMT_SBGGR8 : 2 ‘BA81’
          # V4L2_PIX_FMT_SPCA561 : 3 ‘S561’
          # V4L2_PIX_FMT_SGBRG8 : 4 ‘GBRG’
          # V4L2_PIX_FMT_SGRBG8 : 5 ‘GRBG’
          # V4L2_PIX_FMT_PAC207 : 6 ‘P207’
          # V4L2_PIX_FMT_PJPG : 7 ‘PJPG’
          # V4L2_PIX_FMT_MJPEG : 8 ‘MJPEG’
          # V4L2_PIX_FMT_JPEG : 9 ‘JPEG’
          # V4L2_PIX_FMT_RGB24 : 10 ‘RGB3’
          # V4L2_PIX_FMT_SPCA501 : 11 ‘S501’
          # V4L2_PIX_FMT_SPCA505 : 12 ‘S505’
          # V4L2_PIX_FMT_SPCA508 : 13 ‘S508’
          # V4L2_PIX_FMT_UYVY : 14 ‘UYVY’
          # V4L2_PIX_FMT_YUYV : 15 ‘YUYV’
          # V4L2_PIX_FMT_YUV422P : 16 ‘422P’
          # V4L2_PIX_FMT_YUV420 : 17 ‘YU12’
          #
          v4l2_palette 17

          # The video input to be used (default: -1)
          # Should normally be set to 0 or 1 for video/TV cards, and -1 for USB cameras
          input -1

          # The video norm to use (only for video capture and TV tuner cards)
          # Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL)
          norm 0

          # The frequency to set the tuner to (kHz) (only for TV tuner cards) (default: 0)
          frequency 0

          # Rotate image this number of degrees. The rotation affects all saved images as
          # well as movies. Valid values: 0 (default = no rotation), 90, 180 and 270.
          rotate 180

          # Image width (pixels). Valid range: Camera dependent, default: 352
          width 1280

          # Image height (pixels). Valid range: Camera dependent, default: 288
          height 720

          # Maximum number of frames to be captured per second.
          # Valid range: 2-100. Default: 100 (almost no limit).
          framerate 10

          # Minimum time in seconds between capturing picture frames from the camera.
          # Default: 0 = disabled – the capture rate is given by the camera framerate.
          # This option is used when you want to capture images at a rate lower than 2 per second.
          minimum_frame_time 0

          # URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// mjpg:// or file:///)
          # Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined
          ; netcam_url value

          # Username and password for network camera (only if required). Default: not defined
          # Syntax is user:password
          ; netcam_userpass value

          # The setting for keep-alive of network socket, should improve performance on compatible net cameras.
          # off: The historical implementation using HTTP/1.0, closing the socket after each http request.
          # force: Use HTTP/1.0 requests with keep alive header to reuse the same connection.
          # on: Use HTTP/1.1 requests that support keep alive as default.
          # Default: off
          netcam_keepalive off

          # URL to use for a netcam proxy server, if required, e.g. “http://myproxy”.
          # If a port number other than 80 is needed, use “http://myproxy:1234”.
          # Default: not defined
          ; netcam_proxy value

          # Set less strict jpeg checks for network cameras with a poor/buggy firmware.
          # Default: off
          netcam_tolerant_check off

          # Path to file containing raw captured YUV frames from which to read input
          Default: Not defined
          ; filecam_path value

          # Name of camera to use if you are using a camera accessed through OpenMax/MMAL
          Default: Not defined
          mmalcam_name vc.ril.camera

          # Camera control parameters (see raspivid/raspistill tool documentation)
          Default: Not defined
          ; mmalcam_control_params value

          # Use the still camera output – limits frame rate, but can show more of frame
          Default: off
          mmalcam_use_still off

          # Path to file where raw dump of camera YUV capture will be written (for testing, profiling & debugging)
          Default: Not defined
          ; mmalcam_raw_capture_file value

          # Let motion regulate the brightness of a video device (default: off).
          # The auto_brightness feature uses the brightness option as its target value.
          # If brightness is zero auto_brightness will adjust to average brightness value 128.
          # Only recommended for cameras without auto brightness
          auto_brightness on

          # Set the initial brightness of a video device.
          # If auto_brightness is enabled, this value defines the average brightness level
          # which Motion will try and adjust to.
          # Valid range 0-255, default 0 = disabled
          brightness 0

          # Set the contrast of a video device.
          # Valid range 0-255, default 0 = disabled
          contrast 0

          # Set the saturation of a video device.
          # Valid range 0-255, default 0 = disabled
          saturation 0

          # Set the hue of a video device (NTSC feature).
          # Valid range 0-255, default 0 = disabled
          hue 0

          ############################################################
          # Round Robin (multiple inputs on same video device name)
          ############################################################

          # Number of frames to capture in each roundrobin step (default: 1)
          roundrobin_frames 1

          # Number of frames to skip before each roundrobin step (default: 1)
          roundrobin_skip 1

          # Try to filter out noise generated by roundrobin (default: off)
          switchfilter off

          ############################################################
          # Motion Detection Settings:
          ############################################################

          # Threshold for number of changed pixels in an image that
          # triggers motion detection (default: 1500)
          threshold 1500

          # Automatically tune the threshold down if possible (default: off)
          threshold_tune off

          # Noise threshold for the motion detection (default: 32)
          noise_level 32

          # Automatically tune the noise threshold (default: on)
          noise_tune on

          # Despeckle motion image using (e)rode or (d)ilate or (l)abel (Default: not defined)
          # Recommended value is EedDl. Any combination (and number of) of E, e, d, and D is valid.
          # (l)abeling must only be used once and the ‘l’ must be the last letter.
          # Comment out to disable
          despeckle_filter EedDl

          # Detect motion in predefined areas (1 – 9). Areas are numbered like that: 1 2 3
          # A script (on_area_detected) is started immediately when motion is 4 5 6
          # detected in one of the given areas, but only once during an event. 7 8 9
          # One or more areas can be specified with this option. Take care: This option
          # does NOT restrict detection to these areas! (Default: not defined)
          ; area_detect value

          # PGM file to use as a sensitivity mask.
          # Full path name to. (Default: not defined)
          ; mask_file value

          # Dynamically create a mask file during operation (default: 0)
          # Adjust speed of mask changes from 0 (off) to 10 (fast)
          smart_mask_speed 0

          # Ignore sudden massive light intensity changes given as a percentage of the picture
          # area that changed intensity. If set to 1, motion will do some kind of
          # auto-lightswitch. Valid range: 0 – 100 , default: 0 = disabled
          lightswitch 0

          # Picture frames must contain motion at least the specified number of frames
          # in a row before they are detected as true motion. At the default of 1, all
          # motion is detected. Valid range: 1 to thousands, recommended 1-5
          minimum_motion_frames 1

          # Specifies the number of pre-captured (buffered) pictures from before motion
          # was detected that will be output at motion detection.
          # Recommended range: 0 to 5 (default: 0)
          # Do not use large values! Large values will cause Motion to skip video frames and
          # cause unsmooth movies. To smooth movies use larger values of post_capture instead.
          pre_capture 0

          # Number of frames to capture after motion is no longer detected (default: 0)
          post_capture 0

          # Event Gap is the seconds of no motion detection that triggers the end of an event.
          # An event is defined as a series of motion images taken within a short timeframe.
          # Recommended value is 60 seconds (Default). The value -1 is allowed and disables
          # events causing all Motion to be written to one single movie file and no pre_capture.
          # If set to 0, motion is running in gapless mode. Movies don’t have gaps anymore. An
          # event ends right after no more motion is detected and post_capture is over.
          event_gap 10

          # Maximum length in seconds of a movie
          # When value is exceeded a new movie file is created. (Default: 0 = infinite)
          max_movie_time 0

          # Always save images even if there was no motion (default: off)
          emulate_motion off

          ############################################################
          # Image File Output
          ############################################################

          # Output ‘normal’ pictures when motion is detected (default: on)
          # Valid values: on, off, first, best, center
          # When set to ‘first’, only the first picture of an event is saved.
          # Picture with most motion of an event is saved when set to ‘best’.
          # Picture with motion nearest center of picture is saved when set to ‘center’.
          # Can be used as preview shot for the corresponding movie.
          output_pictures off

          # Output pictures with only the pixels moving object (ghost images) (default: off)
          output_debug_pictures off

          # The quality (in percent) to be used by the jpeg compression (default: 75)
          quality 75

          # Type of output images
          # Valid values: jpeg, ppm (default: jpeg)
          picture_type jpeg

          ############################################################
          # FFMPEG related options
          # Film (movie) file output, and deinterlacing of the video input
          # The options movie_filename and timelapse_filename are also used
          # by the ffmpeg feature
          ############################################################

          # Use ffmpeg to encode movies in realtime (default: off)
          ffmpeg_output_movies on

          # Use ffmpeg to make movies with only the pixels moving
          # object (ghost images) (default: off)
          ffmpeg_output_debug_movies off

          # Use ffmpeg to encode a timelapse movie
          # Default value 0 = off – else save frame every Nth second
          ffmpeg_timelapse 0

          # The file rollover mode of the timelapse video
          # Valid values: hourly, daily (default), weekly-sunday, weekly-monday, monthly, manual
          ffmpeg_timelapse_mode daily

          # Bitrate to be used by the ffmpeg encoder (default: 400000)
          # This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled)
          ffmpeg_bps 500000

          # Enables and defines variable bitrate for the ffmpeg encoder.
          # ffmpeg_bps is ignored if variable bitrate is enabled.
          # Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps,
          # or the range 2 – 31 where 2 means best quality and 31 is worst.
          ffmpeg_variable_bitrate 0

          # Codec to used by ffmpeg for the video compression.
          # Timelapse movies are always made in mpeg1 format independent from this option.
          # Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.
          # mpeg1 – gives you files with extension .mpg
          # mpeg4 or msmpeg4 – gives you files with extension .avi
          # msmpeg4 is recommended for use with Windows Media Player because
          # it requires no installation of codec on the Windows client.
          # swf – gives you a flash film with extension .swf
          # flv – gives you a flash video with extension .flv
          # ffv1 – FF video codec 1 for Lossless Encoding ( experimental )
          # mov – QuickTime ( testing )
          # ogg – Ogg/Theora ( testing )
          ffmpeg_video_codec mpeg4

          # Use ffmpeg to deinterlace video. Necessary if you use an analog camera
          # and see horizontal combing on moving objects in video or pictures.
          # (default: off)
          ffmpeg_deinterlace off

          ############################################################
          # External pipe to video encoder
          # Replacement for FFMPEG builtin encoder for ffmpeg_output_movies only.
          # The options movie_filename and timelapse_filename are also used
          # by the ffmpeg feature
          ############################################################

          # Bool to enable or disable extpipe (default: off)
          use_extpipe off

          # External program (full path and opts) to pipe raw video to
          # Generally, use ‘-‘ for STDIN…
          ; extpipe value

          ############################################################
          # Snapshots (Traditional Periodic Webcam File Output)
          ############################################################

          # Make automated snapshot every N seconds (default: 0 = disabled)
          snapshot_interval 0

          ############################################################
          # Text Display
          # %Y = year, %m = month, %d = date,
          # %H = hour, %M = minute, %S = second, %T = HH:MM:SS,
          # %v = event, %q = frame number, %t = thread (camera) number,
          # %D = changed pixels, %N = noise level, \n = new line,
          # %i and %J = width and height of motion area,
          # %K and %L = X and Y coordinates of motion center
          # %C = value defined by text_event – do not use with text_event!
          # You can put quotation marks around the text to allow
          # leading spaces
          ############################################################

          # Locate and draw a box around the moving object.
          # Valid values: on, off, preview (default: off)
          # Set to ‘preview’ will only draw a box in preview_shot pictures.
          locate_motion_mode off

          # Set the look and style of the locate box if enabled.
          # Valid values: box, redbox, cross, redcross (default: box)
          # Set to ‘box’ will draw the traditional box.
          # Set to ‘redbox’ will draw a red box.
          # Set to ‘cross’ will draw a little cross to mark center.
          # Set to ‘redcross’ will draw a little red cross to mark center.
          locate_motion_style box

          # Draws the timestamp using same options as C function strftime(3)
          # Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock
          # Text is placed in lower right corner
          text_right %Y-%m-%d\n%T-%q

          # Draw a user defined text on the images using same options as C function strftime(3)
          # Default: Not defined = no text
          # Text is placed in lower left corner
          ; text_left value

          # Draw the number of changed pixed on the images (default: off)
          # Will normally be set to off except when you setup and adjust the motion settings
          # Text is placed in upper right corner
          text_changes off

          # This option defines the value of the special event conversion specifier %C
          # You can use any conversion specifier in this option except %C. Date and time
          # values are from the timestamp of the first image in the current event.
          # Default: %Y%m%d%H%M%S
          # The idea is that %C can be used filenames and text_left/right for creating
          # a unique identifier for each event.
          text_event %Y%m%d%H%M%S

          # Draw characters at twice normal size on images. (default: off)
          text_double on

          # Text to include in a JPEG EXIF comment
          # May be any text, including conversion specifiers.
          # The EXIF timestamp is included independent of this text.
          ; exif_text value

          ############################################################
          # Target Directories and filenames For Images And Films
          # For the options snapshot_, picture_, movie_ and timelapse_filename
          # you can use conversion specifiers
          # %Y = year, %m = month, %d = date,
          # %H = hour, %M = minute, %S = second,
          # %v = event, %q = frame number, %t = thread (camera) number,
          # %D = changed pixels, %N = noise level,
          # %i and %J = width and height of motion area,
          # %K and %L = X and Y coordinates of motion center
          # %C = value defined by text_event
          # Quotation marks round string are allowed.
          ############################################################

          # Target base directory for pictures and films
          # Recommended to use absolute path. (Default: current working directory)
          target_dir /home/pi/cam/photos

          # File path for snapshots (jpeg or ppm) relative to target_dir
          # Default: %v-%Y%m%d%H%M%S-snapshot
          # Default value is equivalent to legacy oldlayout option
          # For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-snapshot
          # File extension .jpg or .ppm is automatically added so do not include this.
          # Note: A symbolic link called lastsnap.jpg created in the target_dir will always
          # point to the latest snapshot, unless snapshot_filename is exactly ‘lastsnap’
          snapshot_filename %v-%Y%m%d%H%M%S-snapshot

          # File path for motion triggered images (jpeg or ppm) relative to target_dir
          # Default: %v-%Y%m%d%H%M%S-%q
          # Default value is equivalent to legacy oldlayout option
          # For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-%q
          # File extension .jpg or .ppm is automatically added so do not include this
          # Set to ‘preview’ together with best-preview feature enables special naming
          # convention for preview shots. See motion guide for details
          picture_filename %v-%Y%m%d%H%M%S-%q

          # File path for motion triggered ffmpeg films (movies) relative to target_dir
          # Default: %v-%Y%m%d%H%M%S
          # Default value is equivalent to legacy oldlayout option
          # For Motion 3.0 compatible mode choose: %Y/%m/%d/%H%M%S
          # File extension .mpg or .avi is automatically added so do not include this
          # This option was previously called ffmpeg_filename
          movie_filename %v-%Y%m%d%H%M%S

          # File path for timelapse movies relative to target_dir
          # Default: %Y%m%d-timelapse
          # Default value is near equivalent to legacy oldlayout option
          # For Motion 3.0 compatible mode choose: %Y/%m/%d-timelapse
          # File extension .mpg is automatically added so do not include this
          timelapse_filename %Y%m%d-timelapse

          ############################################################
          # Global Network Options
          ############################################################

          # Enable or disable IPV6 for http control and stream (default: off)
          ipv6_enabled off

          ############################################################
          # Live Stream Server
          ############################################################

          # The mini-http server listens to this port for requests (default: 0 = disabled)
          stream_port 8081

          # Quality of the jpeg (in percent) images produced (default: 50)
          stream_quality 50

          # Output frames at 1 fps when no motion is detected and increase to the
          # rate given by stream_maxrate when motion is detected (default: off)
          stream_motion off

          # Maximum framerate for streams (default: 1)
          stream_maxrate 1

          # Restrict stream connections to localhost only (default: on)
          stream_localhost off

          # Limits the number of images per connection (default: 0 = unlimited)
          # Number can be defined by multiplying actual stream rate by desired number of seconds
          # Actual stream rate is the smallest of the numbers framerate and stream_maxrate
          stream_limit 0

          # Set the authentication method (default: 0)
          # 0 = disabled
          # 1 = Basic authentication
          # 2 = MD5 digest (the safer authentication)

          stream_auth_method 0

          # Authentication for the stream. Syntax username:password
          # Default: not defined (Disabled)
          ; stream_authentication value

          ############################################################
          # HTTP Based Control
          ############################################################

          # TCP/IP port for the http server to listen on (default: 0 = disabled)
          webcontrol_port 8080

          # Restrict control connections to localhost only (default: on)
          webcontrol_localhost off

          # Output for http server, select off to choose raw text plain (default: on)
          webcontrol_html_output on

          # Authentication for the http based control. Syntax username:password
          # Default: not defined (Disabled)
          ; webcontrol_authentication value

          ############################################################
          # Tracking (Pan/Tilt)
          ############################################################

          # Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo)
          # The generic type enables the definition of motion center and motion size to
          # be used with the conversion specifiers for options like on_motion_detected
          track_type 0

          # Enable auto tracking (default: off)
          track_auto off

          # Serial port of motor (default: none)
          ; track_port value

          # Motor number for x-axis (default: 0)
          track_motorx 0

          # Set motorx reverse (default: off)
          track_motorx_reverse off

          # Motor number for y-axis (default: 0)
          track_motory 0

          # Set motory reverse (default: off)
          track_motory_reverse off

          # Maximum value on x-axis (default: 0)
          track_maxx 0

          # Minimum value on x-axis (default: 0)
          track_minx 0

          # Maximum value on y-axis (default: 0)
          track_maxy 0

          # Minimum value on y-axis (default: 0)
          track_miny 0

          # Center value on x-axis (default: 0)
          track_homex 128

          # Center value on y-axis (default: 0)
          track_homey 128

          # ID of an iomojo camera if used (default: 0)
          track_iomojo_id 0

          # Angle in degrees the camera moves per step on the X-axis
          # with auto-track (default: 10)
          # Currently only used with pwc type cameras
          track_step_angle_x 10

          # Angle in degrees the camera moves per step on the Y-axis
          # with auto-track (default: 10)
          # Currently only used with pwc type cameras
          track_step_angle_y 10

          # Delay to wait for after tracking movement as number
          # of picture frames (default: 10)
          track_move_wait 10

          # Speed to set the motor to (stepper motor option) (default: 255)
          track_speed 255

          # Number of steps to make (stepper motor option) (default: 40)
          track_stepsize 40

          ############################################################
          # External Commands, Warnings and Logging:
          # You can use conversion specifiers for the on_xxxx commands
          # %Y = year, %m = month, %d = date,
          # %H = hour, %M = minute, %S = second,
          # %v = event, %q = frame number, %t = thread (camera) number,
          # %D = changed pixels, %N = noise level,
          # %i and %J = width and height of motion area,
          # %K and %L = X and Y coordinates of motion center
          # %C = value defined by text_event
          # %f = filename with full path
          # %n = number indicating filetype
          # Both %f and %n are only defined for on_picture_save,
          # on_movie_start and on_movie_end
          # Quotation marks round string are allowed.
          ############################################################

          # Do not sound beeps when detecting motion (default: on)
          # Note: Motion never beeps when running in daemon mode.
          quiet on

          # Command to be executed when an event starts. (default: none)
          # An event starts at first motion detected after a period of no motion defined by event_gap
          ; on_event_start value

          # Command to be executed when an event ends after a period of no motion
          # (default: none). The period of no motion is defined by option event_gap.
          ; on_event_end value

          # Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
          # To give the filename as an argument to a command append it with %f
          ; on_picture_save value

          # Command to be executed when a motion frame is detected (default: none)
          ; on_motion_detected value

          # Command to be executed when motion in a predefined area is detected
          # Check option ‘area_detect’. (default: none)
          ; on_area_detected value

          # Command to be executed when a movie file (.mpg|.avi) is created. (default: none)
          # To give the filename as an argument to a command append it with %f
          ; on_movie_start value

          # Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
          # To give the filename as an argument to a command append it with %f
          ; on_movie_end value

          # Command to be executed when a camera can’t be opened or if it is lost
          # NOTE: There is situations when motion don’t detect a lost camera!
          # It depends on the driver, some drivers dosn’t detect a lost camera at all
          # Some hangs the motion thread. Some even hangs the PC! (default: none)
          ; on_camera_lost value

          ############################################################
          # Common Options for database features.
          # Options require the database options to be active also.
          ############################################################

          # Log to the database when creating motion triggered image file (default: on)
          sql_log_picture on

          # Log to the database when creating a snapshot image file (default: on)
          sql_log_snapshot on

          # Log to the database when creating motion triggered movie file (default: off)
          sql_log_movie off

          # Log to the database when creating timelapse movie file (default: off)
          sql_log_timelapse off

          # SQL query string that is sent to the database
          # Use same conversion specifiers has for text features
          # Additional special conversion specifiers are
          # %n = the number representing the file_type
          # %f = filename with full path
          # Create tables :
          ##
          # Mysql
          # CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp(14), event_time_stamp timestamp(14));
          #
          # Postgresql
          # CREATE TABLE security (camera int, filename char(80) not null, frame int, file_type int, time_stamp timestamp without time zone, event_time_stamp timestamp without time zone);
          #
          # Default value:
          # insert into security(camera, filename, frame, file_type, time_stamp, text_event) values(‘%t’, ‘%f’, ‘%q’, ‘%n’, ‘%Y-%m-%d %T’, ‘%C’)
          sql_query sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values(‘%t’, ‘%f’, ‘%q’, ‘%n’, ‘%Y-%m-%d %T’, ‘%C’)

          ############################################################
          # Database Options
          ############################################################

          # database type : mysql, postgresql, sqlite3 (default : not defined)
          ; database_type value

          # database to log to (default: not defined)
          ; database_dbname value

          # The host on which the database is located (default: not defined)
          database_host localhost

          # User account name for database (default: not defined)
          ; database_user value

          # User password for database (default: not defined)
          ; database_password value

          # Port on which the database is located (default: not defined)
          # mysql 3306 , postgresql 5432 (default: not defined)
          database_port 0

          ############################################################
          # Video Loopback Device (vloopback project)
          ############################################################

          # Output images to a video4linux loopback device
          # The value ‘-‘ means next available (default: not defined)
          ; video_pipe value

          # Output motion images to a video4linux loopback device
          # The value ‘-‘ means next available (default: not defined)
          ; motion_video_pipe value

          ##############################################################
          # Thread config files – One for each camera.
          # Except if only one camera – You only need this config file.
          # If you have more than one camera you MUST define one thread
          # config file for each camera in addition to this config file.
          ##############################################################

          ; thread /usr/local/etc/thread1.conf

  19. I have a wifi network but no internet access in the Rpi. I installed the motion webserver. But there’s a problem with libjpeg62 and since I don’t have internet connection sudo apt-get install libjpeg62 is not working. So anyone share me the offline installer or pre compiled version of libjpeg62. It would be great help if you do asap

  20. Paul Ber says:

    I know motion uses a mini-http server how can I add to that web page? Where is the index?

  21. Paul Ber says:

    Cool.

    How would i take the video and have it part of a port 80 webpage?

    Right now I have it working for a Garage Door monitor/control, but the video only works on the local wifi network. When forwarding the video doesn’t show when check from mobile data.

  22. tyler says:

    i’ve been doing this project to make video stream with picam. i’ve found this page and it works properly, but the video is not going smoothly. i am wondering if it’s only my problem or not. how about you? is it working well?

  23. Anonymous says:

    Got it to work, but after reboot I need to reload the v4l2 driver again by typing “sudo modprobe bcm2835-v4l2” Anyone have the same problem?

  24. Geert says:

    Worked fine on Rpi1 running on Wheezy, but with a rpi2 running Jessie I got:
    “./motion: error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory” Then, trying to install libjpeg62, it said: “Note, selecting ‘libjpeg62-turbo’ instead of ‘libjpeg62′” and that was already installed/latest version. So I guess libjpeg62 was replaced in the Jessie distro by it ‘turbo’-version, but that doesn’t work quite the same….? Any ideas on this? Do I need a different build for Jessie?

  25. Tom says:

    I had an old pre Jessie raspian image which I used and it sorted me out but I’m sure it’s causing a lot of problems for people.

  26. Anonymous says:

    To disable camera led

    sudo nano /boot/config.txt

    Add the line

    disable_camera_led=1

  27. t.tutt says:

    this is killing me. I have downloaded the tar file. I entered in the tar line to unpack it and it says it is not in gzip format. I tried to unpack it through GUI Xarchiver and I get archive format is not recognized. what exactly is the trick to getting this unpacked?

    • t.tutt says:

      sorry. wrong version. i have tried this so many times that I got them mixed up. the archive mentioned in the post worked, and unpacked but gave me an error: “error while loading shared libraries: libavformat.so.53 cannot open shared object file: no such file or directory” I tried the build by lowflyerUK mentioned above, but that version will not unpack. perhaps it is best to just revert to wheezy. haven’t had this pi up for very long anyway so nothing to loose.

      BTW, this is so far the most current and helpful discussion on this issue I have found after lots of searching.

    • Anonymous says:

      finally got it working. I had to individually run down each missing package, but I had to try several times due to a wifi issue. don’t blame me, I just got used to linux “just working” as it usually does. I guess I got too comfortable with that.

      im sure i’ll be back when I try to get this thing to jump through some more difficult hoops.

  28. Mark Miller says:

    I am using RPi2 and the Raspberry Pi camera module (B) rev 2.0. I can not get it to run. When I enter ./motion -c motion-mmal.conf I get the following error “./motion: error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory”. I enter my RPi IP and 8081 and the page won’t open. Anybody have a solution? I am a newbie and am unfamiliar with how to recompile something, or edit this file or that so you know what level I am at. Thanks.

  29. Emperor Splang says:

    Look at December 26, 2015 at 10:33 post.

  30. Ronald says:

    can i insert capture video in a database ? please reply

  31. Cade says:

    after entering the line “sudo ./motion -c motion-mmalcam.conf” it basically says theres no suc file or derectory? anybody know what’s causing this? How to fix it?

  32. Anonymous says:

    I got the same thing I am not sure what is going on but try sudo apt-get upgrade and update

  33. Amin Mohd says:

    i have the same issue : error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory

  34. Is it possible to set motion to do a timelapse video saving frame every Nth second EXCEPT in the night? if yes, which have to be modified in .conf file?

  35. Excellent article. I’m going through many of these issues as well..

  36. mgarrow says:

    I was having issues like Amin and others with the libraries being screwed up. What I discovered was in my normal routine of cleaning the system, I apt-get autoremove~ed old files that the system thought weren’t needed. That removed the needed libraries.. The solution was to apt-get install motion > apt-get remove motion. That put the necessary libraries back in the system correctly. I hope this helps someone!

  37. Darbley Ale says:

    Per the problem videotester helped with above, the build and instructions given in his reply work on raspberry pi 3 too. Thanks!!

  38. oxize says:

    Didnt get it working properly. I am using Pikrellcam (more advanced stuff)

  39. eelcohoff says:

    I was confronted with the error “error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory” and found the solution here.

    Many other sites could not provide that. Finally got the cam working the way I want. Now up to a multicam version ;-)

    Tnx Videotester!

    • Hank says:

      I have the same error. Can you tell me where ‘here’ is for the solution.
      Thanks

    • Hank says:

      Please ignore my previous reply. I now see that the ‘here’ is Videotester. I tried it and it worked for me.
      Thanks,
      Hank

  40. Agan says:

    hello, Have a Nice day…
    I was curious with pan/tilt ini mmal cam.
    how you can use it?
    there is serial port of motor but i read serial can be use if you use USB… then how about use GPIO?
    here the code in mmal.cam I use and i didn’t know the program is not working (not the motion detection but motor tracking)
    I only use Pan not the tilt.
    and I use Continous servo MG955 pro

    ############################################################
    # Tracking (Pan/Tilt)
    ############################################################

    # Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo)
    # The generic type enables the definition of motion center and motion size to
    # be used with the conversion specifiers for options like on_motion_detected
    track_type 6

    # Enable auto tracking (default: off)
    track_auto on

    # Serial port of motor (default: none)
    ; track_port value #<==here I didn't understand.

    # Motor number for x-axis (default: 0)
    track_motorx 1

    # Set motorx reverse (default: off)
    track_motorx_reverse on

    # Motor number for y-axis (default: 0)
    track_motory 0

    # Set motory reverse (default: off)
    track_motory_reverse off

    # Maximum value on x-axis (default: 0)
    track_maxx 360

    # Minimum value on x-axis (default: 0)
    track_minx 1

    # Maximum value on y-axis (default: 0)
    track_maxy 0

    # Minimum value on y-axis (default: 0)
    track_miny 0

    # Center value on x-axis (default: 0)
    track_homex 128

    # Center value on y-axis (default: 0)
    track_homey 128

    # ID of an iomojo camera if used (default: 0)
    track_iomojo_id 0

    # Angle in degrees the camera moves per step on the X-axis
    # with auto-track (default: 10)
    # Currently only used with pwc type cameras
    track_step_angle_x 10

    # Angle in degrees the camera moves per step on the Y-axis
    # with auto-track (default: 10)
    # Currently only used with pwc type cameras
    track_step_angle_y 10

    # Delay to wait for after tracking movement as number
    # of picture frames (default: 10)
    track_move_wait 10

    # Speed to set the motor to (stepper motor option) (default: 255)
    track_speed 255

    # Number of steps to make (stepper motor option) (default: 40)
    track_stepsize 40

  41. guys, why is this happening. i only get black and blue images, blue when something is moving and black when stationary.

  42. Olli Raatikainen says:

    Works great :) However, why can’t I change the resolution of the images? I have the original (V1) rpi camera module. Resolutions above 640×480 cause segfault, when I start motion. The camera module officially has 640×480, 720p and even 1080p resolutions. Any clues on this?

  43. loxleybottom says:

    I followed this site but the installation fails due to dependencies that cannot be resolved if you try to install into Jessie. The following site has a specific section devoted to Jessie and it works!
    http://wiki.raspberrytorte.com/index.php?title=Motion_MMAL

  44. kam wan says:

    Excellent article , For what it’s worth , others require a TX Direct Deposit Sign-up & Change Form for Vendors , my family filled out a fillable form here https://goo.gl/RKPJwi

  45. abdul says:

    I just want to click an image from picamera….I m using ‘raspistill’ and then ‘raspistill -o imagename.jpg’ …my camera module’s red light is on but then there is an error called ‘mmal2 ….error’ …I updated and upgraded but still it is not working….what’s an issue??

  46. […] The following information is from this EmbeddedDay post: […]

  47. elwood says:

    Thank you video tester you are a genius. After many hours trying to resolve the libjpeg62 error. Your links worked perfectly out of the box. Thanks again

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: