The functions in the Python code snippets assume that you have:
- Imported the necessary modules. You may not need all of the modules shown here. If the code below doesn't use the module, you can omit it.
- Created and edited an .env file that contains your authentication values. You can get a sample.env file from the Media Services Python samples.
- Read and instantiated environment variables by using load_env() as below. Depending on what you are doing, you may or may not need some of the variables.
- Created a Media Services client as below.
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.mgmt.media import AzureMediaServices
# BuiltInEncoderPreset is used here but you should import the preset that you want to use.
from azure.mgmt.media.models import (Transform,TransformOutput,BuiltInStandardEncoderPreset)
import os
# Get environment variables
load_dotenv()
subscriptionId = os.getenv("SUBSCRIPTIONID")
accountName=os.getenv("ACCOUNTNAME")
resourceGroupName=os.getenv("RESOURCEGROUP")
clientId = os.getenv("AZURE_CLIENT_ID")
storageAccountName=os.getenv("STORAGEACCOUNTNAME")
# Create the Media Services client and authenticate using the DefaultAzureCredential
default_credential = DefaultAzureCredential()
# From SDK
# AzureMediaServices(credentials, subscription_id, base_url=None)
client = AzureMediaServices(default_credential, subscriptionId)
# Create a Transform
# Set the name of the transform you want to create.
transformName='MyTransform'
# Create at least one transform output.
# Don't forget to import the preset that you want to use.
# From SDK
# TransformOutput(*, preset, on_error=None, relative_priority=None, **kwargs) -> None
transform_output = TransformOutput(preset=BuiltInStandardEncoderPreset(preset_name="AdaptiveStreaming"))
# Add the transform output to the outputs list
outputs = [transform_output]
# Create the transform object
# From SDK
# Transform(*, description: Optional[str] = None, outputs: Optional[List[azure.mgmt.media.models._models_py3.TransformOutput]] = None, **kwargs)
transform = Transform(description="My description",outputs=outputs)
print("Creating transform " + transformName)
# From SDK
# Create_or_update(resource_group_name, account_name, transform_name, outputs, description=None, custom_headers=None, raw=False, **operation_config)
def createTransform(resource_group_name, account_name, transform_name,transform):
client.transforms.create_or_update(resource_group_name,account_name,transform_name,transform)
createTransform(resourceGroupName,accountName,transformName,transform)