Following on from Part 1 I’ll explain how you can install the Python software and get your own Video Capture Unit up and running.
You don’t need to build your unit in exactly the same way as mine but as a minimum you need :
- Raspberry Pi
- SD card with Raspbian
- Camera module
- 5V power supply
- 1 LED attached to GPIO4 via current limiting resistor (ie 330 ohm)
- 1 Switch attached to GPIO7 with 10K pull-down to ground
If you want to be able to easily transfer video files to a PC you might also want to use a :
- USB Flash Drive (8GB+)
The setup might be spread over a desk or installed in raspberry pi case. The choice is yours.
The software is available from the RPiSpy Video Capture Unit BitBucket repository and consists of the following main files :
This file contain the user defined settings used by vcu.py. It allows the user to adjust various parameters. If “/boot/vcu_config.py” exists it is copied over this config file. The vcu_config.py can be used to edit settings on a Windows PC which can see the /boot/ partition on the SD card.
This script is run when the Pi boots. It looks for a network connection and only runs vcu.py if it doesn’t find one. This allows the Pi to boot normally when you have connected it to your network to copy video files.
Summary of these installation instructions for reference.
This script provides an easy way to convert the recorded h264 files to MP4 files. It may take a while to convert depending on the total duration of the videos. It uses MP4Box and is meant to run via Windows.
This script provides an easy way to convert the recorded h264 files to MP4 files. It may take a while to convert depending on the total duration of the videos. It uses MP4Box and is meant to run on the Pi itself.
This is the main Python script which does most of the work. It is called from cron.py when the Pi boots.
First prepare a fresh SD card with Raspbian. Use a recent download from the official RaspberryPi.org site. Why Raspbian? I use it for everything!
Power up the Pi and login. You will now be in the home directory. Run the Pi configuration tool :
Expand the file system, Enable the Pi Camera and under Boot Options select “Console Auto Login”. Now reboot using:
As this will allow the file system to expand and configure the auto-login.
Create a new directory and navigate into it :
mkdir rpispy_vcu cd rpispy_vcu
Now we can download the archive file from BitBucket using :
If you type ls you should see the master.tar.gz file sitting in the current directory. Use the following command to extract the files from the archive :
tar -xvf master.tar.gz --strip 1
Typing ls should show you a list of the files :
You can remove the archive now using :
The Python scripts control the Raspberry Pi Camera Module using the Picamera module. This is installed by default on the latest version of Raspbian but if you are using the “Lite” version you will have to install it. Start by updating your list of packages using :
sudo apt-get update sudo apt-get upgrade
then install using :
sudo apt-get -y install python-picamera
To convert the camera’s h264 files to MP4 files we can use MP4Box (aka gpac). To install this utility start by updating your list of packages using:
sudo apt-get -y install gpac
Config File Setup (optional)
If you want to be able to edit the config file in Windows you will need to place a copy in the /boot/ directory. You can do that using :
sudo cp config.py /boot/vcu_config.py
When the cron.py script runs at boot time it will check if there is a vcu_config.py file in /boot/. If there is it copies it over config.py. The main script would then run and use the new settings.
USB Flash Drive Setup (optional)
In order to save our video files to a removable drive we need to get the Pi to automatically mount the USB flash drive. This is a fairly easy process and is described in my How To Mount A USB Flash Disk On The Raspberry Pi tutorial. Follow the tutorial so that your drive is mounted as “/media/usb”.
Ensure the VIDEO_PATH parameter in the config.py file points to ‘/media/usb/’. Don’t forget to update /boot/vcu_config.py if you are using that file.
If you don’t want to use a USB flash drive and you want to store videos on your SD card you will need to make a directory :
Ensure the VIDEO_PATH parameter in the config.py file points to ‘/home/pi//rpispy_vcu/videos/’. Don’t forget to update /boot/vcu_config.py if you are using that file.
Autorun On Boot Setup
To run the script automatically when the Pi boots you can use ‘cron’. To edit it we use the command :
sudo crontab -e
Using your cursor keys scroll to the bottom and add the following line :
@reboot python /home/pi/rpispy_vcu/cron.py &
Make sure you get this line correct as the script will fail to run on boot if there are any mistakes. Note that it ends in an ampersand symbol.
To save these changes type “CTRL-X”, then press “Y” and “Return”. You should now be back at the command prompt.
Shutdown your Pi and remove the power. Disconnect your network cable. Reconnect the power and boot the Pi. The Pi will boot and you will hear the buzzer sound once. The camera is now recording!
When you want to stop recording hold down the button until you hear a double beep from the buzzer. The Pi will shutdown. Wait 10 seconds before removing the power cable.
In part 3 I will cover converting the resulting video files into MP4 files which makes them easier to play in a media player or editing application.