Python library for RTSP streaming from Axis devices
Project description
ax-devil-rtsp
A Python library for RTSP streaming from Axis cameras with video and AXIS Scene metadata support.
The words 'AXIS Scene Metadata' is hereby called 'application data' in this project.
See also: ax-devil-device-api and ax-devil-mqtt for other Axis device management tools.
📋 Contents
🔍 Feature Overview
| Feature | Description | Python API |
|---|---|---|
| 🔄 Combined Streaming | Simultaneous video and application data streaming (default) | RtspDataRetriever |
| 📹 Video Only | Stream video frames without application data | RtspVideoDataRetriever |
| 📊 Application Data (AXIS Scene Metadata) Only | Stream scene application data without video | RtspApplicationDataRetriever |
| ⚡ Real-time Processing | Frame-by-frame processing with custom callbacks | on_video_data |
| 🎯 RTP Extension Data | Access to ONVIF RTP extension data and timing information (enabled by default) | rtp_ext=True |
| 🛠️ Axis URL Builder | Utility for constructing Axis-compatible RTSP URLs | build_axis_rtsp_url |
📦 Installation
pip install ax-devil-rtsp
System Dependencies
On Linux, this library requires system packages for PyGObject and GStreamer. If they're missing, you'll see clear error messages with installation instructions.
Quick setup (Ubuntu/Debian):
# Check what's missing
python tools/dep.py --check
# Get installation commands
python tools/dep.py --install
🚀 Quick Start
Python API
from ax_devil_rtsp import RtspDataRetriever, build_axis_rtsp_url
from multiprocessing import freeze_support
import time
# Define callback functions
def on_video_data(payload):
frame = payload["data"]
diagnostics = payload["diagnostics"]
print(f"Video frame: {frame.shape}, {diagnostics}")
def on_application_data(payload):
xml_data = payload["data"]
diagnostics = payload["diagnostics"]
print(f"Application data: {len(xml_data)} bytes, {diagnostics}")
def on_error(payload):
print(f"Error: {payload['message']}")
def main():
# Build the RTSP URL or supply one directly
# rtsp_url = "rtsp://username:password@192.168.1.90/axis-media/media.amp?analytics=polygon"
rtsp_url = build_axis_rtsp_url(
ip="192.168.1.90",
username="username",
password="password",
video_source=1,
get_video_data=True,
get_application_data=True,
rtp_ext=True, # Enable RTP extension data
resolution="640x480",
)
retriever = RtspDataRetriever(
rtsp_url=rtsp_url,
on_video_data=on_video_data,
on_application_data=on_application_data,
on_error=on_error,
latency=100,
)
# Use context manager for automatic cleanup
with retriever:
print("Streaming... Press Ctrl+C to stop")
while True:
time.sleep(0.1)
if __name__ == "__main__":
freeze_support() # Needed on Windows when multiprocessing start method is 'spawn'
main()
Note
Because
ax-devil-rtspforces the multiprocessing start method to'spawn', your script's entry point must be guarded withif __name__ == "__main__":(as shown above). On Windows also callmultiprocessing.freeze_support()before starting the retriever.
Video-only and application-data-only
from ax_devil_rtsp import (
RtspVideoDataRetriever,
RtspApplicationDataRetriever,
build_axis_rtsp_url,
)
# Video-only
video_url = build_axis_rtsp_url(
ip="192.168.1.90",
username="username",
password="password",
video_source=1,
get_video_data=True,
get_application_data=False,
rtp_ext=True,
)
with RtspVideoDataRetriever(
rtsp_url=video_url,
on_video_data=lambda p: print(p["diagnostics"]),
):
...
# Application data only
app_url = build_axis_rtsp_url(
ip="192.168.1.90",
username="username",
password="password",
video_source=1,
get_video_data=False,
get_application_data=True,
rtp_ext=True,
)
with RtspApplicationDataRetriever(
rtsp_url=app_url,
on_application_data=lambda p: print(len(p["data"]))
):
...
### CLI Usage
The CLI offers two subcommands:
- `device` builds the RTSP URL from device details like IP address and
credentials.
- `url` is for when you already have a complete RTSP URL. Options that modify
the URL (for example `--resolution` or `--rtp-ext`) are only valid with the
`device` command.
**Basic Usage (streams both video and application data):**
```bash
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret
Using a complete RTSP URL:
ax-devil-rtsp url "rtsp://admin:secret@192.168.1.90/axis-media/media.amp?analytics=polygon"
Common Options:
# Custom resolution
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret \
--resolution 1280x720
# Different camera source
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret --source 2
Specialized Modes:
# Video only (no application data overlay)
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret --only-video
# Application data only (no video window)
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret --only-application-data
# Disable RTP extension data
ax-devil-rtsp device --ip 192.168.1.90 --username admin --password secret --no-rtp-ext
For demo processing and lifecycle control, see: --enable-video-processing, --brightness-adjustment, and --manual-lifecycle (run ax-devil-rtsp device --help).
Environment Variables (Optional)
export AX_DEVIL_TARGET_ADDR=192.168.1.90
export AX_DEVIL_TARGET_USER=admin
export AX_DEVIL_TARGET_PASS=secret
export AX_DEVIL_USAGE_CLI=safe # Set to "unsafe" to skip SSL verification
Set these variables to avoid passing --ip, --username, or --password each
time you invoke the device command.
AX_DEVIL_USAGE_CLI is shared with related ax-devil-* tools and kept here for consistency.
🧪 Testing
# Unit tests
pytest tests/unit/ -v
# Integration tests (local test servers)
pytest tests/integration/ -v
# Integration tests (real camera)
USE_REAL_CAMERA=true AX_DEVIL_TARGET_ADDR=192.168.1.90 pytest tests/integration/ -v
Note on GI/GStreamer
On Linux,
PyGObjectand GStreamer are system packages. Install them with your distro package manager before using this library (see Development Setup below). If they are missing, the library will show an error with install instructions.
Python Environment
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
Helper Scripts
tools/dep.py: Unified dependency management tool- Check dependencies:
python tools/dep.py --check - Get install commands (Ubuntu/Debian):
python tools/dep.py --install
- Check dependencies:
📄 License
MIT License - See LICENSE file for details.
⚠️ Disclaimer
This project is independent and not affiliated with Axis Communications AB. For official resources, visit Axis developer documentation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ax_devil_rtsp-0.1.0.tar.gz.
File metadata
- Download URL: ax_devil_rtsp-0.1.0.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14d26a3fb36d688d917e3505b0dbea3368ee18248ef033f0bdde37e7078cae20
|
|
| MD5 |
82a71e1e51c148cb91b9ff931df0a416
|
|
| BLAKE2b-256 |
8f142aaa2154685b1b0fe8e854954fcf4164913c2d3763379a1d150fcdebc8a7
|
File details
Details for the file ax_devil_rtsp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ax_devil_rtsp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 41.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c587cc38315d42b24828a8f0dc4f76964222128b77e95f1c0ed1430c601abb38
|
|
| MD5 |
e52ceb11e2395cc4ef79e00d10742a50
|
|
| BLAKE2b-256 |
c0a495fa7926406c36337223de1e2cf410e30395d030a8011ff7c34e58d7be18
|