1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Onvif で RTSP Stream URIを取得するまでの流れ

Last updated at Posted at 2024-04-07

以下のシミュレータで試す。

の Download x86 (Windowsの場合)をダウンロード。

ダウンロード後実行する場合、単に試すだけなら、runme を起動すればいい。

起動すると

Happytime onvif server version V10.5
Onvif server running at http://192.168.1.18:8000

などのコンソールに表示されている。この192.168.1.19 は、環境によって違うので、以下のIPアドレスは上記にあわせる。

pythonで試す場合、onvif_zeepをインストール

$ pip install onvif_zeep

以下のようにして、カメラにアクセス。adminは一つ目はユーザー名、二つ目はパスワードで、Happytime Softのonvif-serverの初期値。

from onvif import ONVIFCamera
mycam = ONVIFCamera('192.168.1.18', 8000, 'admin', 'admin')

このときに、'No such file: devicemgmt.wsdl'というエラーが出ることがある。
pipでonvif_zeepを入れると、WSDLがコピーされていない環境がある模様。
解決法はわからないが、https://github.com/FalkTannhaeuser/python-onvif-zeep/tree/zeep/wsdl からファイルをすべてダウンロードして、スクリプトと同じフォルダに配置して回避した。

# To avoid 'No such file: devicemgmt.wsdl', copied wsdl folder from
#  https://github.com/FalkTannhaeuser/python-onvif-zeep/tree/zeep/wsdl
mycam = ONVIFCamera('192.168.1.18', 8000, 'admin', 'admin', os.path.join(SCRIPTDIR, 'wsdl'))

RTSP の URIを取得するまでの流れは以下の通り。

$ python
>>> from onvif import ONVIFCamera
>>> mycam = ONVIFCamera('192.168.1.18', 8000, 'admin', 'admin')
>>> mycam.devicemgmt.GetDeviceInformation()
{
    'Manufacturer': 'Happytimesoft',
    'Model': 'IPCamera',
    'FirmwareVersion': '2.4',
    'SerialNumber': '123456',
    'HardwareId': '1.0'
}
>>> media_service = mycam.create_media_service()
>>> profile_token = mycam.media.GetProfiles()[0].token
>>> get_stream_uri = media_service.create_type("GetStreamUri")
>>> get_stream_uri.ProfileToken = profile_token
>>> get_stream_uri.StreamSetup =  {'Stream': 'RTP-Unicast', 'Transport': {'Protocol': 'RTSP'}}
>>> media_service.GetStreamUri(get_stream_uri)
{
    'Uri': 'rtsp://192.168.1.18/test.mp4&t=unicast&p=rtsp&ve=H264&w=1280&h=720&ae=PCMU&sr=8000',
    'InvalidAfterConnect': False,
    'InvalidAfterReboot': False,
    'Timeout': datetime.timedelta(seconds=60),
    '_value_1': None,
    '_attr_1': None
}

対応しているサービスの確認

