Media Services v3 samples

media services logo v3


Looking for Media Services v2 documentation?
See the Troubleshooting guide for solutions to issues with using Media Services.
Code samples can be found on the Samples page.

This article contains a list of all the samples available for Media Services organized by method and SDK.

Samples by SDK

You'll find description and links to the samples you may be looking for in each of the tabs.

Warning

If you choose not to keep the resources used in these samples after trying them out, remember to delete them. You should create a resource group that contains all of the resources you will use in the samples and then delete the resource group when you are done experimenting. If you don't delete the resources, you will continue to be billed.

Sample Description
Account
Create an account The sample shows how to create a Media Services account and set the primary storage account, in addition to advanced configuration settings including Key Delivery IP allowlist, Managed Identity, storage auth, and bring your own encryption key.
Create an account with user assigned managed identity The sample shows how to create a Media Services account and set the primary storage account, in addition to advanced configuration settings including Key Delivery IP allowlist, user or system assigned Managed Identity, storage auth, and bring your own encryption key.
Assets
Hello World - list assets Basic example of how to connect and list assets
Get the storage container from an asset Demonstrates how to find the Azure storage account container used to store the contents of this asset. This can be used to then edit sources, modify, or copy contents using the Azure storage SDK library
List assets using filters Use filters in your list assets calls to find assets by date and order them.
List tracks in an asset Use the tracks collection to list all of the track names and track types (audio, video, or text) available on an asset
Streaming
Live stream with standard passthrough Standard passthrough live streaming example.
Live stream with standard passthrough with Event Hubs Demonstrates how to use Event Hubs to subscribe to events on the live streaming channel. Events include encoder connections, disconnections, heartbeat, latency, discontinuity, and drift issues.
Live stream with basic passthrough Shows how to set up the basic passthrough live event if you only need to broadcast a low-cost UGC channel.
Low Latency Live (LL-HLS) with 720P standard encoding Enable low latency live streaming with Apple's LL-HLS protocol and encode with the new 3-layer 720P HD adaptive bitrate encoding preset.
Live stream with 720P standard encoding Use live encoding in the cloud with the 720P HD adaptive bitrate encoding preset.
Live stream with 1080P encoding Use live encoding in the cloud with the 1080P HD adaptive bitrate encoding preset.
Upload and stream HLS and DASH Basic example for uploading a local file or encoding from a source URL. Sample shows how to use storage SDK to download content, and shows how to stream to a player
Content protection
Upload and stream HLS and DASH with PlayReady and Widevine DRM Demonstrates how to encode and stream using Widevine and PlayReady DRM
Basic Playready DRM content protection and streaming Demonstrates how to encode and stream using PlayReady DRM
Basic Widevine DRM content protection and streaming Demonstrates how to encode and stream using Widevine DRM
Encoding
Create transform, use job preset overrides (v2-to-v3 API migration) If you need a workflow where you desire to submit custom preset jobs to a single queue, you can use this base sample that shows how to create a (mostly) empty Transform, and then you can use the preset override property on the Job to submit custom presets to the same transform. This allows you to treat the v3 AMS API a lot more like the legacy v2 API Job queue if you desire.
Copy Audio and Video to MP4 without re-encoding Uses the built in preset that rapidly copies the source video and audio into a new MP4 file that is ready to be streamed as on-demand through AMS. This is an extremely useful preset for pre-encoded content or externally encoded content to be quickly readied for streaming in AMS.
Copy Audio and Video to MP4 without re-encoding and create a low bitrate proxy Same as above sample, but adds an additional fast encoded proxy resolution. Very useful when creating a CMS or preview of an Asset.
Copy Audio and Video to MP4 without re-encoding and create a low bitrate proxy and VTT sprite thumbnail Same as above samples, with the addition of a VTT sprite thumbnail for use in building a web page, CMS, or custom asset management application
Encode with H264 Shows how to use the standard encoder to encode a source file into H264 format with AAC audio and PNG thumbnails
Encode with H264 with Event Hubs/Event Grid Shows how to use the standard encoder and receive and process Event Grid events from Media Services through an Event Hubs. First set up an Event Grid subscription that pushes events into an Event Hubs using the Azure portal or CLI to use this sample.
Create a thumbnail sprite (VTT) in JPG format Shows how to generate a VTT Sprite Thumbnail in JPG format and how to set the columns and number of images. This also shows a speed encoding mode in H264 for a 720P layer.
Content aware encoding with H264 Example of using the standard encoder with Content Aware encoding to automatically generate the best quality adaptive bitrate streaming set based on an analysis of the source files contents
Content aware encoding constrained with H264 Demonstrates how to control the output settings of the Content Aware encoding preset to make the outputs more deterministic to your encoding needs and costs. This will still auto generate the best quality adaptive bitrate streaming set based on an analysis of the source files contents, but constrain the output to your desired ranges.
Use an overlay image Shows how to upload an image file and overlay on top of video with output to MP4 container
Rotate a video Shows how to use the rotation filter to rotate a video by 90 degrees.
Output to MPEG transport stream format Shows how to use the standard encoder to encode a source file and output to MPEG Transport Stream format using H264 format with AAC audio and PNG thumbnail
Encode with HEVC Shows how to use the standard encoder to encode a source file into HEVC format with AAC audio and PNG thumbnails
Content aware encoding with HEVC Example of using the standard encoder with Content Aware encoding to automatically generate the best quality HEVC (H.265) adaptive bitrate streaming set based on an analysis of the source files contents
Content aware encoding constrained with HEVC Demonstrates how to control the output settings of the Content Aware encoding preset to make the outputs more deterministic to your encoding needs and costs. This will still auto generate the best quality adaptive bitrate streaming set based on an analysis of the source files contents, but constrain the output to your desired ranges.
Bulk encoding from a remote Azure storage account using SAS URLs This samples shows how you can point to a remote Azure Storage account using a SAS URL and submit batches of encoding jobs to your account, monitor progress, and continue. You can modify the file extension types to scan for (e.g - .mp4, .mov) and control the batch size submitted. You can also modify the Transform used in the batch operation. This sample demonstrates the use of SAS URL's as ingest sources to a Job input. Make sure to configure the REMOTESTORAGEACCOUNTSAS environment variable in the .env file for this sample to work.
Copy live archive to MP4 file format for export or use with Video Indexer This sample demonstrates how to use the archived output from a live event and extract only the top highest bitrate video track to be packaged into an MP4 file for export to social media platforms, or for use with Video Indexer. The key concept in this sample is the use of an input definition on the Job InputAsset to specify a VideoTrackDescriptor. The SelectVideoTrackByAttribute allows you to select a single track from the live archive by using the bitrate attribute, and filtering by the "Top" video bitrate track in the live archive.
Encode a multi-channel audio source file This sample demonstrates how to create an encoding Transform that uses channel mappings and audio track selection from the input source to output two new AAC audio tracks.
The standard encoder is limited to outputting 1 Stereo track, followed by a 5.1 surround sound audio track in AAC format.
Stitch and edit two assets together This sample demonstrates how to stitch and edit together two or more assets into a single MP4 file using the JobInputSequence as part of a job submission.
Analytics
Video Analytics This sample illustrates how to create a video and audio analyzer transform, upload a video file to an input asset, submit a job with the transform and download the results for verification.
Basic Audio Analytics with per-job language override This sample illustrates how to create a audio analyzer transform using the basic mode. It also shows how you can override the preset language on a per-job basis to avoid creating a transform for every language. It also shows how to upload a media file to an input asset, submit a job with the transform and download the results for verification.

Warning

It is not advised to attempt to wrap the REST API for Media Services directly into your own library code, as doing so properly for production purposes would require you to implement the full Azure Resource Management retry logic and understand how to manage long running operations in Azure Resource Management APIs. This is handled by the client SDKs for various languages - .NET, Java, TypeScript, Python, etc. - automatically and reduces the chances of you having issues with retry logic or failed API calls. The client SDKs all handle this for you already.