- Version: 20261019
- Source Code Copyright: Unknown
- Bundled FFmpeg 4.3.1 Windows build (bin/ffmpeg-4.3.1-win64-static-lgpl): GNU Lesser General Public License v3.0 (LGPL-3.0).
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Console/terminal network video recorder (NVR) demo for Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon; OpenCV backend only): records a webcam continuously into fixed-length segments named model/video/YYYY-MM-DD/YYYY-MM-DD-HH-MM-SS.flv, while a background thread deletes day folders older than the retention period (30 days by default). Stop recording with Ctrl+C. CPU only: the pip opencv-python build has no GPU backend (no CUDA, no Apple GPU), and both backends encode the FLV1 codec on the CPU.
Two backends: OpenCV (video only, timestamp burned into every frame, 1-minute segments) and FFmpeg (video + microphone audio, or video only with --no-audio; 10-minute segments). On Windows the FFmpeg backend uses the bundled bin/ffmpeg-4.3.1-win64-static-lgpl; on Linux it uses the system ffmpeg. The OpenCV backend runs on Windows, Linux and macOS; the FFmpeg backend on Windows and Linux only.
[Folder Structure]
- CLAUDE.md / AGENTS.md: Program specification (identical content).
- CHANGELOG.md: Change log.
- copyright.txt: Copyright notice.
- NVR-Python.html: This document (usage page).
- bin/ffmpeg-4.3.1-win64-static-lgpl/: Bundled Windows FFmpeg (LGPL build).
- model/video/: Recordings: one folder per day, one file per segment.
- tool/tools.py: Shared helpers.
- src/: The recorders and launcher scripts.
- venv/: Python virtual environment, created by 02_venv_create_windows/linux/mac.
[Prerequisites]
- Python 3.14, installed by 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh (Windows: winget; Ubuntu: apt, or the deadsnakes PPA when the Ubuntu archive has no python3.14; macOS: Homebrew), and a webcam.
- 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh create venv/ with Python 3.14 and install numpy and opencv-python from src/requirements.txt (same packages on every OS). Windows needs nothing else (bundled FFmpeg); Ubuntu needs sudo apt install ffmpeg for the FFmpeg backend; on macOS the terminal app must be allowed to use the camera (System Settings → Privacy & Security → Camera).
- GPU: none. CPU only on every OS, because the pip opencv-python build has no GPU backend and the FLV1 encoding runs on the CPU; no NVIDIA driver or CUDA is needed.
[Launcher Scripts]
1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh
Install Python 3.14 (winget / apt or deadsnakes PPA, needs sudo / Homebrew). Skips the install when Python 3.14 is already present. On Windows, open a new terminal afterwards.
2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh
Delete the old venv/, create a fresh one with Python 3.14, install src/requirements.txt (numpy, opencv-python). Aborts loudly if pip fails.
3. 03_venv_activate.bat / 03_venv_activate.sh
Activate the venv. On Linux/macOS, source it: source src/03_venv_activate.sh (bash or zsh). If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.
4. 04_record_opencv.bat / 04_record_opencv.sh
Record with OpenCV (video only, 1-minute segments).
5. 05_record_ffmpeg.bat / 05_record_ffmpeg.sh / — (not supported)
Record with FFmpeg (video + audio, 10-minute segments).
6. 06_record_ffmpeg_no_audio.bat / 06_record_ffmpeg_no_audio.sh / — (not supported)
Record with FFmpeg, video only.
7. 99_venv_clean.bat / 99_venv_clean.sh
Delete the venv/ folder.
8. 99_venv_deactivate.bat / 99_venv_deactivate.sh
Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).
[Python Entry Points]
src/recorder_opencv.py
[--camera 0] [--width 1280] [--height 720] [--in-fps 10] [--out-fps 10] [--segment-minutes 1] [--extension flv] [--output-dir DIR] [--retention-days 30] [--cleanup-interval 86400] [--show]. Captures at --in-fps, records every in-fps/out-fps-th frame with the FLV1 codec, and overlays the current time in green. --show opens a live preview (press q to stop); without it, recording is fully headless. Runs on Windows (DirectShow), Linux (V4L2) and macOS (AVFoundation).
src/recorder_ffmpeg.py
[--list-devices] [--camera 0] [--audio 0] [--no-audio] [--record-time 00:10:00] [--frame-size 1280x720] [--fps 30] [--extension flv] [--output-dir DIR] [--retention-days 30] [--cleanup-interval 86400]. --list-devices prints the available cameras and microphones and exits. Audio is encoded with AAC; --no-audio records video only. Windows and Linux only.
Both recorders run on the CPU (no GPU backend in OpenCV's pip build or in the FLV1 encoder); there is no --device option.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
REM open a new terminal
src\02_venv_create_windows.bat
src\04_record_opencv.bat
Ubuntu 24.04
bash src/01_python_install_linux.sh
sudo apt install ffmpeg
bash src/02_venv_create_linux.sh
bash src/04_record_opencv.sh
macOS 14+ (Apple Silicon; OpenCV backend only)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/04_record_opencv.sh
FFmpeg backend, and listing the capture devices (Windows/Linux):
bash src/05_record_ffmpeg.sh
bash src/06_record_ffmpeg_no_audio.sh
bash src/05_record_ffmpeg.sh --list-devices
[Notes]
- Recordings accumulate quickly — the retention thread keeps only the last 30 days (--retention-days); folders in model/video/ whose names are not dates are never touched.
- The OpenCV backend needs no FFmpeg at all; the FFmpeg backend needs no Python packages beyond the standard library.
- macOS: only the OpenCV backend is supported; 05_record_ffmpeg.sh / 06_record_ffmpeg_no_audio.sh exit with a hint to use 04_record_opencv.sh.
- If FFmpeg stops with an error right away, the camera may not support the requested --frame-size / --fps; pass values the camera offers.
[References]
- FFmpeg: ffmpeg.org
This SDK is built in AppForAI - AI Dev Tools.