Skip to content

Instantly share code, notes, and snippets.

@itorian
Last active April 19, 2016 07:20
Show Gist options
  • Save itorian/73a92df9cb5597a0385e6ca911236f11 to your computer and use it in GitHub Desktop.
Save itorian/73a92df9cb5597a0385e6ca911236f11 to your computer and use it in GitHub Desktop.
I received two different error messages (.xml preset and .json preset displays different messages) from azure media services encoder.
{
"Version": 1.0,
"Codecs": [
{
"KeyFrameInterval": "00:00:02",
"H264Layers": [
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 1000,
"MaxBitrate": 1000,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 650,
"MaxBitrate": 650,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 400,
"MaxBitrate": 400,
"BufferWindow": "00:00:05",
"Width": 320,
"Height": 180,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
}
],
"Type": "H264Video"
},
{
"Profile": "AACLC",
"Channels": 2,
"SamplingRate": 48000,
"Bitrate": 128,
"Type": "AACAudio"
}
],
"Outputs": [
{
"FileName": "{Basename}_{Width}x{Height}_{VideoBitrate}.mp4",
"Format": {
"Type": "MP4Format"
}
}
]
}
<?xml version="1.0" encoding="utf-16"?>
<Preset xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0" xmlns="http://www.windowsazure.com/media/encoding/Preset/2014/03">
<Encoding>
<H264Video>
<KeyFrameInterval>00:00:02</KeyFrameInterval>
<H264Layers>
<H264Layer>
<Bitrate>1000</Bitrate>
<Width>640</Width>
<Height>360</Height>
<FrameRate>0/1</FrameRate>
<Profile>Auto</Profile>
<Level>auto</Level>
<BFrames>3</BFrames>
<ReferenceFrames>3</ReferenceFrames>
<Slices>0</Slices>
<AdaptiveBFrame>true</AdaptiveBFrame>
<EntropyMode>Cabac</EntropyMode>
<BufferWindow>00:00:05</BufferWindow>
<MaxBitrate>1000</MaxBitrate>
</H264Layer>
<H264Layer>
<Bitrate>650</Bitrate>
<Width>640</Width>
<Height>360</Height>
<FrameRate>0/1</FrameRate>
<Profile>Auto</Profile>
<Level>auto</Level>
<BFrames>3</BFrames>
<ReferenceFrames>3</ReferenceFrames>
<Slices>0</Slices>
<AdaptiveBFrame>true</AdaptiveBFrame>
<EntropyMode>Cabac</EntropyMode>
<BufferWindow>00:00:05</BufferWindow>
<MaxBitrate>650</MaxBitrate>
</H264Layer>
<H264Layer>
<Bitrate>400</Bitrate>
<Width>320</Width>
<Height>180</Height>
<FrameRate>0/1</FrameRate>
<Profile>Auto</Profile>
<Level>auto</Level>
<BFrames>3</BFrames>
<ReferenceFrames>3</ReferenceFrames>
<Slices>0</Slices>
<AdaptiveBFrame>true</AdaptiveBFrame>
<EntropyMode>Cabac</EntropyMode>
<BufferWindow>00:00:05</BufferWindow>
<MaxBitrate>400</MaxBitrate>
</H264Layer>
</H264Layers>
<Chapters />
</H264Video>
<AACAudio>
<Profile>AACLC</Profile>
<Channels>2</Channels>
<SamplingRate>48000</SamplingRate>
<Bitrate>128</Bitrate>
</AACAudio>
</Encoding>
<Outputs>
<Output FileName="{Basename}_{Width}x{Height}_{VideoBitrate}.mp4">
<MP4Format />
</Output>
</Outputs>
</Preset>
using Microsoft.WindowsAzure.MediaServices.Client;
using System;
using System.Configuration;
using System.IO;
using System.Threading;
namespace OnDemandEncodingWithMES
{
class Program
{
// Read values from the App.config file
private static readonly string _mediaServicesAccountName = ConfigurationManager.AppSettings["MediaServicesAccountName"];
private static readonly string _mediaServicesAccountKey = ConfigurationManager.AppSettings["MediaServicesAccountKey"];
private static readonly string _mediaFiles = Path.GetFullPath(@"../..\Media");
private static readonly string _presetFiles = Path.GetFullPath(@"../..\Presets");
// Field for service context
private static CloudMediaContext _context = null;
private static MediaServicesCredentials _cachedCredentials = null;
static void Main(string[] args)
{
try
{
_cachedCredentials = new MediaServicesCredentials(_mediaServicesAccountName, _mediaServicesAccountKey);
_context = new CloudMediaContext(_cachedCredentials);
Console.WriteLine("Upload video file\n");
IAsset inputAsset = UploadFile(Path.Combine(_mediaFiles, @"TestClip.mp4"), AssetCreationOptions.None);
Console.WriteLine("Encode uploaded file\n");
IAsset encodedAsset = EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.None);
}
catch (Exception exception)
{
exception = MediaServicesExceptionParser.Parse(exception);
Console.Error.WriteLine(exception.Message);
}
finally
{
Console.ReadLine();
}
}
static public IAsset UploadFile(string fileName, AssetCreationOptions options)
{
IAsset inputAsset = _context.Assets.CreateFromFile(
fileName,
options,
(af, p) =>
{
Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
});
Console.WriteLine("Asset {0} created.", inputAsset.Id);
return inputAsset;
}
static public IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions options)
{
/////// XML PRESET FILE
//// Custom preset settings with XML
//// ErrorDetail.Message: A transient error has occurred.We apologize for the inconvenience. Please try again.
//// ErrorDetail.Code: TransientSystem
string configurationXml = File.ReadAllText(Path.Combine(_presetFiles, @"H264MultipleBitrateCustom720p.xml"));
IJob jobXml = _context.Jobs.CreateWithSingleTask(MediaProcessorNames.AzureMediaEncoder,
configurationXml,
asset,
"Test-Video-" + Guid.NewGuid().ToString() + "-Adaptive-Bitrate-MP4",
AssetCreationOptions.None);
Console.WriteLine("Submitting transcoding job using XML preset file\n");
jobXml.Submit();
jobXml = jobXml.StartExecutionProgressTask(
j =>
{
Console.WriteLine("Job state: {0}", j.State);
// Error handling
if (j.State == JobState.Error)
{
foreach (var task in jobXml.Tasks)
{
if (task.ErrorDetails != null)
{
foreach (var errordetail in task.ErrorDetails)
{
Console.WriteLine("ErrorDetail Message:" + errordetail.Message);
Console.WriteLine("ErrorDetail Code:" + errordetail.Code);
}
}
}
}
Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
},
CancellationToken.None).Result;
Console.WriteLine("Transcoding job of XML preset end.");
/////// JSON PRESET FILE
//// Custom preset settings with JSON
//// ErrorDetail.Message: The preset submitted for this Azure Media Encoder Task is invalid
//// ErrorDetail.Code: ErrorParsingConfiguration
string configurationJson = File.ReadAllText(Path.Combine(_presetFiles, @"H264MultipleBitrateCustom720p.json"));
IJob jobJson = _context.Jobs.CreateWithSingleTask(MediaProcessorNames.AzureMediaEncoder,
configurationJson,
asset,
"Test-Video-" + Guid.NewGuid().ToString() + "-Adaptive-Bitrate-MP4",
AssetCreationOptions.None);
Console.WriteLine("\nSubmitting transcoding job using JSON preset file\n");
jobJson.Submit();
jobJson = jobJson.StartExecutionProgressTask(
j =>
{
Console.WriteLine("Job state: {0}", j.State);
// Error handling
if (j.State == JobState.Error)
{
foreach (var task in jobJson.Tasks)
{
if (task.ErrorDetails != null)
{
foreach (var errordetail in task.ErrorDetails)
{
Console.WriteLine("ErrorDetail Message:" + errordetail.Message);
Console.WriteLine("ErrorDetail Code:" + errordetail.Code);
}
}
}
}
Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
},
CancellationToken.None).Result;
Console.WriteLine("Transcoding job of JSON preset end.");
IAsset outputAsset = jobJson.OutputMediaAssets[0];
return outputAsset;
}
}
}
@itorian
Copy link
Author

itorian commented Apr 19, 2016

I noticed the difference in error message and thought to draft it so that you can discover and resolve it easily. Here is the output of above code:

different error message for same bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment