This software will turn a raspberry pi with USB camera into a Homekit security camera
Follow these steps to setup the pi:
- Make sure python is installed and git
- Git clone this repo
- install kernel headers -
sudo apt install raspberrypi-kernel-headers
- Install OpenCV for python -
sudo apt install python3-opencv
. I don't have this in my pip requirements as I have the "wheel" fails often. - Install Python HAP deps -
sudo apt-get install libavahi-compat-libdnssd-dev
andpip install HAP-python[QRCode]
. Had trouble with thecryptography
wheel and needed to install Rustcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
andlibssl-dev
. - install FFMPEG -
sudo apt install -y ffmpeg
(Issue) - Install v4l2 for video loop back -
sudo apt-get install v4l2loopback-dkms
andsudo apt-get install v4l-utils
- enable at boot -
/etc/modules-load.d/v4l2loopback.conf
and addv4l2loopback
- Complete Copying Camera Stream
- cd into repo folder
- install python deps. -
pip install -r requirements.txt
sudo modprobe v4l2loopback video_nr=99,100
ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -f v4l2 /dev/video100
- open second terminal and cd into git repo then run
python3 ./main.py
sudo nano /etc/modprobe.d/v4l2loopback.conf
- Add this so it creates extra video devices on boot
options v4l2loopback video_nr=99,100
sudo cp camow7_ffmpeg.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable camow7_ffmpeg.service
sudo systemctl start camow7_ffmpeg.service
First open the camera.service
file and make sure the path to main.py
is correct for your system. Then run the command below.
sudo cp camera.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable camera.service
sudo systemctl start camera.service
pip install -r requirements.txt
To allow openCV to access the camera feed for motion while also allowing the HAP library to stream the camera we need to use ffmpeg to copy the video to a seperate file:
ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -f v4l2 /dev/video100
If you want to copy it to multiple video device use
ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -map 0 -f v4l2 /dev/video99 -vcodec copy -map 0 -f v4l2 /dev/video100
cat << '_EOF_' > /etc/apt/preferences.d/dietpi-ffmpeg
Package: ffmpeg* libav* libpostproc* libsw*
Pin: origin archive.raspberrypi.org
Pin-Priority: -1
_EOF_
apt update
apt install ffmpeg
ffmpeg -version