azureazure-media-servicesvideo-thumbnails

Azure media service get the thumbnail file URL


We currently are uploading video using Azure media services. When the job runs in Media Service it creates a thumbnail. I can navigate to it from the Azure Portal.

When the job finishes, we use event grid and have code which handles the event. We receive in a JSONObject which has the following form

outputs {[
  {
    "@odata.type": "#Microsoft.Media.JobOutputAsset",
    "assetName": "output-06982218-ecb1-4680-8cd4-c6800d991fba",
    "error": null,
    "label": "BuiltInStandardEncoderPreset_0",
    "progress": 100,
    "state": "Finished"
  }
]}

If I navigate to that output Asset in Azure portal, it shows

Storage container:asset-a5536b5c-3024-4162-ad78-81f5448d3f68

and inside this is the thumb nail file

My questions is given the output-06982218-ecb1-4680-8cd4-c6800d991fba

how can I general a URL to asset-a5536b5c-3024-4162-ad78-81f5448d3f68/Thumbnail000001.jpg
which is the thumbnail file?

We want to store this in a database for use later.


Solution

  • Every Asset in AMS has a container name property on it.

    You can use that to find the container that stores your contents for the asset including the MP4 files, manifests, metadata, and any output thumbnail JPG or PNG or VTT files.
    To get access to that, just use the Storage Client SDKs. We have many samples of downloading content using storage client SDKs in our sample repos. https://learn.microsoft.com/en-us/rest/api/media/assets/get#asset

    Check out the Node/Typescript ones for various examples of using the Storage client SDKS to download content. https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/main/VideoEncoding/Encoding_Sprite_Thumbnail

    If you need to just get a URL to that file, you can also create a SAS URL on the Asset using the GetContainerSAS method and then append the name of the file you want to that SAS URL and download it directly using the URL. https://learn.microsoft.com/en-us/rest/api/media/assets/list-container-sas Just note that GetContainerSAS will give you a SAS URL to the container. You still have to use some URL Path library to append the name of your .jpg or .png image to the end of that URL, but preserve the query string with the token on it.

    UPDATE: I also created a quick Typescript/Node.js sample to show how to create an Asset with your own container name, and how to get it back. https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Assets/get-container-from-asset.ts

    UPDATE 2: Added another sample for .NET here - https://github.com/Azure-Samples/media-services-v3-dotnet/blob/main/Assets/Program.cs