Skip to content

Configuring cameras

Scott Lamb edited this page Apr 27, 2021 · 4 revisions

Moonfire NVR doesn't (yet) have any camera autoconfiguration. You need to tell it the RTSP URLs for the main and sub streams during installation.

If you don't know your camera's URLs,

  • look at the camera pages on this wiki for help
  • look elsewhere on the web, eg security.world or getscw.com.
  • try third-party tools to auto-detect the URL.
  • ask for help

python-onvif-zeep

A small script with the python-onvif-zeep library can autodetect RTSP URLs for ONVIF profiles if you know the camera's IP address.

#!/usr/bin/env python3

import argparse
from onvif import ONVIFCamera


def PrintCam(ip, port, username, password):
    print(f'camera {ip}:{port}')
    c = ONVIFCamera(ip, port, username, password)

    c.create_devicemgmt_service()
    print(c.devicemgmt.GetDeviceInformation())

    c.create_media_service()
    for p in c.media.GetProfiles():
        resp = c.media.GetStreamUri({
            'StreamSetup': {'Stream': 'RTP-Unicast', 'Transport': {'Protocol': 'RTSP'}},
            'ProfileToken': p.token,
        })
        print(resp.Uri)


parser = argparse.ArgumentParser(description='Find RTSP URLs.')
parser.add_argument('--ip', dest='ip', required=True,
                   help='ip address (or hostname) of the camera')
parser.add_argument('--port', dest='port', type=int, default=80,
                   help='ONVIF port of the camera (default 80)')
parser.add_argument('--username', dest='username',
                   help='ONVIF administrator username')
parser.add_argument('--password', dest='password',
                   help='ONVIF administrator password')
args = parser.parse_args()
PrintCam(args.ip, args.port, args.username, args.password)
$ ./find-urls.py --ip 192.168.5.112 --username admin --password mypassword
camera 192.168.5.112:80
{
    'Manufacturer': 'General',
    'Model': 'IPC-T5442T-ZE',
    'FirmwareVersion': '2.800.15OG004.0.T, Build Date 2020-11-23',
    'SerialNumber': '6H0AB8BPAG0B6D7',
    'HardwareId': '1.00'
}
rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif
rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=2&unicast=true&proto=Onvif

Note: if you see an error like the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/onvif/client.py", line 216, in __init__
    self.update_xaddrs()
  File "/usr/local/lib/python3.8/dist-packages/onvif/client.py", line 223, in update_xaddrs
    self.devicemgmt  = self.create_devicemgmt_service()
  File "/usr/local/lib/python3.8/dist-packages/onvif/client.py", line 333, in create_devicemgmt_service
    return self.create_onvif_service('devicemgmt', from_template)
  File "/usr/local/lib/python3.8/dist-packages/onvif/client.py", line 312, in create_onvif_service
    xaddr, wsdl_file, binding_name = self.get_definition(name, portType)
  File "/usr/local/lib/python3.8/dist-packages/onvif/client.py", line 292, in get_definition
    raise ONVIFError('No such file: %s' % wsdlpath)
onvif.exceptions.ONVIFError: Unknown error: No such file: /usr/local/lib/python3.8/dist-packages/wsdl/devicemgmt.wsdl

try installing from source rather than pip install onvif_zeep. See python-onvif-zeep#13.

lumeohq/onvif-rs

The lumeohq/onvif-rs project also supports discovering URLs.

$ git clone https://github.com/lumeohq/onvif-rs
$ cd onvif-rs
$ cargo run --example camera -- get-stream-uris --uri http://192.168.5.112/ --username admin --password mypassword
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/examples/camera get-stream-uris --uri 'http://192.168.5.112/' --username admin --password mypassword`
token=MediaProfile00000 name=MediaProfile_Channel1_MainStream
    rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
    H264, 2688x1520
    30 fps, 20480 kbps
    audio: Aac, 192 kbps, 48 kHz
token=MediaProfile00001 name=MediaProfile_Channel1_SubStream1
    rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif
    H264, 704x480
    15 fps, 512 kbps
    audio: Aac, 192 kbps, 48 kHz
token=MediaProfile00002 name=MediaProfile_Channel1_SubStream2
    rtsp://192.168.5.112:554/cam/realmonitor?channel=1&subtype=2&unicast=true&proto=Onvif
    H264, 704x480
    12 fps, 256 kbps
    audio: G711, 32 kbps, 8 kHz
Clone this wiki locally