0

I'm trying to use a Image Thumbnail from a Video on Azure Media Service. I can't understand if a thumbnail is made automatically And if so - then what is the URI for it.

Documentation talks about 'Thumbnail Collections' in AssetFile - but I can't find anything further.

Any ideas?

Thanks

Drew
  • 24,851
  • 10
  • 43
  • 78
ActionFactory
  • 1,393
  • 2
  • 12
  • 19

1 Answers1

0

Here is a sample code to add thumbnail task to encoding job

ITask task = job.Tasks.AddNew("My thumbnail task",
    processor,
    "Thumbnails",
    TaskOptions.None);

You can control thumbnail task parameters by using xml preset instead of system named pereset. I pasted it from sdk github repo file Jobtests.cs

    string presetXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
                    <Thumbnail Size=""80,60"" Type=""Jpeg"" Filename=""{OriginalFilename}_{ThumbnailTime}.{DefaultExtension}"">
                      <Time Value=""0:0:0""/>
                      <Time Value=""0:0:3"" Step=""0:0:0.25"" Stop=""0:0:10""/>
                    </Thumbnail>";

IJob job = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, presetXml, asset, TaskOptions.None);
    var task = job.Tasks.First();
    var asset = task.OutputAssets.First();
    var files = asset.AssetFiles.ToList();

Run test ShouldFinishJobWithSuccessWhenPresetISUTF8() which is using thumbnail preset and you will find that job generates 1 output asset which will have around 30 files. To download these files you can simply call Download or DownloadAsync.

files[0].Download() 

If you need to get url for selected file you can execute following code:

var accessPolicy = mediaContext.AccessPolicies.Create("12HoursRead", TimeSpan.FromHours(12), AccessPermissions.Read);

//Creating read-only access url which will be available for 12 hours 
var locator = mediaContext.Locators.CreateSasLocator(asset, accessPolicy);

//Getting url for first file in collection
UriBuilder uriBuilder = new UriBuilder(locator.BaseUri);
uriBuilder.Path += String.Concat("/", files[0].Name);

Please note that all Azure media asset files are stored in Azure Storage. If you have high volume website, it will be better to download thumbnails from storage and publish them through CDN.

MSDN docs related to thumbnail preset

George Trifonov
  • 1,971
  • 17
  • 20