Microsoft Azure Media Live Video Analytics Edge SDK Library for Python
Project description
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:
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 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.
#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.
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
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
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.
Release History
1.0.0b1 (2021-01-13)
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file azure-media-analytics-edge-1.0.0b1.zip
.
File metadata
- Download URL: azure-media-analytics-edge-1.0.0b1.zip
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1162655f6a90f034b5f71c62cc643e41e95b2c2976cdd367f53a539402f7beca |
|
MD5 | e7574c4be63ffe76cfbfdb02de7cc0d5 |
|
BLAKE2b-256 | f0646c371b5580077dc4b710c3fc87214b7ac4b3948b97d85fe317e97abb0714 |
File details
Details for the file azure_media_analytics_edge-1.0.0b1-py2.py3-none-any.whl
.
File metadata
- Download URL: azure_media_analytics_edge-1.0.0b1-py2.py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 604594156b1df2a45a0cedb0ad8f7f2782621d8e9e0d35980e7aee5cc246eae8 |
|
MD5 | bf6caff4c6ebbc4f5d59ecdc72682b52 |
|
BLAKE2b-256 | 1cd5d01214be6b36605a260e616cd88305630e1e2cbbb8dcae142f083e0cb394 |