.. role:: raw-html-m2r(raw) :format: html Azure Live Video Analytics for IoT Edge client library for Python ================================================================= Live Video Analytics on IoT Edge provides a platform to build intelligent video applications that span the edge and the cloud. The platform offers the capability to capture, record, and analyze live video along with publishing the results, video and video analytics, to Azure services in the cloud or the edge. It is designed to be an extensible platform, enabling you to connect different video analysis edge modules (such as Cognitive services containers, custom edge modules built by you with open-source machine learning models or custom models trained with your own data) to it and use them to analyze live video without worrying about the complexity of building and running a live video pipeline. Use the client library for Live Video Analytics on IoT Edge to: * Simplify interactions with the `Microsoft Azure IoT SDKs `_ * Programatically construct media graph topologies and instances `Package (PyPI) `_ | `Product documentation `_ | `Direct methods `_ | `Media graphs `_ | `Source code `_ | `Samples `_ Getting started --------------- Install the package ^^^^^^^^^^^^^^^^^^^ Install the Live Video Analytics client library for Python with pip: .. code-block:: bash pip install azure-media-analytics-edge Prerequisites ^^^^^^^^^^^^^ * Python 2.7, or 3.5 or later is required to use this package. * You need an active `Azure subscription `_\ , and a `IoT device connection string `_ to use this package. * To interact with Azure IoT Hub you will need to run ``pip install azure-iot-hub`` * You will need to use the version of the SDK that corresponds to the version of the LVA Edge module you are using. | SDK | LVA Edge Module | |---|---| | 1.0.0b1 | 2.0 | ### Creating a graph topology and making requests Please visit the `Examples <#examples>`_ for starter code ## Key concepts MediaGraph Topology vs MediaGraph Instance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A *graph topology* is a blueprint or template of a graph. It defines the parameters of the graph using placeholders as values for them. A *graph instance* references a graph topology and specifies the parameters. This way you are able to have multiple graph instances referencing the same topology but with different values for parameters. For more information please visit `Media graph topologies and instances `_ CloudToDeviceMethod ^^^^^^^^^^^^^^^^^^^ The ``CloudToDeviceMethod`` is part of the `azure-iot-hub SDk `_. This method allows you to communicate one way notifications to a device in your IoT hub. In our case, we want to communicate various graph methods such as ``MediaGraphTopologySetRequest`` and ``MediaGraphTopologyGetRequest``. To use ``CloudToDeviceMethod`` you need to pass in two parameters: ``method_name`` and ``payload``. The first parameter, ``method_name``\ , is the name of the media graph request you are sending. Make sure to use each method's predefined ``method_name`` property. For example, ``MediaGraphTopologySetRequest.method_name``. The second parameter, ``payload``\ , sends the entire serialization of the media graph request. For example, ``MediaGraphTopologySetRequest.serialize()`` Examples -------- Creating a graph topology ^^^^^^^^^^^^^^^^^^^^^^^^^ To create a graph topology you need to define parameters, sources, and sinks. .. code-block:: #Parameters user_name_param = MediaGraphParameterDeclaration(name="rtspUserName",type="String",default="dummyusername") password_param = MediaGraphParameterDeclaration(name="rtspPassword",type="String",default="dummypassword") url_param = MediaGraphParameterDeclaration(name="rtspUrl",type="String",default="rtsp://rtspsim:554/media/camera-300s.mkv") #Source and Sink source = MediaGraphRtspSource(name="rtspSource", endpoint=MediaGraphUnsecuredEndpoint(url="${rtspUrl}",credentials=MediaGraphUsernamePasswordCredentials(username="${rtspUserName}",password="${rtspPassword}"))) node = MediaGraphNodeInput(node_name="rtspSource") sink = MediaGraphAssetSink(name="assetsink", inputs=[node],asset_name_pattern='sampleAsset-${System.GraphTopologyName}-${System.GraphInstanceName}', segment_length="PT0H0M30S",local_media_cache_maximum_size_mi_b=2048,local_media_cache_path="/var/lib/azuremediaservices/tmp/") graph_properties = MediaGraphTopologyProperties(parameters=[user_name_param, password_param, url_param], sources=[source], sinks=[sink], description="Continuous video recording to an Azure Media Services Asset") graph_topology = MediaGraphTopology(name=graph_topology_name,properties=graph_properties) Creating a graph instance ^^^^^^^^^^^^^^^^^^^^^^^^^ To create a graph instance, you need to have an existing graph topology. .. code-block:: url_param = MediaGraphParameterDefinition(name="rtspUrl", value=graph_url) graph_instance_properties = MediaGraphInstanceProperties(description="Sample graph description", topology_name=graph_topology_name, parameters=[url_param]) graph_instance = MediaGraphInstance(name=graph_instance_name, properties=graph_instance_properties) Invoking a graph method request ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To invoke a graph method on your device you need to first define the request using the lva sdk. Then send that method request using the iot sdk's ``CloudToDeviceMethod`` .. code-block:: set_method_request = MediaGraphTopologySetRequest(graph=graph_topology) direct_method = CloudToDeviceMethod(method_name=set_method_request.method_name, payload=set_method_request.serialize()) registry_manager = IoTHubRegistryManager(connection_string) registry_manager.invoke_device_module_method(device_id, module_d, direct_method) To try different media graph topologies with the SDK, please see the official `Samples `_. Troubleshooting --------------- * When sending a method request using the IoT Hub's ``CloudToDeviceMethod`` remember to not type in the method request name directly. Instead use ``[MethodRequestName.method_name]`` * Make sure to serialize the entire method request before passing it to ``CloudToDeviceMethod`` Next steps ---------- * `Samples `_ * `Azure IoT Device SDK `_ * `Azure IoTHub Service SDK `_ Contributing ------------ This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. If you encounter any issues, please open an issue on our `Github `_. When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. This project has adopted the `Microsoft Open Source Code of Conduct `_. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. :raw-html-m2r:`` Indices and tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` .. toctree:: :maxdepth: 5 :glob: :caption: Developer Documentation azure.media.analyticsedge.rst