网络摄像机(IPC)开发(3):ONVIF获取编码参数

258 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。 ​ ​

一、编码参数

    通过GetVideoEncoderConfigurations可以得到IPC视频流的编码参数:视频编码类型、视频分辨率、帧率、视频质量、码流、I帧间隔等参数;

二、获取编码参数实现

1、创建tcp socket,IP为192.168.100.123,端口:8099;

2、通过ONVIF Device Test Tool工具得到GetDeviceInformation数据

3、发送(send)数据:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">
<soap:Body>
    <trt:GetVideoEncoderConfigurations />
</soap:Body>
</soap:Envelope>

4、接受(recv)数据

HTTP/1.1 200 OK
Server: gSOAP/2.7
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 5008
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xs="http://www.w3.org/2000/10/XMLSchema" xmlns:wsse="http://docs.oasis-
open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
xmlns:wsa5="http://www.w3.org/2005/08/addressing" 
xmlns:xop="http://www.w3.org/2004/08/xop/include" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:tt="http://www.onvif.org/ver10/schema" 
xmlns:ns1="http://www.w3.org/2005/05/xmlmime" xmlns:wstop="http://docs.oasis-
open.org/wsn/t-1" xmlns:ns7="http://docs.oasis-open.org/wsrf/r-2" 
xmlns:ns2="http://docs.oasis-open.org/wsrf/bf-2" 
xmlns:dndl="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" 
xmlns:dnrd="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" 
xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" 
xmlns:dn="http://www.onvif.org/ver10/network/wsdl" 
xmlns:ns10="http://www.onvif.org/ver10/replay/wsdl" 
xmlns:ns11="http://www.onvif.org/ver10/search/wsdl" 
xmlns:ns13="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" 
xmlns:ns14="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" 
xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" 
xmlns:ns15="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" 
xmlns:ns16="http://www.onvif.org/ver10/events/wsdl/EventBinding" 
xmlns:tev="http://www.onvif.org/ver10/events/wsdl" 
xmlns:ns17="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" 
xmlns:ns18="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" 
xmlns:ns19="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" 
xmlns:ns20="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" 
xmlns:ns21="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" 
xmlns:ns22="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBind
ing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" 
xmlns:ns3="http://www.onvif.org/ver10/analyticsdevice/wsdl" 
xmlns:ns4="http://www.onvif.org/ver10/deviceIO/wsdl" 
xmlns:ns5="http://www.onvif.org/ver10/display/wsdl" 
xmlns:ns8="http://www.onvif.org/ver10/receiver/wsdl" 
xmlns:ns9="http://www.onvif.org/ver10/recording/wsdl" 
xmlns:tds="http://www.onvif.org/ver10/device/wsdl" 
xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" 
xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" 
xmlns:trt="http://www.onvif.org/ver10/media/wsdl" 
xmlns:trt2="http://www.onvif.org/ver20/media/wsdl" 
xmlns:ter="http://www.onvif.org/ver10/error" 
xmlns:tns1="http://www.onvif.org/ver10/topics" 
xmlns:tnsn="http://www.eventextension.com/2011/event/topics">
  <SOAP-ENV:Body>
    <trt:GetVideoEncoderConfigurationsResponse>
      <trt:Configurations token="000">
        <tt:Name>VideoE_000</tt:Name>
        <tt:UseCount>1</tt:UseCount>
        <tt:Encoding>H264</tt:Encoding>
        <tt:Resolution>
          <tt:Width>1280</tt:Width>
          <tt:Height>720</tt:Height>
        </tt:Resolution>
        <tt:Quality>1</tt:Quality>
        <tt:RateControl>
          <tt:FrameRateLimit>15</tt:FrameRateLimit>
          <tt:EncodingInterval>1</tt:EncodingInterval>
          <tt:BitrateLimit>1792</tt:BitrateLimit>
        </tt:RateControl>
        <tt:H264>
          <tt:GovLength>12</tt:GovLength>
          <tt:H264Profile>High</tt:H264Profile>
        </tt:H264>
        <tt:Multicast>
          <tt:Address>
            <tt:Type>IPv4</tt:Type>
            <tt:IPv4Address>224.1.2.3</tt:IPv4Address>
          </tt:Address>
          <tt:Port>0</tt:Port>
          <tt:TTL>0</tt:TTL>
          <tt:AutoStart>false</tt:AutoStart>
        </tt:Multicast>
        <tt:SessionTimeout>PT10S</tt:SessionTimeout>
      </trt:Configurations>
      <trt:Configurations token="001">
        <tt:Name>VideoE_001</tt:Name>
        <tt:UseCount>1</tt:UseCount>
        <tt:Encoding>H264</tt:Encoding>
        <tt:Resolution>
          <tt:Width>352</tt:Width>
          <tt:Height>288</tt:Height>
        </tt:Resolution>
        <tt:Quality>1</tt:Quality>
        <tt:RateControl>
          <tt:FrameRateLimit>15</tt:FrameRateLimit>
          <tt:EncodingInterval>1</tt:EncodingInterval>
          <tt:BitrateLimit>512</tt:BitrateLimit>
        </tt:RateControl>
        <tt:H264>
          <tt:GovLength>12</tt:GovLength>
          <tt:H264Profile>High</tt:H264Profile>
        </tt:H264>
        <tt:Multicast>
          <tt:Address>
            <tt:Type>IPv4</tt:Type>
            <tt:IPv4Address>224.1.2.3</tt:IPv4Address>
          </tt:Address>
          <tt:Port>0</tt:Port>
          <tt:TTL>0</tt:TTL>
          <tt:AutoStart>false</tt:AutoStart>
        </tt:Multicast>
        <tt:SessionTimeout>PT10S</tt:SessionTimeout>
      </trt:Configurations>
      <trt:Configurations token="002">
        <tt:Name>VideoE_002</tt:Name>
        <tt:UseCount>1</tt:UseCount>
        <tt:Encoding>JPEG</tt:Encoding>
        <tt:Resolution>
          <tt:Width>352</tt:Width>
          <tt:Height>288</tt:Height>
        </tt:Resolution>
        <tt:Quality>4</tt:Quality>
        <tt:RateControl>
          <tt:FrameRateLimit>-3600</tt:FrameRateLimit>
          <tt:EncodingInterval>1</tt:EncodingInterval>
          <tt:BitrateLimit>512</tt:BitrateLimit>
        </tt:RateControl>
        <tt:Multicast>
          <tt:Address>
            <tt:Type>IPv4</tt:Type>
            <tt:IPv4Address>224.1.2.3</tt:IPv4Address>
          </tt:Address>
          <tt:Port>0</tt:Port>
          <tt:TTL>0</tt:TTL>
          <tt:AutoStart>false</tt:AutoStart>
        </tt:Multicast>
        <tt:SessionTimeout>PT10S</tt:SessionTimeout>
      </trt:Configurations>
    </trt:GetVideoEncoderConfigurationsResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

5、解析上面接受到数据可以看到,这个IPC可以得到3个视频流;分别对应3个token:000、001、002;我这里只解析一个视频流:token="000",需要得到其他也是同样方法,后面获取码流的url也需要这个token;
token="000",Name="VideoE_000" 设备的编码参数如下:

编码类型:     Encoding:               H264
视频分辨率:  WidthHeight         1280720
视频质量:   Quality                   1
帧率:          FrameRateLimit     15
码率:          BitrateLimit             1792
I帧间隔         GovLength             12

6、上面这些是IPC设备默认编码参数,IPC设备也是可以通过SetVideoEncoderConfiguration设置编码参数的,后面博客会有讲解;