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 drive, USB 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
sudo apt-get update sudo apt-get upgrade
- Update Firmware
sudo rpi-update sudo ldconfig sudo rebootMake 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.
sudo apt-get update sudo apt-get install motionIf 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:sudo nano /etc/motion/motion.conf
The configuration
The configuration is summarized, some configuration is not showed Motion Configuration version 3.2.12 ######################### Run as daemon in the backgrounddaemon offThis is are the pid (Process Identifier) // Change it to /home/pi/process/motion.pid to avoid permissions problems
process_id_file /var/run/motion/motion.pidThis is are location of the videodevice // add comment for IP Camera
videodevice /dev/video0Change to your videodevice mode
v4l2_palette 8This used for USB Camera and other plugged to Pi camera
input 8This used only for video capture or TV tuner cards (not used for IP Camera)
norm 0This used only for TV tuner cards
frequency 0Change it if you want use custom rotation degrees
rotate 0Change it to your camera pixel width
width 320Change it to your camera pixel height
height 240Frame rate is the Frame per second of the recorded video from camera (high frame rate mean high CPU usage)
framerate 2This will limit frame per seconds of the capturing images
minimum_frame_time 0This is are the URL of the IP camera e.g : http://192.168.1.150/video.mjpg
; netcam_url valueThis is are the username and password to login to your IP Camera e.g : admin:password
; netcam_userpass valueThis is are the http version of your IP Camera , you can check by doing curl --head url
; netcam_http 1.0This is are threshold for motion detection (high number = high sensitivity)
threshold 1500This is are the video duration split before the movie is encoded to files (3600 Recommended)
max_mpeg_time 0It will save image even no motion detected (turn it on if you want save the images per-frames and video even no motion detected)
output_all offThis will encode mpeg movies from the camera e.g 01-20140330-09-01-06.avi
ffmpeg_cap_new onThe quality of movie encoding (highest = high quality but takes more CPU load)
ffmpeg_bps 500000I recommend the default value (it will depends on ffmpeg_bps).
ffmpeg_variable_bitrate 0I'm currently using msmpeg4 format because it's almost multi-supported almost all platform
ffmpeg_video_codec msmpeg4This is are where location the images or movies will be saved
target_dir /tmp/motionAfter 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
cd /home/pi/ mkdir process cd process mkdir motion
- Create Video folder (change the folder to yours)
cd /home/pi mkdir Video cd Video mkdir motion
Start Motion
Now you can test motion by start motion service , you can do so by running :motionAfter you running the motion then there are no problem you can turn on daemon to on (run automatically at startup)
sudo nano /etc/default/motion start_motion_enable=yes
Extra Scripts
This is are extra scripts list for Raspberry as NVR to ensure working as NVR properlyRemove 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:cd /home/pi mkdir jobs cd jobs echo 'find /path/to/folder* -mtime +5 -exec rm {} \;' > cleanup.sh crontab -eThen add an extra line with the configuration of cron scheduler:
0 0 */1 * * /home/pi/jobs/cleanup.sh
Save videos on Windows shared folder (optional)
Raspberry can store the videos on the Windows shared folder , you can follow this steps:sudo nano /etc/fstabThen add an extra line with the configuration of your Windows network shared folder:
//YOURSERVERNAME/YOURSHAREDFOLDERNAME /mnt/camshare cifs username=YOURSHAREDFOLDERUSERNAME,password=YOURSHAREDFOLDERPASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0Be 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:
target_dir /mnt/camshareso 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.
- Use HTTP 1.0 instead of HTTP 1.1.
- Try change netcam_tolerant_check to on.
please guide on how to add ip camera to videodevice /dev/video0
ReplyDeleteThat would be great! Also looking for this solution.
DeleteIn an IP framework, there is no confinement as to where an IP camera can be introduced. Furthermore, they can give more elevated amount of joining with other equipment, which helps in the constant improvement of the framework. An incorporated IP framework empowers multiple applications all the while, for example, get to control, purpose of offers framework and so forth.
ReplyDeletewarehouse network camera installation
I want to use a Raspi 3 as a DVR running the Xeoma platform that also is available for Pi. But I want to find out how many cameras that the Pi 3 can handle if used for continuous watching in a shop. They want to have 3 ip cameras and the Xeoma show all three at the same time. Is this possible?
ReplyDeletecctv camera wholesale dealers in mumbai | cctv camera wholesale market in mumbai | cctv camera service provider in mumbai | cctv camera service provider in navi mumbai | cctv camera company in mumbai | cctv camera supplier in mumbai |
ReplyDeleteLook at the lower left corner of the video to see the ghost. A person died in that parking lot 1 month before from a gunshot wound.Hiksion Deep Learning NVR
ReplyDeletecctv camera dubai, a complete security solution providing company in IP Surveillance Products, and a service provider we are not only for enterprise but also individual retail segment customers. Please visit more details security camera in uae
ReplyDeleteI can see that you a an expert at ur field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. security camera system
ReplyDeletethis reminds me of university project, how difficult it was. but it was fun to do. cctv wholesale in melbourne
ReplyDelete