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 :
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. Expand the file system and Enable the Pi Camera using the config tool :
Ensure you’ve got the latest firmware using :
Create a new directory and navigate into it :
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.
Then finally install MP4Box (aka gpac) which can be used to convert the h264 files recorded by the camera to slightly more usable MP4 files :
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
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”.
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 :
and set the VIDEO_PATH parameter in the config.py file to point 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 click “CTRL-X”, then “Y” and finally “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.