Raspberry Pi is a low-cost micro-computer that is able to run Linux and has endless extension possibilities then can be also used for network video recorder (NVR) to records video in a digital format to a disk driveUSB flash drive, SD memory card or other mass storage device.

This post will guide you through the process of setting up your Raspberry Pi as a Network video recorder (NVR).

Requirements

You are going to need the following:

  • A Raspberry Pi
  • An Internet connection
  • An SD Card flashed with Raspbian OS (> 8 Gb)
  • IP or Analog camera with mjpeg streaming support or USB Camera (If you want record from Raspberry’s camera module, Please visit “Raspberry Pi as low-cost HD surveillance camera“)

Update the Raspberry Pi

Before continue make sure all packages, firmware, and kernel is up to date

–  Run the following commands:

  • Update Packages
  •  Update Firmware
Make sure there are no error while updating the firmware or kernel

Install Motion

In order for the Raspberry Pi to act as a network video recording you need to install packages on the Raspberry. You are going to need the following packages

  • motion
    Motion is a program that monitors the video signal from one or more cameras and is able to detect if a significant part of the picture has changed; in other words, it can detect motion.

To install the motion packages run following command:

If there are no error at installation you can continue to the next step.

Configure the Motion

To configure the motion, make sure backup the file first then you can open file called /etc/motion/motion.conf edit this file or open it using this command:

The configuration

The configuration is summarized, some configuration is not showed

Motion Configuration version 3.2.12

#########################

Run as daemon in the background

This is are the pid (Process Identifier) // Change it to /home/pi/process/motion.pid to avoid permissions problems

This is are location of the videodevice // add comment for IP Camera

Change to your videodevice mode

This used for USB Camera and other plugged to Pi camera

This used only for video capture or TV tuner cards (not used for IP Camera)

This used only for TV tuner cards

Change it if you want use custom rotation degrees

Change it to your camera pixel width

Change it to your camera pixel height

Frame rate is the Frame per second of the recorded video from camera (high frame rate mean high CPU usage)

This will limit frame per seconds of the capturing images

This is are the URL of the IP camera e.g : http://192.168.1.150/video.mjpg

This is are the username and password to login to your IP Camera e.g : admin:password

This is are the http version of your IP Camera , you can check by doing curl –head url

This is are threshold for motion detection (high number = high sensitivity)

This is are the video duration split before the movie is encoded to files (3600 Recommended)

It will save image even no motion detected (turn it on if you want save the images per-frames and video even no motion detected)

This will encode mpeg movies from the camera e.g 01-20140330-09-01-06.avi

The quality of movie encoding (highest = high quality but takes more CPU load)

I recommend the default value (it will depends on ffmpeg_bps).

I’m currently using msmpeg4 format because it’s almost multi-supported almost all platform

This is are where location the images or movies will be saved

After you finish the editing make sure you save the files

Now we need to add the process PID and Video folder with (rwxrwxrwx) permissions to avoid motion bug on creating files and PID:

  • Create Pid folder
  •  Create Video folder (change the folder to yours)

Start Motion

Now you can test motion by start motion service , you can do so by running :

After you running the motion then there are no problem you can turn on daemon to on (run automatically at startup)

Extra Scripts

This is are extra scripts list for Raspberry as NVR to ensure working as NVR properly

Remove Old Videos After x Days

Change /path/to/files to your file path and +5 it will find files older than 5 days or how long the video is saved then will deleted:

Then add an extra line with the configuration of cron scheduler:

Save videos on Windows shared folder (optional)

Raspberry can store the videos on the Windows shared folder , you can follow this steps:

Then add an extra line with the configuration of your Windows network shared folder:

Be sure that the user has the correct permissions to save files to that shared folder. After a reboot, the Raspberry should have an extra folder /mnt/camshare mounted to the Windows shared folder. You should now set in your motion.conf:

so that motion saves all movies to the shared folder on the Windows machine.

Extra Links

Troubleshooting

– Playback issues or freezing

  • Play the video with KMPlayer or another video player.
  • View the file size or diagnose the motion log file.

– Motion disconnect the IP Camera or Endpoint error

  • Use HTTP 1.0 instead of HTTP 1.1.
  • Try change netcam_tolerant_check to on.

Read also

  1. Motion’s Wiki
  2. Raspberry Pi as low-cost HD surveillance camera
  3. How Can I keep My Raspbian “Wheezy” Up to Date? – István Simon‘s answer
  4. Image – Source: adafruit.com