Posts: 115
Joined: Fri May 04, 2012 4:33 pm

24/7 video recording - camera module

Thu Aug 07, 2014 12:33 pm


I'm looking to find the best way to have 24/7 recording (and possibly streaming) with the Camera Module.

Especially since the other night someone stole some stone flags from my neighbours yard I want to setup some video surveillance. Luckily I did have an RPi taking photos every minute so the thieves were caught on camera.

The new full FOV modes make things much better in terms of what I can see, that paired with a cheap wide-angle magnetic lens makes the FOV perfect.

I've currently got a very basic script to record 30 second clips to an SMB share which just loops.

I'm using a 512MB model B.

Current script:

Code: Select all


while true

curryear="`date +%Y`"
currmonth="`date +%Y-%m`"
currday="`date +%Y-%m-%d`"
currhour="`date +%H`"
unix="`date +%s`"

mkdir -p /mnt/server/rpivideo/$curryear/$currmonth/$currday/$currhour

/opt/vc/bin/raspivid -o /mnt/server/rpivideo/$curryear/$currmonth/$currday/$currhour/video-$unix.h264 -t 30000 -b 5000000 -w 1296 -h 976 -ex night

I've seen a few examples like here - ... _streaming - for streaming and recording.

My question is, whilst my script works it seems very crude, would anyone recommend a better method?

Also, there's been times where something has crashed causing the camera to not open giving the usual mmal errors requiring a reboot. I'd love to be able to avoid that if possible.

Avoiding gaps between clips would be great too but I realise that might not be totally possible.

Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: 24/7 video recording - camera module

Mon Aug 11, 2014 10:47 am

triplemdw wrote:Everything you need: ... 43&t=63276 ;)
I might be wrong but it doesn't really seem to fit my purpose after a quick play.

I will probably need to dig deeper.

User avatar
bugsy_malone 666
Posts: 289
Joined: Mon Dec 17, 2012 10:50 pm
Location: Basingstoke UK

Re: 24/7 video recording - camera module

Mon Aug 11, 2014 2:26 pm

Depending on how you want to go about it and what you wish to capture there are ways.

I had the situation that I needed a standalone CCTV camera that needed to operate 24/7 for upto a week without any intevention (where possible as it was mounted 20ft up) and basically I had the pi, camera module, a smartphone fisheye lense, in a security light housing running from solar/large batteries. I used 8gb cards which I would change once a week, resolution wasnt amazing but its the price you pay for getting 7 days of footage one an 8gb memory card.

I basically used the setup here:

The guy built a pi camcorder with 2 button operation, which is how I operate me CCTV, insert card turn it on, set it recording and leave for a week, come back shut down change the card and so on and so on.

He also said there was a way to web stream it but I havent looked into that yet.

Maybe some use? I used mine for 6 months clocking up some 40-50gb of video, like I said though the quality is not amazing, but i can be used to show you the problem and with different bitrates you may solve this at the cost of storage.

One thing I did find is under continuous use (with a few power failures due to no sun and lots of rain for long periods) the 8gb kingston cards I used lasted about 3 months use (1.5 months each) before getting data corruption.

Hope this helps.

Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: 24/7 video recording - camera module

Tue Aug 12, 2014 9:11 am

Thanks for the link.

SD Card corruption hopefully shouldn't be an issue because I'm writing directly to an SMB share over ethernet. I also do a nightly backup of the full system image in case of corruption since I have had it happen a few times in the past on other RPis. I've also killed dead at least 1 SD card!

These days, anything that needs a lot of file writes I put in /dev/shm

Posts: 31
Joined: Wed Oct 22, 2014 4:03 am

Re: 24/7 video recording - camera module

Sun Mar 08, 2015 10:15 pm

Install UV4L drivers and then do the following:

Code: Select all

Steps to upgrade cameras:
sudo apt-get remove uv4l-server -y
sudo apt-get update 
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo rpi-update
sudo apt-get install vlc -y

sudo nano /etc/uv4l/uv4l-raspicam.conf
Add the following:
width = 1280
height = 720
#framerate = 10
inline-headers = yes
quantisation-parameter = 30

Add the following:
#! /bin/bash
# This script starts the camera streaming

#Start the uv4l driver - not needed if you edited /etc/uv4l/uv4l-raspicam.conf
#sudo uv4l --sched-rr --driver raspicam --auto-video_nr --framerate 10 --encoding h264 --width 1296 --height 976  --rotation 180

#v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=H264 -d /dev/video0

LD_PRELOAD='' cvlc v4l2:///dev/video0 --v4l2-width 1280 --v4l2-height 720 --v4l2-chroma h264 --sout '#rtp{sdp=rtsp://:8554/}'

chmod +x

sudo nano /etc/init.d/camera
Add the following:
# /etc/init.d/camera

# Provides:          camera
# Required-Start:    $networking $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This service is used to manage a camera stream

case "$1" in 
        echo "Starting camera"
        sudo su - pi /home/pi/
        echo "Stopping camera"
        echo "Usage: /etc/init.d/camera start|stop"
        exit 1

exit 0

sudo chmod +x /etc/init.d/camera
sudo update-rc.d camera defaults
sudo reboot

Add the camera to the server:
on sauron@watcher
nano ~/
Add the following
avconv -i rtsp://192.168.1.XXX:8554/ -acodec copy -vcodec copy -map 0 -f segment -segment_time 3600 -segment_format mp4 -crf 22.0  "/events/video/CameraName/`date +%Y-%m-%d-%H-%M-%S`-capture-%03d.mp4" &

You'll have to mod the IP, output folders, etc to suit your needs. I'm able to get 14 Rpi cameras recording 24/7, 1280x720@30fps using minimal resources. The movies are 1hr long, open in totem with no problem, and take up variable amounts of disk space depending upon how much movement is in the video, colors, etc. Change the quantisation parameter to lower numbers for higher quality but at the price of disk space. Currently it takes about 50-200Mb/hr.

Also, a lot of people here don't understand that mjpeg will fill your hard drive in no time and will saturate a 100mbps LAN with only a few cameras. Most of the posts here deal with one camera, low resolution, mtion detection, etc. Not 24x7, high res, etc.

Posts: 1
Joined: Sun Feb 19, 2017 12:09 am

Re: 24/7 video recording - camera module

Sun Feb 19, 2017 3:59 pm

Hello Whytehorse,

i followed your guide, but to me it's not clear if you talk about two Raspberrys here, one with a camera that is streaming the video and one that receives the stream and records it to a locally attached drive.

When you say "Add the camera to the server", is this supposed to be on a second raspberry?
What does "on sauron@watcher" mean?

Which IP-address am i supposed to insert at "avconv -i rtsp://192.168.1.XXX:8554/"? I guess the code is supposed to be added to the receiving server and the IP is the one of the streaming Raspberry?

How would i have to setup the receiving server?
How would i start and stop the camera?


Return to “Graphics, sound and multimedia”