Azure Media Services Encoding code samples

Media Services logo v3


Warning

Azure Media Services will be retired June 30th, 2024. For more information, see the AMS Retirement Guide.

This article is a listing of code samples for Encoding.

H264

Encode with H264

This sample shows how to use the standard encoder to encode a source file into H264 format with AAC audio and PNG thumbnails.

.NET Node.JS Python

Use content aware encoding with H264

This sample is an 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.

.NET Node.JS Python

Use content aware encoding constrained with H264

This sample demonstrates how to control the output settings of the Content Aware encoding H264 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.

.NET Node.JS Python

HEVC

Encode with HEVC

This sample shows how to use the standard encoder to encode a source file into HEVC format with AAC audio and PNG thumbnails.

.NET Node.JS Python

Use content aware encoding with HEVC

This sample is an 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.

.NET Node.JS Python

Use content aware encoding constrained with HEVC

This sample demonstrates how to control the output settings of the Content Aware HEVC 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.

.NET Node.JS Python

Images, thumbnails and sprites

Use an overlay image

This sample shows you how to upload an image file and overlay on top of video with output to MP4 container.

.NET Node.JS Python

Create a thumbnail sprite

This samples shows how to encode with a custom Transform to create a thumbnail sprite.

.NET Node.JS Python

Video manipulation

Rotate a video

This sample shows how to use the rotation filter to rotate a video by 90 degrees.

.NET Node.JS Python

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.

.NET Node.JS Python

Preset override or other use case

Create a transform and 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 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.

.NET not yet available Node.JS Python

Output to MPEG transport stream format

This sample 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.

.NET Node.JS Python

Bulk encode 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 URLs as ingest sources to a Job input. Make sure to configure the REMOTESTORAGEACCOUNTSAS environment variable in the .env file for this sample to work.

.NET not yet available Node.JS not yet available

Encode with Constant Rate Factor Preset for H.264

This sample shows how to create a custom encoding Transform using custom H.264 Constant Rate Factor (CRF) encoding settings.

.NET Node.JS not yet available Python not yet available

Encode with MES adaptive bitrate predefined preset from an HTTP source URL

This sample demonstrates how to create an encoding Transform that uses a built-in preset for adaptive bitrate encoding and ingests a file directly from an HTTPs source URL, publish output asset for streaming, and download results for verification.

.NET Node.JS not yet available Python not yet available

Audio

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.

.NET Node.JS Python

Without re-encoding

Copy Audio and Video to MP4 without re-encoding

This sample uses the built-in preset that rapidly copies the source video and audio into a new MP4 file that is ready to be streamed on-demand. This is an extremely useful preset for pre-encoded content or externally encoded content to be quickly readied for streaming in AMS.

.NET Node.JS Python

Copy Audio and Video to MP4 without re-encoding and create a low bitrate proxy

This sample adds an additional fast-encoded proxy resolution to the Copy Audio and Video to MP4 sample. It is very useful when creating a CMS or preview of an Asset.

.NET Node.JS Python

Copy Audio and Video to MP4 without re-encoding and create a low bitrate proxy and VTT sprite thumbnail

This sample adds a VTT sprite thumbnail to the Copy Audio and Video to MP4 sample for building a web page, CMS, or custom asset management application.

.NET not yet available Node.JS Python

Combine with other Azure services

Encode with H264 with Event Hubs/Event Grid

This sample 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.

.NET not yet available Node.JS
Python

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.

.NET not yet available Node.JS Python