Skip to content

This software will turn a raspberry pi with USB camera into a Homekit security camera

Notifications You must be signed in to change notification settings

camow7/rpi-homekit-cam

Repository files navigation

rpi-homekit-cam

This software will turn a raspberry pi with USB camera into a Homekit security camera

Setup Dependencies

Follow these steps to setup the pi:

  1. Make sure python is installed and git
  2. Git clone this repo
  3. install kernel headers - sudo apt install raspberrypi-kernel-headers
  4. 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.
  5. Install Python HAP deps - sudo apt-get install libavahi-compat-libdnssd-dev and pip install HAP-python[QRCode]. Had trouble with the cryptography wheel and needed to install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh and libssl-dev.
  6. install FFMPEG - sudo apt install -y ffmpeg (Issue)
  7. Install v4l2 for video loop back - sudo apt-get install v4l2loopback-dkms and sudo apt-get install v4l-utils
  8. enable at boot - /etc/modules-load.d/v4l2loopback.conf and add v4l2loopback
  9. Complete Copying Camera Stream
  10. cd into repo folder
  11. install python deps. - pip install -r requirements.txt

Run

  1. sudo modprobe v4l2loopback video_nr=99,100
  2. ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -f v4l2 /dev/video100
  3. open second terminal and cd into git repo then run python3 ./main.py

Creating Extra Video Streams

  1. sudo nano /etc/modprobe.d/v4l2loopback.conf
  2. Add this so it creates extra video devices on boot options v4l2loopback video_nr=99,100

Setup FFMPEG Service

sudo cp camow7_ffmpeg.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable camow7_ffmpeg.service
sudo systemctl start camow7_ffmpeg.service

Setup Camera 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

Installing Requirements

pip install -r requirements.txt

Copying Camera Stream

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

Troubleshooting

ffmpeg with bookworm

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

About

This software will turn a raspberry pi with USB camera into a Homekit security camera

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages