Ptz onvif

From damionrashford/media-os · View interactive version

Ptz onvif is an AI agent skill from the GitHub repository damionrashford/media-os. Discover and control ONVIF IP cameras via SOAP/XML with WS-Security UsernameToken digest: onvif-util (libonvif github.com/sr99622/libonvif), onvif-cli (github.com/gardere/onvif-cli), python-onvif-zeep (PyPI onvif-zeep), onvif_control (bash + WS-Security), gonvif (Go). WS-Discovery multicast to 239.2

How to use this skill

Skill file

PTZ ONVIF

Context: $ARGUMENTS

Speak ONVIF (SOAP 1.2 / XML / WS-Security) to IP cameras — the industry-standard way to discover devices, pull RTSP URIs, and drive PTZ without vendor SDKs. For low-level Sony VISCA (non-ONVIF PTZ) use ptz-visca. For spec lookup see ptz-docs.

Quick start

When to use

Step 1 — Discover

WS-Discovery is a UDP multicast probe to 239.255.255.250:3702. The helper sends a SOAP <Probe> envelope and parses ProbeMatch responses to extract each camera's Device service URL (XAddrs).

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py discover --timeout 3

Output (JSON):

[
  {"xaddr": "http://192.168.1.64:80/onvif/device_service",
   "types": "dn:NetworkVideoTransmitter tds:Device",
   "scopes": ["onvif://www.onvif.org/hardware/DS-2CD2", ...]}
]

WS-Discovery is link-local — it does NOT cross subnets or VLANs. For a camera you already know, skip to Step 2 with the Device service URL (usually http://HOST/onvif/device_service).

Step 2 — Get device info

Requires WS-Security UsernameToken with digest:

Digest = BASE64( SHA1( nonce + created + password ) )

nonce is raw random bytes (NOT base64) used inside the SHA1. The header also carries the base64 of the nonce and the ISO-8601 Created timestamp.

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py info \
    --host 192.168.1.64 --user admin --password 'S3cret' \
    --format json

Returns Manufacturer, Model, FirmwareVersion, SerialNumber, HardwareId.

Step 3 — Fetch stream URIs (Media service)

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py streams \
    --host 192.168.1.64 --user admin --password 'S3cret'

Enumerates media profiles and returns RTSP URIs suitable for ffmpeg:

ffmpeg -rtsp_transport tcp -i rtsp://admin:S3cret@192.168.1.64:554/... out.mp4

Pass --rtsp-transport rtp-unicast / rtp-multicast / http to tweak SetStreamUri negotiation.

Step 4 — Snapshot

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py snapshot \
    --host 192.168.1.64 --user admin --password 'S3cret' \
    --output shot.jpg

Calls GetSnapshotUri then fetches the JPEG via HTTP Digest (most cameras) or Basic auth.

Step 5 — PTZ

# Continuous move (ContinuousMove, auto-stop after --timeout)
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz continuous \
    --host 192.168.1.64 --user admin --password 'S3cret' \
    --pan 0.5 --tilt 0 --zoom 0 --timeout 1.5

# Absolute (AbsoluteMove)
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz absolute \
    --host ... --pan-x 0.5 --tilt-y -0.3 --zoom 0.2

# Goto preset
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz preset-goto \
    --host ... --preset-token 2

# Save current position as preset
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz preset-set \
    --host ... --preset-name "Cam1-Wide"

# Stop
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz stop --host ...

Pan/tilt velocities are normalized to [-1.0, 1.0]. Absolute positions also [-1.0, 1.0]; zoom [0.0, 1.0]. The helper auto-discovers the first ProfileToken if none is provided.

Gotchas

Examples

Example 1 — Discover and grab stream URIs in one shot

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py discover | \
    jq -r '.[].xaddr' | while read url; do
        uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py streams \
            --xaddr "$url" --user admin --password 'S3cret'
    done

Example 2 — Point camera at preset 2 with a 1 s pre-move freeze

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz stop --host ... --user admin --password x
sleep 1
uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py ptz preset-goto \
    --host ... --user admin --password x --preset-token 2

Example 3 — Pipe the RTSP URI straight to ffmpeg

URL=$(uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py streams \
    --host ... --user admin --password x --format json \
    | jq -r '.[0].rtsp_uri')
ffmpeg -rtsp_transport tcp -i "$URL" -c copy out.mp4

Example 4 — Dry-run the SOAP envelope

uv run ${CLAUDE_SKILL_DIR}/scripts/onvifctl.py info \
    --host ... --user admin --password x --dry-run --verbose

Prints the SOAP envelope and the computed WS-Security digest without hitting the network.

Reference docs

CLI alternatives

Troubleshooting

WS-Discovery returns nothing

Cause: Not on the same L2 broadcast domain, or firewall drops multicast.

Solution: Confirm cameras on same subnet/VLAN. Disable firewall UDP blocks on port 3702. Fall back to unicast GetCapabilities with a known IP.

HTTP 401 from SOAP endpoint

Cause: Digest mismatch — typically PasswordText vs PasswordDigest, or clock skew > 5 min.

Solution: Use --verbose to see the SOAP envelope. Verify the Created timestamp is current. Check the camera's NTP.

`Sender not authorized` or `401` from digest

Cause: Wrong hashing order (nonce + created + password is required — in that order), or passing the base64-encoded nonce into the SHA1 instead of raw bytes.

Solution: Read references/services.md WS-Security pseudocode. Let --dry-run --verbose print the digest inputs.

`ActionNotSupported` on `AbsoluteMove`

Cause: Camera lacks AbsolutePanTiltPositionSpace.

Solution: Use ContinuousMove with a short --timeout or RelativeMove.

RTSP stream URL returns 401

Cause: Different user table for RTSP vs SOAP.

Solution: Embed user/password in the URL (rtsp://user:pass@host/...) or check the RTSP user in the camera UI.

Snapshot URL 404s

Cause: Vendor's snapshot handler lives elsewhere despite what GetSnapshotUri returns.

Solution: Try the vendor's documented URL (e.g. http://host/cgi-bin/snapshot.cgi for Amcrest/Dahua), or use an ffmpeg -frames:v 1 grab from the RTSP stream.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.