GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sinhsac/my-cam-control: Python RTSP IP camera control & EZVIZ LAN discovery worker with MySQL action queue, FFmpeg frame validation, and H.264/H.265 timelapse video recording.

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
.gitignore
.gitignore
 
 
CamHelper.py
CamHelper.py
 
 
DbHelper.py
DbHelper.py
 
 
EzvizCam.py
EzvizCam.py
 
 
FrameHelper.py
FrameHelper.py
 
 
IPHelper.py
IPHelper.py
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SysConfig.py
SysConfig.py
 
 
common.py
common.py
 
 
db.sample.txt
db.sample.txt
 
 
db.sql
db.sql
 
 
main.py
main.py
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

My Cam Control

License: MIT Python FFmpeg MySQL

A Python automation toolkit for EZVIZ and RTSP IP camera discovery, MySQL-backed camera control, frame quality validation, and FFmpeg timelapse video recording. It scans local networks for RTSP cameras, synchronizes IP/MAC inventory to MySQL, processes queued camera actions, and provides a resilient timelapse worker with sharpness-based frame selection and disk space management.


Key Features

  • Fast LAN Camera Discovery & ARP Mapping: Concurrently scans a local IPv4 subnet (default 192.168.1.0/24) on RTSP port 554 using ThreadPoolExecutor, resolves MAC addresses via the OS ARP table (arp -a), and caches results for 1 hour.
  • MySQL Camera Inventory & Action Queue: Automatically upserts discovered cameras (ip_address, ip_type, mac_address) into xcam_cameras and polls xcam_actions for pending jobs, updating status transitions (pending → in_progress → done / failed).
  • RTSP Stream Testing & Resilient Frame Capture: Verifies RTSP stream health via FFmpeg (test_rtsp_connection) and captures frames with automatic retries across three fallback FFmpeg strategies (TCP MJPEG, UDP MJPEG, and TCP +genpts / yuv420p).
  • Automated Frame Validation & Sharpness Selection: Validates captured frames for file size, minimum dimensions, and grayscale brightness using Pillow, and selects the sharpest frame from multi-shot bursts via NumPy gradient variance.
  • FFmpeg Timelapse Worker (TimelapseWorker): Records interval snapshots at configurable resolutions (480p, 720p, 1080p), maintains rolling frame backups, monitors free disk space, and compiles continuous frame sequences into MP4 videos using libx264 (h264) or libx265 (h265) with +faststart.

Tech Stack & Project Structure

  • Language: Python 3
  • Media Processing: FFmpeg (CLI via subprocess)
  • Database: MySQL (mysql-connector-python)
  • Imaging & Networking: Pillow (PIL), NumPy, requests, standard library (socket, ipaddress, concurrent.futures)
my-cam-control/
├── main.py             # Main worker loop: camera discovery sync + MySQL action polling
├── CamHelper.py        # RTSP URL builder, connectivity tests, multi-strategy frame capture & validation
├── EzvizCam.py         # TimelapseWorker class for scheduled capture, disk checks & MP4 encoding
├── IPHelper.py         # Concurrent subnet port 554 scanner, EZVIZ HTTP check & ARP MAC resolver
├── DbHelper.py         # MySQL wrapper with CRUD, batch upserts, and schema/action constants
├── FrameHelper.py      # Session frame cleanup and rolling backup retention (latest 100 backups)
├── SysConfig.py        # Loader/writer for MySQL connection settings (sys_config.json)
├── common.py           # ~/.mycamcontrol workspace setup, logging, status/config JSON & frame renumbering
├── db.sql              # MySQL schema for xcam_actions and xcam_cameras tables
├── db.sample.txt       # Example DbHelper CRUD usage snippets
└── requirements.txt    # Python dependencies

At runtime, common.py initializes a working directory at ~/.mycamcontrol/:

