// </CreateOutputAsset> /// <summary> /// If the specified transform exists, get that transform. /// If the it does not exist, creates a new transform with the specified output. /// In this case, the output is set to encode a video using one of the built-in encoding presets. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="transformName">The name of the transform.</param> /// <returns></returns> // <EnsureTransformExists> private static async Task <Transform> GetOrCreateTransformAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. Transform transform = await client.Transforms.GetAsync(resourceGroupName, accountName, transformName); if (transform == null) { // You need to specify what you want it to produce as an output TransformOutput[] output = new TransformOutput[] { new TransformOutput { // The preset for the Transform is set to one of Media Services built-in sample presets. // You can customize the encoding settings by changing this to use "StandardEncoderPreset" class. Preset = new BuiltInStandardEncoderPreset() { // This sample uses the built-in encoding preset for Adaptive Bitrate Streaming. PresetName = EncoderNamedPreset.AdaptiveStreaming } } }; // Create the Transform with the output defined above transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, output); } return(transform); }
private static async Task <Transform> GetOrCreateTransformAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { Transform transform = await client.Transforms.GetAsync(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] output = new TransformOutput[] { new TransformOutput { Preset = new BuiltInStandardEncoderPreset() { PresetName = EncoderNamedPreset.AdaptiveStreaming } } }; transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, output); } return(transform); }
/// <summary> /// If the specified transform exists, get that transform. /// If the it does not exist, creates a new transform with the specified output. /// In this case, the output is set to encode a video using one of the built-in encoding presets. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="transformName">The name of the transform.</param> /// <returns></returns> private static async Task <Transform> GetOrCreateTransformAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { // You need to specify what you want it to produce as an output TransformOutput[] output = new TransformOutput[] { new TransformOutput { // The preset for the Transform is set to one of Media Services built-in sample presets. // You can customize the encoding settings by changing this to use "StandardEncoderPreset" class. Preset = new BuiltInStandardEncoderPreset() { // This sample uses the built-in encoding preset for Adaptive Bit-rate Streaming. PresetName = EncoderNamedPreset.AdaptiveStreaming } } }; // Does a Transform already exist with the desired name? This method will just overwrite (Update) the Transform if it exists already. // In production code, you may want to be cautious about that. It really depends on your scenario. Transform transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, output); return(transform); }
public async Task <Transform> EnsureTransformExistsAsync(CancellationToken cancellationToken) { var client = await GetAzureMediaServicesClientAsync(); var transform = await client.Transforms.GetAsync(_settings.ResourceGroup, _settings.AccountName, _settings.MediaServicesTransform, cancellationToken); if (transform == null) { // https://docs.microsoft.com/en-us/rest/api/media/transforms/createorupdate TransformOutput[] outputs = new TransformOutput[] { new TransformOutput( new StandardEncoderPreset { Codecs = new Codec[] { // AAC Audio layer for the audio encoding new AacAudio { Channels = 2, SamplingRate = 48000, Bitrate = 128000, Profile = AacAudioProfile.AacLc }, // H264Video for the video encoding new H264Video { Complexity = H264Complexity.Quality, KeyFrameInterval = TimeSpan.FromSeconds(2), Layers = new H264Layer[] { new H264Layer { Bitrate = 1000000, // Units are in bits per second Width = "1280", Height = "720" } } } }, Formats = new Format[] { new Mp4Format { FilenamePattern = "{Basename}{Extension}" } } }, OnErrorType.StopProcessingJob, Priority.Normal ) }; string description = "A simple custom encoding transform with 2 MP4 bitrates"; transform = await client.Transforms.CreateOrUpdateAsync(_settings.ResourceGroup, _settings.AccountName, _settings.MediaServicesTransform, outputs, description, cancellationToken); } return(transform); }
/// <inheritdoc cref="MediaServicesV3TransformBase"/> protected override void Create() { Codec[] codecs = GetCodecs(); Format[] formats = GetFormats(); TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(new StandardEncoderPreset(codecs: codecs, formats: formats)) }; Output = new MediaServicesV3TransformOutput(outputs, Description); }
/// <summary> /// If the specified transform exists, return that transform. If the it does not /// exist, creates a new transform with the specified output. In this case, the /// output is set to encode a video using a predefined preset. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="log">Function logger.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="transformName">The transform name.</param> /// <param name="builtInPreset">The built in standard encoder preset to use if the transform is created.</param> /// <returns></returns> private static async Task<Transform> CreateEncodingTransform(IAzureMediaServicesClient client, ILogger log, string resourceGroupName, string accountName, string transformName, string builtInPreset) { bool createTransform = false; Transform transform = null; try { // Does a transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. transform = client.Transforms.Get(resourceGroupName, accountName, transformName); } catch (ErrorResponseException ex) when (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { createTransform = true; log.LogInformation("Transform not found."); } if (createTransform) { log.LogInformation($"Creating transform '{transformName}'..."); // Create a new Transform Outputs array - this defines the set of outputs for the Transform TransformOutput[] outputs = new TransformOutput[] { // Create a new TransformOutput with a custom Standard Encoder Preset // This demonstrates how to create custom codec and layer output settings new TransformOutput( new BuiltInStandardEncoderPreset() { // Pass the buildin preset name. PresetName = builtInPreset }, onError: OnErrorType.StopProcessingJob, relativePriority: Priority.Normal ) }; string description = $"An encoding transform using {builtInPreset} preset"; // Create the Transform with the outputs defined above transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs, description); } else { log.LogInformation($"Transform '{transformName}' found in AMS account."); } return transform; }
private static Transform EnsureTransformExists(IAzureMediaServicesClient client, string location, string transformName, Preset preset) { Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(preset), }; transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, outputs); } return(transform); }
private IList <JobOutput> GetJobOutputs(string transformName, MediaJob mediaJob) { List <JobOutputAsset> outputAssets = new List <JobOutputAsset>(); Transform transform = GetEntity <Transform>(MediaEntity.Transform, transformName); for (int i = 0; i < transform.Outputs.Count; i++) { TransformOutput transformOutput = transform.Outputs[i]; string outputAssetName = GetOutputAssetName(transformOutput, mediaJob, out string outputAssetStorage); string assetDescription = i > mediaJob.OutputAssetDescriptions.Length - 1 ? null : mediaJob.OutputAssetDescriptions[i]; string assetAlternateId = i > mediaJob.OutputAssetAlternateIds.Length - 1 ? null : mediaJob.OutputAssetAlternateIds[i]; CreateAsset(outputAssetStorage, outputAssetName, assetDescription, assetAlternateId); JobOutputAsset outputAsset = new JobOutputAsset(outputAssetName); outputAssets.Add(outputAsset); } return(outputAssets.ToArray()); }
private void ListBoxOutputs_SelectedIndexChanged(object sender, EventArgs e) { TransformOutput output = _transform.Outputs.Skip(listBoxOutputs.SelectedIndex).Take(1).FirstOrDefault(); DGOutputs.Rows.Clear(); DGOutputs.Rows.Add("Preset type", output.Preset.GetType().ToString()); var presetRest = _transformRest.Properties.Outputs.Skip(listBoxOutputs.SelectedIndex).Take(1).FirstOrDefault().Preset; string presetJson = JsonConvert.SerializeObject(presetRest, Formatting.Indented); /* * if (output.Preset.GetType() == typeof(BuiltInStandardEncoderPreset)) * { * BuiltInStandardEncoderPreset pmes = (BuiltInStandardEncoderPreset)output.Preset; * presetJson = JsonConvert.SerializeObject(pmes, Newtonsoft.Json.Formatting.Indented); * } * else if (output.Preset.GetType() == typeof(AudioAnalyzerPreset)) * { * AudioAnalyzerPreset pmes = (AudioAnalyzerPreset)output.Preset; * presetJson = JsonConvert.SerializeObject(pmes, Newtonsoft.Json.Formatting.Indented); * } * else if (output.Preset.GetType() == typeof(StandardEncoderPreset)) * { * StandardEncoderPreset pmes = (StandardEncoderPreset)output.Preset; * presetJson = JsonConvert.SerializeObject(pmes, Newtonsoft.Json.Formatting.Indented); * } * else if (output.Preset.GetType() == typeof(VideoAnalyzerPreset)) * { * VideoAnalyzerPreset pmes = (VideoAnalyzerPreset)output.Preset; * presetJson = JsonConvert.SerializeObject(pmes, Newtonsoft.Json.Formatting.Indented); * } * else if (output.Preset.GetType() == typeof(FaceDetectorPreset)) * { * FaceDetectorPreset pmes = (FaceDetectorPreset)output.Preset; * presetJson = JsonConvert.SerializeObject(pmes, Newtonsoft.Json.Formatting.Indented); * } * else * { * presetJson = JsonConvert.SerializeObject(output.Preset, Newtonsoft.Json.Formatting.Indented); * } */ textBoxPresetJson.Text = presetJson; DGOutputs.Rows.Add("Relative Priority", output.RelativePriority); }
/// <summary> /// If the specified transform exists, get that transform. /// If the it does not exist, creates a new transform with the specified output. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName"> The Media Services account name.</param> /// <param name="transformName">The name of the transform.</param> /// <returns></returns> private static async Task <Transform> GetOrCreateTransformAsync(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName, Preset preset) { // Start by defining the desired outputs. TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(preset), }; // Does a Transform already exist with the desired name? This method will just overwrite (Update) the Transform if it exists already. // In production code, you may want to be cautious about that. It really depends on your scenario. Transform transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs); return(transform); }
/// <summary> /// If the specified transform exists, get that transform. If the it does not exist, creates a new transform /// with the specified output. In this case, the output is set to encode a video using the passed in preset. /// </summary> /// <param name="client">The Media Services client.</param> /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param> /// <param name="accountName">The Media Services account name.</param> /// <param name="transformName">The name of the transform.</param> /// <param name="preset">The preset.</param> /// <returns>The transform found or created.</returns> private static async Task <Transform> EnsureTransformExists(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName, Preset preset) { Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(preset), }; Console.WriteLine("Creating a transform..."); transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs); } return(transform); }
/// <summary> /// Checks if transform exists, if not, creates transform /// </summary> /// <param name="client">Azure Media Services instance client</param> /// <param name="resourceGroupName">Azure resource group</param> /// <param name="accountName">Azure Media Services instance account name</param> /// <param name="transformName">Transform name</param> /// <param name="preset">transform preset object</param> /// <returns></returns> public static async Task <Transform> EnsureTransformExists(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName, Preset preset) { if (client == null) { throw new ArgumentNullException(nameof(client)); } // create output with given preset var outputs = new TransformOutput[] { new TransformOutput(preset) }; // create new transform Transform transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs).ConfigureAwait(false); return(transform); }
private Transform EnsureTransformExists(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)), new TransformOutput(new VideoAnalyzerPreset()), }; transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, outputs); Console.WriteLine("AMSv3 Transform has been created: ", transformName); } return(transform); }
public static Transform EnsureTransformExists(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName, Preset preset) { // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { // Start by defining the desired outputs. TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(preset), }; // Create the Transform with the output defined above transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, outputs); } return(transform); }
public static Transform EnsureEncoderTransformExists(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName, EncoderNamedPreset preset, TraceWriter log) { Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] output = new TransformOutput[] { new TransformOutput { Preset = new BuiltInStandardEncoderPreset() { PresetName = preset } } }; transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, output); } return(transform); }
private string GetOutputAssetName(TransformOutput transformOutput, MediaJob mediaJob, out string outputAssetStorage) { outputAssetStorage = this.PrimaryStorageAccount; string outputAssetName = mediaJob.InputAssetName; if (!string.IsNullOrEmpty(mediaJob.InputFileUrl) && string.IsNullOrEmpty(outputAssetName)) { Uri inputFileUri = new Uri(mediaJob.InputFileUrl); outputAssetName = Path.GetFileNameWithoutExtension(inputFileUri.LocalPath); } else if (!string.IsNullOrEmpty(mediaJob.InputAssetName)) { Asset inputAsset = GetEntity <Asset>(MediaEntity.Asset, mediaJob.InputAssetName); outputAssetStorage = inputAsset.StorageAccountName; } switch (mediaJob.OutputAssetMode) { case MediaJobOutputMode.SingleAsset: outputAssetName = string.Concat(outputAssetName, " (", Constant.Media.Job.OutputAssetNameSuffix.Default, ")"); break; case MediaJobOutputMode.DistinctAssets: string assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.Default; if (transformOutput.Preset is BuiltInStandardEncoderPreset) { assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.AdaptiveStreaming; } else if (transformOutput.Preset is VideoAnalyzerPreset) { assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.VideoAnalyzer; } else if (transformOutput.Preset is AudioAnalyzerPreset) { assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.AudioAnalyzer; } outputAssetName = string.Concat(outputAssetName, " (", assetNameSuffix, ")"); break; } return(outputAssetName); }
private static async Task <Transform> GetOrCreateTransformAsync(IAzureMediaServicesClient client, string transformName) { // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. Transform transform = await client.Transforms.GetAsync(ResourceGroup, AccountName, transformName); if (transform == null) { // You need to specify what you want it to produce as an output TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)), new TransformOutput(new VideoAnalyzerPreset()) }; // Create the Transform with the output defined above transform = await client.Transforms.CreateOrUpdateAsync(ResourceGroup, AccountName, transformName, outputs); } return(transform); }
private async Task EnsureTransformExists() { // get transform by name var transform = await _amsClient.Transforms.GetAsync( _amsSettings.ResourceGroup, _amsSettings.AccountName, _amsSettings.TransformName); // if it doesn't exist, create it if (transform == null) { var transformOutput = new TransformOutput[] { new TransformOutput { Preset = new StandardEncoderPreset() { Codecs = new Codec[] { new AacAudio(channels: 2, samplingRate: 44100, bitrate: 128000, profile: AacAudioProfile.AacLc) }, Formats = new Format[] { new Mp4Format("{Basename}-{Bitrate}{Extension}") } }, OnError = OnErrorType.StopProcessingJob, RelativePriority = Priority.Normal }, }; transform = await _amsClient.Transforms.CreateOrUpdateAsync( _amsSettings.ResourceGroup, _amsSettings.AccountName, _amsSettings.TransformName, transformOutput); } }
private static async Task <Transform> GetOrCreateTransformAsync( IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { Transform transform = await client.Transforms.GetAsync(resourceGroupName, accountName, transformName); if (transform == null) { TransformOutput[] output = new TransformOutput[] { new TransformOutput { } }; transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, output); } return(transform); }
private void listBoxOutputs_SelectedIndexChanged(object sender, EventArgs e) { TransformOutput output = _transform.Outputs.Skip(listBoxOutputs.SelectedIndex).Take(1).FirstOrDefault(); DGOutputs.Rows.Clear(); DGOutputs.Rows.Add("Preset type", output.Preset.GetType().ToString()); if (output.Preset.GetType() == typeof(BuiltInStandardEncoderPreset)) { BuiltInStandardEncoderPreset pmes = (BuiltInStandardEncoderPreset)output.Preset; DGOutputs.Rows.Add("Preset name", pmes.PresetName); } else if (output.Preset.GetType() == typeof(AudioAnalyzerPreset)) { AudioAnalyzerPreset pmes = (AudioAnalyzerPreset)output.Preset; DGOutputs.Rows.Add("Audio language", pmes.AudioLanguage); } else if (output.Preset.GetType() == typeof(StandardEncoderPreset)) { StandardEncoderPreset pmes = (StandardEncoderPreset)output.Preset; // DGOutputs.Rows.Add("Audio language", pmes.); } else if (output.Preset.GetType() == typeof(VideoAnalyzerPreset)) { VideoAnalyzerPreset pmes = (VideoAnalyzerPreset)output.Preset; DGOutputs.Rows.Add("Audio language", pmes.AudioLanguage); DGOutputs.Rows.Add("Insights To Extract", pmes.InsightsToExtract); } else if (output.Preset.GetType() == typeof(FaceDetectorPreset)) { FaceDetectorPreset pmes = (FaceDetectorPreset)output.Preset; DGOutputs.Rows.Add("Resolution", pmes.Resolution.HasValue ? pmes.Resolution.Value.ToString() : string.Empty); } DGOutputs.Rows.Add("Relative Priority", output.RelativePriority); }
/// <summary> /// Connects to the Azure Media Service /// </summary> /// <returns>Generic asynchronous operation that returns type IAzureMediaServicesClient</returns> public static async Task <IAzureMediaServicesClient> Connect(string TransformName = "transformName") { _client = await ClientService(); _encoding = await _client.Transforms.GetAsync(_configuration.ResourceGroup, _configuration.AccountName, TransformName); _client.LongRunningOperationRetryTimeout = 2; if (_encoding == null) { TransformOutput [] output = new TransformOutput [] { new TransformOutput { Preset = new BuiltInStandardEncoderPreset() { PresetName = EncoderNamedPreset.AdaptiveStreaming } } }; _encoding = await _client.Transforms.CreateOrUpdateAsync(_configuration.ResourceGroup, _configuration.AccountName, TransformName, output); } return(_client); }
public static TransformOutput[] CustomEncode_HD_SD_Thumb() { TransformOutput[] outputs = new TransformOutput[] { new TransformOutput( new StandardEncoderPreset( codecs: new Codec[] { // Add an AAC Audio layer for the audio encoding //new AacAudio( // channels: 2, // samplingRate: 48000, // bitrate: 128000, // profile: AacAudioProfile.AacLc //), // Next, add a H264Video for the video encoding new H264Video( // Set the GOP interval to 2 seconds for both H264Layers keyFrameInterval: TimeSpan.FromSeconds(2), // Add H264Layers, one at HD and the other at SD. Assign a label that you can use for the output filename layers: new H264Layer[] { new H264Layer( bitrate: 1500000, // Note that the units is in bits per second width: "1920", height: "1080", label: "HD-1080" // This label is used to modify the file name in the output formats ), new H264Layer( bitrate: 1000000, // Note that the units is in bits per second width: "1280", height: "720", label: "HD-720" // This label is used to modify the file name in the output formats ), new H264Layer( bitrate: 600000, width: "960", height: "540", label: "SD-540" ) } ), // Also generate a set of PNG thumbnails new JpgImage( start: "25%", step: "25%", range: "80%", layers: new JpgLayer[] { new JpgLayer( width: "50%", height: "50%" ) } ) }, // Specify the format for the output files - one for video+audio, and another for the thumbnails formats: new Format[] { // Mux the H.264 video and AAC audio into MP4 files, using basename, label, bitrate and extension macros // Note that since you have multiple H264Layers defined above, you have to use a macro that produces unique names per H264Layer // Either {Label} or {Bitrate} should suffice new Mp4Format( filenamePattern: "Video-{Basename}-{Label}-{Bitrate}{Extension}" ), new JpgFormat( filenamePattern: "Thumbnail-{Basename}-{Index}{Extension}" ) } ), onError: OnErrorType.StopProcessingJob, relativePriority: Priority.Normal ) }; return(outputs); }
public void JobComboTest() { using (MockContext context = this.StartMockContextAndInitializeClients(this.GetType())) { try { string transformName = TestUtilities.GenerateName("transform"); string transformDescription = "A test transform"; string jobName = TestUtilities.GenerateName("job"); string outputAssetName = TestUtilities.GenerateName("outputAsset"); CreateMediaServicesAccount(); // Create a transform as it is the parent of Jobs TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)) }; Transform transform = MediaClient.Transforms.CreateOrUpdate(ResourceGroup, AccountName, transformName, outputs, transformDescription); // List jobs, which should be empty var jobs = MediaClient.Jobs.List(ResourceGroup, AccountName, transformName); Assert.Empty(jobs); // Try to get the job, which should not exist Job job = MediaClient.Jobs.Get(ResourceGroup, AccountName, transformName, jobName); Assert.Null(job); // Create a job using an input from an HTTP url and an output to an Asset Asset outputAsset = MediaClient.Assets.CreateOrUpdate(ResourceGroup, AccountName, outputAssetName, new Asset()); JobInputHttp jobInputHttp = new JobInputHttp(files: new string[] { "https://amssamples.streaming.mediaservices.windows.net/2e91931e-0d29-482b-a42b-9aadc93eb825/AzurePromo.mp4" }); JobInputs jobInputs = new JobInputs(inputs: new JobInput[] { jobInputHttp }); JobOutputAsset jobOutput = new JobOutputAsset(outputAssetName); JobOutput[] jobOutputs = new JobOutput[] { jobOutput }; Job input = new Job(jobInputs, jobOutputs); Job createdJob = MediaClient.Jobs.Create(ResourceGroup, AccountName, transformName, jobName, input); ValidateJob(createdJob, jobName, null, jobInputs, jobOutputs); // List jobs and validate the created job shows up jobs = MediaClient.Jobs.List(ResourceGroup, AccountName, transformName); Assert.Single(jobs); ValidateJob(jobs.First(), jobName, null, jobInputs, jobOutputs); // Get the newly created job job = MediaClient.Jobs.Get(ResourceGroup, AccountName, transformName, jobName); Assert.NotNull(job); ValidateJob(job, jobName, null, jobInputs, jobOutputs); // If the job isn't already finished, cancel it if (job.State != JobState.Finished) { MediaClient.Jobs.CancelJob(ResourceGroup, AccountName, transformName, jobName); do { System.Threading.Thread.Sleep(15 * 1000); job = MediaClient.Jobs.Get(ResourceGroup, AccountName, transformName, jobName); }while (job.State != JobState.Finished && job.State != JobState.Canceled); } // Delete the job MediaClient.Jobs.Delete(ResourceGroup, AccountName, transformName, jobName); // List jobs, which should be empty again jobs = MediaClient.Jobs.List(ResourceGroup, AccountName, transformName); Assert.Empty(jobs); // Try to get the job, which should not exist job = MediaClient.Jobs.Get(ResourceGroup, AccountName, transformName, jobName); Assert.Null(job); // Delete the transform MediaClient.Transforms.Delete(ResourceGroup, AccountName, transformName); } finally { DeleteMediaServicesAccount(); } } }
public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { log.Info($"AMS v3 Function - create_transform was triggered!"); string jsonContent = await req.Content.ReadAsStringAsync(); dynamic data = JsonConvert.DeserializeObject(jsonContent); // Validate input objects if (data.transformName == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass transformName in the input object" })); } if (data.builtInStandardEncoderPreset == null && data.videoAnalyzerPreset == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass preset in the input object" })); } string transformName = data.transformName; MediaServicesConfigWrapper amsconfig = new MediaServicesConfigWrapper(); string transformId = null; try { IAzureMediaServicesClient client = CreateMediaServicesClient(amsconfig); // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. Transform transform = client.Transforms.Get(amsconfig.ResourceGroup, amsconfig.AccountName, transformName); if (transform == null) { // Create a new Transform Outputs array - this defines the set of outputs for the Transform TransformOutput[] outputs = new TransformOutput[] { new TransformOutput( new StandardEncoderPreset( codecs: new Codec[] { // Add an AAC Audio layer for the audio encoding new AacAudio( channels: 1, samplingRate: 48000, bitrate: 64000, profile: AacAudioProfile.AacLc ), // Next, add a H264Video for the video encoding new H264Video( // Set the GOP interval to 2 seconds for both H264Layers keyFrameInterval: TimeSpan.FromSeconds(2), stretchMode: StretchMode.None, // Add H264Layers, one at HD and the other at SD. Assign a label that you can use for the output filename layers: new H264Layer[] { new H264Layer( bitrate: 1000000, maxBitrate: 1000000, label: "HD", bufferWindow: TimeSpan.FromSeconds(5), width: "1080", height: "720", referenceFrames: 3, entropyMode: "Cabac", adaptiveBFrame: true, frameRate: "0/1" ), new H264Layer( bitrate: 750000, maxBitrate: 750000, label: "SD", bufferWindow: TimeSpan.FromSeconds(5), width: "720", height: "480", referenceFrames: 3, entropyMode: "Cabac", adaptiveBFrame: true, frameRate: "0/1" ), new H264Layer( bitrate: 500000, maxBitrate: 500000, label: "HD", bufferWindow: TimeSpan.FromSeconds(5), width: "540", height: "360", referenceFrames: 3, entropyMode: "Cabac", adaptiveBFrame: true, frameRate: "0/1" ), new H264Layer( bitrate: 200000, maxBitrate: 200000, label: "HD", bufferWindow: TimeSpan.FromSeconds(5), width: "360", height: "240", referenceFrames: 3, entropyMode: "Cabac", adaptiveBFrame: true, frameRate: "0/1" ) } ), }, // Specify the format for the output files - one for video+audio, and another for the thumbnails formats: new Format[] { // Mux the H.264 video and AAC audio into MP4 files, using basename, label, bitrate and extension macros // Note that since you have multiple H264Layers defined above, you have to use a macro that produces unique names per H264Layer // Either {Label} or {Bitrate} should suffice new Mp4Format( filenamePattern: "Video-{Basename}-{Label}-{Bitrate}{Extension}" ) //,new PngFormat( // filenamePattern:"Thumbnail-{Basename}-{Index}{Extension}" //) } ), onError: OnErrorType.StopProcessingJob, relativePriority: Priority.Normal ) }; string description = "A simple custom encoding transform with 2 MP4 bitrates"; // Create the custom Transform with the outputs defined above transform = client.Transforms.CreateOrUpdate(amsconfig.ResourceGroup, amsconfig.AccountName, transformName, outputs, description); transformId = transform.Id; } } catch (ApiErrorException e) { log.Info($"ERROR: AMS API call failed with error code: {e.Body.Error.Code} and message: {e.Body.Error.Message}"); return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "AMS API call error: " + e.Message })); } return(req.CreateResponse(HttpStatusCode.OK, new { transformId = transformId })); }
public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { log.Info($"AMS v3 Function - create_transform was triggered!"); string jsonContent = await req.Content.ReadAsStringAsync(); dynamic data = JsonConvert.DeserializeObject(jsonContent); // Validate input objects if (data.transformName == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass transformName in the input object" })); } if (data.builtInStandardEncoderPreset == null && data.videoAnalyzerPreset == null) { return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass preset in the input object" })); } string transformName = data.transformName; MediaServicesConfigWrapper amsconfig = new MediaServicesConfigWrapper(); string transformId = null; try { IAzureMediaServicesClient client = CreateMediaServicesClient(amsconfig); // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. Transform transform = client.Transforms.Get(amsconfig.ResourceGroup, amsconfig.AccountName, transformName); if (transform == null) { // You need to specify what you want it to produce as an output var transformOutputList = new List <TransformOutput>(); // BuiltInStandardEncoderPreset if (data.builtInStandardEncoderPreset != null) { EncoderNamedPreset preset = EncoderNamedPreset.AdaptiveStreaming; if (data.builtInStandardEncoderPreset.presetName != null) { string presetName = data.builtInStandardEncoderPreset.presetName; if (encoderPreset.ContainsKey(presetName)) { preset = encoderPreset[presetName]; } } TransformOutput encoderTransform = new TransformOutput { // The preset for the Transform is set to one of Media Services built-in sample presets. // You can customize the encoding settings by changing this to use "StandardEncoderPreset" class. Preset = new BuiltInStandardEncoderPreset() { // This sample uses the built-in encoding preset for Adaptive Bitrate Streaming. PresetName = preset } }; transformOutputList.Add(encoderTransform); } // VideoAnalyzerPreset if (data.builtInStandardEncoderPreset != null) { bool audioInsightsOnly = false; string audioLanguage = "en-US"; if (data.videoAnalyzerPreset.audioInsightsOnly != null) { audioInsightsOnly = data.videoAnalyzerPreset.audioInsightsOnly; } if (data.videoAnalyzerPreset.audioLanguage != null) { audioLanguage = data.videoAnalyzerPreset.audioLanguage; } TransformOutput encoderTransform = new TransformOutput { // The preset for the Transform is set to one of Media Services built-in sample presets. // You can customize the encoding settings by changing this to use "StandardEncoderPreset" class. Preset = new VideoAnalyzerPreset(audioLanguage, audioInsightsOnly) }; transformOutputList.Add(encoderTransform); } // You need to specify what you want it to produce as an output TransformOutput[] output = transformOutputList.ToArray(); // Create the Transform with the output defined above transform = client.Transforms.CreateOrUpdate(amsconfig.ResourceGroup, amsconfig.AccountName, transformName, output); transformId = transform.Id; } } catch (ApiErrorException e) { log.Info($"ERROR: AMS API call failed with error code: {e.Body.Error.Code} and message: {e.Body.Error.Message}"); return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "AMS API call error: " + e.Message })); } return(req.CreateResponse(HttpStatusCode.OK, new { transformId = transformId })); }
private async Task <Transform> EnsureTransformExistsAsync(IAzureMediaServicesClient client, string resourceGroupName, string accountName, string transformName) { // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name // also uses the same recipe or Preset for processing content. var transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { // Create a new Transform Outputs array - this defines the set of outputs for the Transform TransformOutput[] outputs = new TransformOutput[] { // Create a new TransformOutput with a custom Standard Encoder Preset // This demonstrates how to create custom codec and layer output settings new TransformOutput( new StandardEncoderPreset( codecs: new Codec[] { // Add an AAC Audio layer for the audio encoding new AacAudio( channels: 2, samplingRate: 48000, bitrate: 128000, profile: AacAudioProfile.AacLc ), // Next, add a H264Video for the video encoding new H264Video( // Set the GOP interval to 2 seconds for both H264Layers keyFrameInterval: TimeSpan.FromSeconds(2), // Add H264Layers, one at HD and the other at SD. Assign a label that you can use for the output filename layers: new H264Layer[] { new H264Layer( bitrate: 1000000, // Note that the units is in bits per second width: "1280", height: "720", label: "HD" // This label is used to modify the file name in the output formats ), new H264Layer( bitrate: 600000, width: "640", height: "480", label: "SD" ) } ), // Also generate a set of PNG thumbnails new PngImage( start: "25%", step: "25%", range: "80%", layers: new PngLayer[] { new PngLayer( width: "50%", height: "50%" ) } ) }, // Specify the format for the output files - one for video+audio, and another for the thumbnails formats: new Format[] { // Mux the H.264 video and AAC audio into MP4 files, using basename, label, bitrate and extension macros // Note that since you have multiple H264Layers defined above, you have to use a macro that produces unique names per H264Layer // Either {Label} or {Bitrate} should suffice new Mp4Format( filenamePattern: "Video-{Basename}-{Label}-{Bitrate}{Extension}" ), new PngFormat( filenamePattern: "Thumbnail-{Basename}-{Index}{Extension}" ) } ), onError: OnErrorType.StopProcessingJob, relativePriority: Priority.Normal ) }; string description = "A simple custom encoding transform with 2 MP4 bitrates"; // Create the custom Transform with the outputs defined above transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, outputs, description); } return(transform); }
private static Transform EnsureTransformExists(IAzureMediaServicesClient client, string location, string transformName) { Transform transform = client.Transforms.Get(resourceGroupName, accountName, transformName); if (transform == null) { // Create a new Transform Outputs array - this defines the set of outputs for the Transform TransformOutput[] outputs = new TransformOutput[] { // Create a new TransformOutput with a custom Standard Encoder Preset // This demonstrates how to create custom codec and layer output settings new TransformOutput(new StandardEncoderPreset() { Codecs = new List <Codec> { // Add an AAC Audio layer new AacAudio(), // Add two H264 video encoding layers new H264Video { Layers = new List <H264Layer> { new H264Layer { Width = "1280", Height = "720", Bitrate = 1000000, Label = "HD" }, new H264Layer { Width = "640", Height = "480", Bitrate = 600000, Label = "SD" } } }, // Add a thumbnail image layer that outputs a range of thumbnails new PngImage { Start = "25%", Step = "25%", Range = "80%", Layers = new List <PngLayer> { new PngLayer { Width = "50%", Height = "50%" } } } }, Formats = new List <Format> { // Write the Video file to MP4 file format using the {Basename}, {Label}, {Bitrate} and file {Extension} macros // Note that if you have multiple layers defined above, you have to use a macro that produces unique names. new Mp4Format() { FilenamePattern = "Video-{Basename}-{Label}-{Bitrate}{Extension}" }, // Write the Thumbnails out using the basename, index and extension macros new PngFormat { FilenamePattern = "Thumbnail-{Basename}-{Index}{Extension}" } } } ) }; // Create the custom transform templat with the outputs defined above transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, outputs); } return(transform); }
public void TransformComboTest() { using (MockContext context = this.StartMockContextAndInitializeClients(this.GetType())) { try { CreateMediaServicesAccount(); // List transforms, which should be empty var transforms = MediaClient.Transforms.List(ResourceGroup, AccountName); Assert.Empty(transforms); string transformName = TestUtilities.GenerateName("transform"); string transformDescription = "A test transform"; // Get the transform, which should not exist Transform transform = MediaClient.Transforms.Get(ResourceGroup, AccountName, transformName); Assert.Null(transform); // Create a transform TransformOutput[] outputs = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)) }; Transform createdTransform = MediaClient.Transforms.CreateOrUpdate(ResourceGroup, AccountName, transformName, outputs, transformDescription); ValidateTransform(createdTransform, transformName, transformDescription, outputs); // List transforms and validate the created transform shows up transforms = MediaClient.Transforms.List(ResourceGroup, AccountName); Assert.Single(transforms); ValidateTransform(transforms.First(), transformName, transformDescription, outputs); // Get the newly created transform transform = MediaClient.Transforms.Get(ResourceGroup, AccountName, transformName); Assert.NotNull(transform); ValidateTransform(transform, transformName, transformDescription, outputs); // Update the transform TransformOutput[] outputs2 = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)), new TransformOutput(new VideoAnalyzerPreset(insightsToExtract: InsightsType.AllInsights)) }; Transform updatedByPutTransform = MediaClient.Transforms.CreateOrUpdate(ResourceGroup, AccountName, transformName, outputs2, transformDescription); ValidateTransform(updatedByPutTransform, transformName, transformDescription, outputs2); // List transforms and validate the updated transform shows up as expected transforms = MediaClient.Transforms.List(ResourceGroup, AccountName); Assert.Single(transforms); ValidateTransform(transforms.First(), transformName, transformDescription, outputs2); // Get the newly updated transform transform = MediaClient.Transforms.Get(ResourceGroup, AccountName, transformName); Assert.NotNull(transform); ValidateTransform(transform, transformName, transformDescription, outputs2); // Update the transform again TransformOutput[] outputs3 = new TransformOutput[] { new TransformOutput(new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)), new TransformOutput(new AudioAnalyzerPreset()), }; Transform updatedByPatchTransform = MediaClient.Transforms.Update(ResourceGroup, AccountName, transformName, outputs3); ValidateTransform(updatedByPatchTransform, transformName, transformDescription, outputs3); // List transforms and validate the updated transform shows up as expected transforms = MediaClient.Transforms.List(ResourceGroup, AccountName); Assert.Single(transforms); ValidateTransform(transforms.First(), transformName, transformDescription, outputs3); // Get the newly updated transform transform = MediaClient.Transforms.Get(ResourceGroup, AccountName, transformName); Assert.NotNull(transform); ValidateTransform(transform, transformName, transformDescription, outputs3); // Delete the transform MediaClient.Transforms.Delete(ResourceGroup, AccountName, transformName); // List transforms, which should be empty again transforms = MediaClient.Transforms.List(ResourceGroup, AccountName); Assert.Empty(transforms); // Get the transform, which should not exist transform = MediaClient.Transforms.Get(ResourceGroup, AccountName, transformName); Assert.Null(transform); } finally { DeleteMediaServicesAccount(); } } }