We use azure media server for encoding and generating thumbnail. We have the following code for a combined task for encoding and generating thumbnail
IJob job = _context.Jobs.Create(filename + " - Media Encoder Standard");
IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard");
ITask task = job.Tasks.AddNew("Media Encoder Standard", processor, "H264 Single Bitrate 720p for Android", options);
// Specify the input asset to be encoded.
task.InputAssets.Add(asset);
task.OutputAssets.AddNew("Output asset",
AssetCreationOptions.None);
task = job.Tasks.AddNew("Media Encoder Standard", processor, configuration, options);
// Specify the input asset to be encoded.
task.InputAssets.Add(asset);
task.OutputAssets.AddNew("Output asset",
AssetCreationOptions.None);
// Submit the job and wait until it is completed.
job.Submit();
job = job.StartExecutionProgressTask(
j =>
{
},
CancellationToken.None).Result;
Console.WriteLine("Transcoding job finished.");
var outputAssets = job.OutputMediaAssets.ToList();
return outputAssets;
However if the thumbnail task fails and the video encoding goes through. We still generate a url for the video.
we use the following code for generating the url
public string PublishAssetGetURLs(IAsset asset, string fileExt = "")
{
// Publish the output asset by creating an Origin locator for adaptive streaming,
// and a SAS locator for progressive download.
_context.Locators.Create(
LocatorType.Sas,
asset,
AccessPermissions.Read,
TimeSpan.FromDays(365));
IEnumerable<IAssetFile> assetFiles = asset
.AssetFiles
.ToList()
.Where(af => af.Name.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase));
// Get the URls for progressive download for each specified file that was generated as a result
// of encoding.
List<Uri> sasUris = assetFiles.Select(af => af.GetSasUri()).ToList();
var url = sasUris.FirstOrDefault();
if (url != null)
{
return url.ToString();
}
return string.Empty;
}
However when the url is used we get the following xml
<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:a6d14469-0001-0008-7bdb-1f3b8a000000
Time:2017-08-28T08:58:17.0773123Z</Message><AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail></Error>
It works fine if both tasks are success. Do I need to set something on the asset or something?
Apparantly I was wrong about my assumption. It was only sometimes i would break. It was caused by the url created by the sas locator. Sometimes it would have a + char and that would lead to the error. However if it was encoded it worked like a charm. I need more coffee