~/.mycamcontrol/
├── config/
│   ├── sys_config.json # MySQL connection settings
│   ├── cam_info.json   # Cached LAN camera discovery results
│   ├── config.json     # TimelapseWorker settings (RTSP URL, FPS, codec, quality, interval)
│   └── control.json    # TimelapseWorker runtime control state (start/stop, current_video, processing)
├── frames/             # Active session JPEG frames (frame_000001.jpg, ...)
├── backups/            # Rolling backup frames (up to 100 kept)
├── videos/             # Rendered MP4 timelapse videos
└── logs/
    └── app.log         # Application log file

Prerequisites

  • Python 3.10+ (compatible with numpy~=2.3.2, pillow~=11.3.0, requests~=2.32.5)
  • FFmpeg installed and available in your system PATH
  • MySQL 8.0+ (or compatible InnoDB server)
  • arp command-line utility available on the host OS for IP-to-MAC resolution

Getting Started

1. Clone and Install Dependencies

git clone https://github.com/sinhsac/my-cam-control.git
cd my-cam-control
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

2. Initialize the MySQL Database

Create a database and import the schema from db.sql:

mysql -u <user> -p <database_name> < db.sql

This creates two tables:

  • xcam_cameras: stores discovered cameras (ip_address, cam_name, mac_address, ip_type, username, password, channel, status, timestamps).
  • xcam_actions: stores queued camera commands (command, additions JSON payload, status, timestamps).

3. Configure Database Connection

Run python main.py once to generate the ~/.mycamcontrol/config/sys_config.json template (or create it manually) and populate your MySQL credentials:

{
  "db_host": "127.0.0.1",
  "db_port": "3306",
  "db_user": "root",
  "db_password": "your_password",
  "db_name": "your_database"
}

4. Run the Camera Control Worker

python main.py

The worker continuously:

  1. Scans the local subnet (192.168.1.0/24) for open RTSP port 554 hosts when the cache in cam_info.json expires (every 3600 seconds), maps IPs to MAC addresses via arp -a, and upserts them into xcam_cameras.
  2. Polls xcam_actions for the most recent row with status = 'pending'.
  3. Resolves target cameras by mac_addresses from the JSON additions column and executes the action.

Example: Queueing a check_config Action

Ensure the target camera row in xcam_cameras has its username and password populated, then insert an action:

INSERT INTO xcam_actions (command, additions, status)
VALUES ('check_config', '{"mac_addresses": ["aa-bb-cc-dd-ee-ff"]}', 'pending');

Note: DbHelper.ActionType defines constants for check_config, capture_image, capture_and_stitch, and start_recording; main.py currently implements the check_config RTSP connectivity check handler.

5. Using the Timelapse Worker (EzvizCam.py)

To run standalone timelapse recording using TimelapseWorker, configure ~/.mycamcontrol/config/config.json:

{
  "rtsp_url": "rtsp://admin:[email protected]:554/h264/ch1/main/av_stream",
  "interval": 10,
  "quality": "720p",
  "output_fps": 15,
  "codec": "h264",
  "disk_warning_threshold": 1024
}

Control recording state via ~/.mycamcontrol/config/control.json:

{
  "status": "start",
  "current_video": "timelapse_session.mp4",
  "processing": false
}

Start the worker from Python:

python -c "from EzvizCam import TimelapseWorker; TimelapseWorker().run()"

Setting "status": "stop" in control.json (or sending SIGINT/SIGTERM) finalizes the session frames into an MP4 file under ~/.mycamcontrol/videos/.


License

This project is licensed under the MIT License — see the LICENSE file for details.

About

Python RTSP IP camera control & EZVIZ LAN discovery worker with MySQL action queue, FFmpeg frame validation, and H.264/H.265 timelapse video recording.

sinhsac.github.io/my-cam-control/

Topics

camera-controlcctvezvizffmpegh264ip-cameramysqlnetwork-scannerpythonrtsptimelapsevideo-surveillance

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.