Menu

Using libonvif for PTZ...

Ed Sutter
2018-06-21
2019-03-22
  • Ed Sutter

    Ed Sutter - 2018-06-21

    I am working on a linux project that (among other things) streams video from cameras. Until now the majority of the cameras we use are USB and most of what we need we do with gstreamer and/or v4l2 using /dev/video. We now have a requirement to stream from various IP-PTZ cameras (I am currently working with a LINGSEE).
    That being said, I installed libonvif and built the 'discovery' example and it worked like a charm; returning the RTSP URI that I was able to then immediately use with gstreamer. So far so good.

    My first question is this:
    Is it reasonable to assume that I can stream video from the camera using RTSP, and then use ONVIF to do the PTZ control? Assuming that is possible, are there any pointers on how to get started with this? I am very new to ONVIF, and will be digging in meanwhile...

     
  • Stephen Rhodes

    Stephen Rhodes - 2019-03-22

    PTZ control is implemented by libonvif. The simplest example would be a gotoPreset call which will position the camera at one of the preset positions. It takes a string argument indicating the position which will usually be a string representation of an integer, e.g. "1", and the camera's OnvifData structure which has been initialized by the discovery function illustrated in the example program.

    The example commands shown below assume that there is an initialized
    struct OnvifData *onvif_data

    int result = gotoPreset("1", onvif_data);

    will send the command to position the camera at the preset labelled "1" and return 0 if successful. A non-zero result will return an error message in onvif_data->last_error. This convention is used throughout the examples.

    Similarly, a setPreset command will write into the camera memory the current location and set the preset label as called.

    int result = setPreset("1", onvif_data);

    will use the current camera position as the setting for the preset labelled "1".

    To move the camera manually, continuousMove and moveStop are implemented. The continousMove function takes float variables for x, y and z in the range of -1.0 to 1.0, with the value repesenting the speed with which the camera should take during the movement. A typical GUI program would use the button down event to initiate movement in the camera with the continuousMove call and then use the button up event to call moveStop. This will give the user the experience of moving the camera while holding the button down and stopping movement when the button is released.

    int result = continuousMove(-0.5, 0, 0, onvif_data);

    will move the camera to the left at half the maxmimum speed and will continue motion until the moveStop command is recieved.

    int result = moveStop(PAN_TILT_STOP, onvif_data);

    Note that if you are using zoom functions that moveStop takes the ZOOM_STOP constant as the first argument.

     

Log in to post a comment.