>>> mycam.devicemgmt.GetCapabilities()
{
    'Analytics': {
        'XAddr': 'http://192.168.1.18:8000/onvif/analytics_service',
        'RuleSupport': True,
        'AnalyticsModuleSupport': True,
        '_value_1': None,
        '_attr_1': None
    },
    'Device': {
        'XAddr': 'http://192.168.1.18:8000/onvif/device_service',
        'Network': {
            'IPFilter': True,
            'ZeroConfiguration': True,
            'IPVersion6': False,
            'DynDNS': True,
            'Extension': {
                '_value_1': [
                    <Element {http://www.onvif.org/ver10/schema}Dot11Configuration at 0x246c7070f00>
                ],
                'Dot11Configuration': None,
                'Extension': None
            },
            '_attr_1': None
        },
        'System': {
            'DiscoveryResolve': True,
            'DiscoveryBye': True,
            'RemoteDiscovery': False,
            'SystemBackup': True,
            'SystemLogging': True,
            'FirmwareUpgrade': True,
            'SupportedVersions': [
                {
                    'Major': 23,
                    'Minor': 12
                },
                {
                    'Major': 23,
                    'Minor': 6
                },
                {
                    'Major': 22,
                    'Minor': 12
                },
                {
                    'Major': 22,
                    'Minor': 6
                },
                {
                    'Major': 21,
                    'Minor': 12
                },
                {
                    'Major': 21,
                    'Minor': 6
                },
                {
                    'Major': 20,
                    'Minor': 12
                },
                {
                    'Major': 20,
                    'Minor': 6
                },
                {
                    'Major': 19,
                    'Minor': 12
                },
                {
                    'Major': 2,
                    'Minor': 0
                }
            ],
            'Extension': {
                '_value_1': [
                    <Element {http://www.onvif.org/ver10/schema}HttpFirmwareUpgrade at 0x246c70704c0>,
                    <Element {http://www.onvif.org/ver10/schema}HttpSystemBackup at 0x246c7071ac0>,
                    <Element {http://www.onvif.org/ver10/schema}HttpSystemLogging at 0x246c7071a00>,
                    <Element {http://www.onvif.org/ver10/schema}HttpSupportInformation at 0x246c7071bc0>
                ],
                'HttpFirmwareUpgrade': None,
                'HttpSystemBackup': None,
                'HttpSystemLogging': None,
                'HttpSupportInformation': None,
                'Extension': None
            },
            '_attr_1': None
        },
        'IO': {
            'InputConnectors': 1,
            'RelayOutputs': 1,
            'Extension': {
                '_value_1': [
                    <Element {http://www.onvif.org/ver10/schema}Auxiliary at 0x246c7042000>,
                    <Element {http://www.onvif.org/ver10/schema}Extension at 0x246c70412c0>
                ],
                'Auxiliary': None,
                'AuxiliaryCommands': [],
                'Extension': None,
                '_attr_1': None
            },
            '_attr_1': None
        },
        'Security': {
            'TLS1.1': False,
            'TLS1.2': False,
            'OnboardKeyGeneration': False,
            'AccessPolicyConfig': True,
            'X.509Token': False,
            'SAMLToken': False,
            'KerberosToken': False,
            'RELToken': False,
            '_value_1': [
                <Element {http://www.onvif.org/ver10/schema}Extension at 0x246c7048140>
            ],
            'Extension': None,
            '_attr_1': None
        },
        'Extension': None,
        '_attr_1': None
    },
    'Events': {
        'XAddr': 'http://192.168.1.18:8000/onvif/event_service',
        'WSSubscriptionPolicySupport': True,
        'WSPullPointSupport': True,
        'WSPausableSubscriptionManagerInterfaceSupport': False,
        '_value_1': None,
        '_attr_1': None
    },
    'Imaging': {
        'XAddr': 'http://192.168.1.18:8000/onvif/image_service',
        '_attr_1': None
    },
    'Media': {
        'XAddr': 'http://192.168.1.18:8000/onvif/media_service',
        'StreamingCapabilities': {
            'RTPMulticast': False,
            'RTP_TCP': True,
            'RTP_RTSP_TCP': True,
            'Extension': None,
            '_attr_1': None
        },
        '_value_1': [
            <Element {http://www.onvif.org/ver10/schema}Extension at 0x246c704a840>
        ],
        'Extension': None,
        '_attr_1': None
    },
    'PTZ': {
        'XAddr': 'http://192.168.1.18:8000/onvif/ptz_service',
        '_value_1': None,
        '_attr_1': None
    },
    'Extension': {
        '_value_1': [
            <Element {http://www.onvif.org/ver10/schema}DeviceIO at 0x246c704b3c0>,
            <Element {http://www.onvif.org/ver10/schema}Recording at 0x246c704b440>,
            <Element {http://www.onvif.org/ver10/schema}Search at 0x246c7048ec0>,
            <Element {http://www.onvif.org/ver10/schema}Replay at 0x246c704af80>,
            <Element {http://www.onvif.org/ver10/schema}Receiver at 0x246c704a2c0>
        ],
        'DeviceIO': None,
        'Display': None,
        'Recording': None,
        'Search': None,
        'Replay': None,
        'Receiver': None,
        'AnalyticsDevice': None,
        'Extensions': None
    },
    '_attr_1': None
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?