Exploring ONVIF APIs and Their Applications for Seamless Integration

Introduction to ONVIF

ONVIF (Open Network Video Interface Forum) is an open industry forum that provides and promotes standardized interfaces for effective interoperability of IP-based physical security products. With ONVIF, manufacturers can ensure that their devices are compatible with a wide range of security management systems, enabling customers to benefit from greater flexibility and choice.

Core ONVIF APIs with Code Snippets

Device Management Service

The Device Management service allows clients to retrieve information about device capabilities, manage configurations, and control settings related to the network and system. Below are some useful API methods:

GetDeviceInformation

  
    POST /onvif/device_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <tds:GetDeviceInformation xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>
      </s:Body>
    </s:Envelope>
  

GetCapabilities

  
    POST /onvif/device_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <tds:GetCapabilities xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
          <tds:Category>All</tds:Category>
        </tds:GetCapabilities>
      </s:Body>
    </s:Envelope>
  

Media Service

The Media service provides interfaces for managing media configurations, streaming profiles, and obtaining stream URIs. Here’s how you can retrieve profiles:

GetProfiles

  
    POST /onvif/media_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <trt:GetProfiles xmlns:trt="http://www.onvif.org/ver10/media/wsdl"/>
      </s:Body>
    </s:Envelope>
  

GetStreamUri

  
    POST /onvif/media_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <trt:GetStreamUri xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
          <trt:StreamSetup>
            <trt:Stream xmlns:tt="http://www.onvif.org/ver10/schema">RTP-Unicast</trt:Stream>
            <trt:Transport xmlns:tt="http://www.onvif.org/ver10/schema">
              <tt:Protocol>RTSP</tt:Protocol>
            </trt:Transport>
          </trt:StreamSetup>
          <trt:ProfileToken>profile_1</trt:ProfileToken>
        </trt:GetStreamUri>
      </s:Body>
    </s:Envelope>
  

PTZ (Pan-Tilt-Zoom) Control

The PTZ control service allows users to control the movement and orientation of the camera. Here are some useful PTZ commands:

ContinuousMove

  
    POST /onvif/ptz_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <tptz:ContinuousMove xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl">
          <tptz:ProfileToken>profile_1</tptz:ProfileToken>
          <tptz:Velocity>
            <tt:PanTilt x="0.5" y="0.5" xmlns:tt="http://www.onvif.org/ver10/schema"/>
          </tptz:Velocity>
        </tptz:ContinuousMove>
      </s:Body>
    </s:Envelope>
  

Stop

  
    POST /onvif/ptz_service HTTP/1.1
    Content-Type: application/soap+xml; charset=utf-8

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Body>
        <tptz:Stop xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl">
          <tptz:ProfileToken>profile_1</tptz:ProfileToken>
        </tptz:Stop>
      </s:Body>
    </s:Envelope>
  

Example App Using ONVIF APIs

Let’s develop a simple Python application that utilizes the ONVIF APIs to control a camera device:

Python Code

  
    from onvif import ONVIFCamera

    # Connect to the camera
    mycam = ONVIFCamera('192.168.1.100', 80, 'username', 'password')

    # Get device information
    resp = mycam.devicemgmt.GetDeviceInformation()
    print ('Manufacturer: ', resp.Manufacturer)
    print ('Model: ', resp.Model)
    print ('FirmwareVersion: ', resp.FirmwareVersion)

    # Get media profiles
    resp = mycam.media.GetProfiles()
    media_profile = resp[0]
    print ('Media Profile: ', media_profile)

    # Get stream URI
    stream_uri = mycam.media.GetStreamUri({'StreamSetup': {'Stream': 'RTP-Unicast', 'Transport': {'Protocol': 'RTSP'}}, 'ProfileToken': media_profile.token})
    print ('Stream URI: ', stream_uri.Uri)

    # Control PTZ
    ptz = mycam.create_ptz_service()
    ptz.ContinuousMove({'ProfileToken': media_profile.token, 'Velocity': {'PanTilt': {'x': 0.5, 'y': 0.5}}})
  

This Python script connects to an ONVIF camera, retrieves device information, media profiles, and stream URIs, and demonstrates basic PTZ control.

With ONVIF APIs, developers can integrate comprehensive device management features into their applications, ensuring seamless interoperability with a variety of camera and security devices.

Hash: bffe72dbcae774feadcf9283ab33a562a11e06aeabe8ebfe7f66e4847fb027e9

Leave a Reply

Your email address will not be published. Required fields are marked *