Skip to main content

Python library for RTSP streaming from Axis devices

Project description

ax-devil-rtsp

Python package for streaming RTSP video and AXIS Scene Metadata (referred to here as "application data") from Axis devices. Includes a Python API with callbacks and a CLI demo for quick inspection.

See also ax-devil-device-api and ax-devil-mqtt for related tools.


Install

pip install ax-devil-rtsp

System dependencies (Linux)

PyGObject and GStreamer must be available via your package manager.

# Check what you already have
python tools/dep.py --check

# Show Ubuntu/Debian install commands
python tools/dep.py --install

Configure (optional)

Avoid repeating device credentials by exporting:

  • AX_DEVIL_TARGET_ADDR – Device IP or hostname
  • AX_DEVIL_TARGET_USER – Device username
  • AX_DEVIL_TARGET_PASS – Device password

CLI

Run ax-devil-rtsp --help for the full reference. Common flows:

  • Connect to a device (builds the RTSP URL for you):
    ax-devil-rtsp --device-ip 192.168.1.90 --device-username admin --device-password secret
    
  • Use an existing RTSP URL:
    ax-devil-rtsp --url "rtsp://admin:secret@192.168.1.90/axis-media/media.amp?analytics=polygon"
    
  • Switch modes without changing the URL:
    # Video only
    ax-devil-rtsp ... --only-video
    
    # Application data only
    ax-devil-rtsp ... --only-application-data
    
    # Disable RTP extension data
    ax-devil-rtsp ... --no-rtp-ext
    
  • Adjust the stream: --resolution 1280x720, --source 2, --latency 200 (only applies when building the URL without --url)
  • Demo helpers: --enable-video-processing, --brightness-adjustment 25, --manual-lifecycle (--url skips device-specific URL construction)

Python API

import time
from multiprocessing import freeze_support
from ax_devil_rtsp import RtspDataRetriever, build_axis_rtsp_url


def on_video_data(payload):
    frame = payload["data"]
    print(f"Video frame: {frame.shape}")


def on_application_data(payload):
    print(f"Application data bytes: {len(payload['data'])}")


def on_session_start(payload):
    media = payload.get("caps_parsed", {}).get("media") or payload.get(
        "structure_parsed", {}
    ).get("media")
    print(f"Session start for {media}: {payload['stream_name']}")


def on_error(payload):
    print(f"Error: {payload['message']}")


def main():
    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,
        resolution="640x480",
    )

    retriever = RtspDataRetriever(
        rtsp_url=rtsp_url,
        on_video_data=on_video_data,
        on_application_data=on_application_data,
        on_session_start=on_session_start,
        on_error=on_error,
        latency=100,
    )

    with retriever:
        print("Streaming... Press Ctrl+C to stop")
        while True:
            time.sleep(0.1)

# Expect `on_session_start` to run once for each RTP pad (typically
# one for video and one for application metadata). Use the parsed
# `media` field to tell them apart, as shown above.

if __name__ == "__main__":
    freeze_support()  # Required on Windows because the package forces 'spawn'
    main()
  • RtspVideoDataRetriever and RtspApplicationDataRetriever are available for video-only or metadata-only flows.
  • on_session_start is invoked once per RTP pad; the parsed media value distinguishes video vs. application data.
  • Because the package forces the multiprocessing start method to 'spawn', keep the if __name__ == "__main__": guard around your entry point (all platforms).

Development

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest
ruff check .
black src tests

License

MIT License - see LICENSE.

Disclaimer

This project is independent and not affiliated with Axis Communications AB. For official resources, visit the 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

ax_devil_rtsp-0.2.1.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ax_devil_rtsp-0.2.1-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file ax_devil_rtsp-0.2.1.tar.gz.

File metadata

  • Download URL: ax_devil_rtsp-0.2.1.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ax_devil_rtsp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3f54b7fcedcf26549e4a25fc264a4c694d88523a65583a73de514325cc542700
MD5 a5bc24cdd0f917a26f4cabdb5c635afb
BLAKE2b-256 df9d4d0681e30970c4d4672be1120e5759c986a97ad05b097cd85309fef9f5f7

See more details on using hashes here.

File details

Details for the file ax_devil_rtsp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ax_devil_rtsp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ax_devil_rtsp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a4a56c34c1aa00a5bd9872cb2028fda83bb9c98a6bbf29b65e9b3c6ff32e83a
MD5 681db4f45387e57b4b494c972d4fe48c
BLAKE2b-256 4872bdc307c74e2b5ec1843eaf762b4ff70d6fbfecabbebb3608cc1338621d24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page