Simple Raspberry Pi webcam monitoring. It records before and after detecting movement, then combines the clips into continuous daily recordings. Ideal for indoor motion detection.
- Motion-triggered recording
- Pre-motion recording buffer
- Lossless video merging
- Automatic systemd setup
Requirements:
- sudo privileges
- python >= 3.10
- python-dotenv
- opencv-python
- ffmpeg
- V4L2 compatible camera
PROJECT_PATH/
├── merged/
│ ├── merged_2026-08-20.mp4
│ ├── merged_2026-08-21.mp4
│ └── ...
├── recordings/
│ ├── .tmp/
│ │ ├── rec_2026-08-22_12-15-23.mp4
│ │ └── ...
│ ├── rec_2026-08-22_12-12-34.mp4
│ ├── rec_2026-08-22_12-12-59.mp4
│ └── ...
└── logs/
Install requirements: python, ffmpeg and v4l-utils
sudo apt install python3 python3-pip ffmpeg v4l-utilsClone repository
git clone https://github.com/aasiop/rpi-motion-camera.gitEnter repository
cd rpi-motion-cameraInstall requirements: python libraries
pip install -r requirements.txt --break-system-packagesCreate your configuration file:
cp .env.example .envChange permissions:
chmod 600 .envEdit the configuration:
nano .envSet up systemd autostart
sudo python3 setup_autostart.pySetup file merge using crontab
python3 setup_merging_time.pyCreate a .env file from .env.example.
Example:
PROJECT_PATH = /mnt/camera
TEMP_DIR = /tmp/merge
RESOLUTION_X = 1920
RESOLUTION_Y = 1080
SENSITIVITY = 65
BUFFER_TIME = 4
AFTER_DETECTION_TIME = 8
MERGE_TIME = 6:00| Variable | Description |
|---|---|
PROJECT_PATH |
Path to store recordings |
TEMP_DIR |
Directory where files are temporary merged |
RESOLUTION_X |
Screen width |
RESOLUTION_Y |
Screen height |
SENSITIVITY |
Higher value = less sensitive motion detection |
BUFFER_TIME |
Seconds recorded before motion detection |
AFTER_DETECTION_TIME |
Seconds recorded after motion stops |
MERGE_TIME |
Daily merge time (24h format) |
WARNING: Recording FPS is not configurable. It depends on your Raspberry Pi's processing performance, camera and selected resolution. Higher resolutions increase CPU usage and may reduce the achievable FPS.
Check program status:
sudo systemctl status rpi-motion-camera.serviceStop program:
sudo systemctl stop rpi-motion-camera.serviceStart program:
sudo systemctl start rpi-motion-camera.serviceDisable autostart:
sudo systemctl disable rpi-motion-camera.serviceEnable autostart:
sudo systemctl enable rpi-motion-camera.serviceStop and remove systemd service:
sudo systemctl stop rpi-motion-camera.service && \
sudo systemctl disable rpi-motion-camera.service && \
sudo rm /etc/systemd/system/rpi-motion-camera.service && \
sudo systemctl daemon-reloadEnter cronjob:
crontab -eRemove line with merge.py:
0 6 * * * /usr/bin/python3 /path/to/merge.py >> /path/to/logs.log 2>&1
Then delete the remaining files in rpi-motion-camera and recordings folder
This project is licensed under the MIT License.