|
| 1 | +--- |
| 2 | +title: Create an Azure Media Services job with multiple transform outputs |
| 3 | +description: This topic demonstrates how to create an Azure Media Services job with multiple transform outputs. |
| 4 | +services: media-services |
| 5 | +documentationcenter: '' |
| 6 | +author: Juliako |
| 7 | +manager: femila |
| 8 | +editor: '' |
| 9 | + |
| 10 | +ms.service: media-services |
| 11 | +ms.workload: |
| 12 | +ms.topic: article |
| 13 | +ms.date: 02/17/2020 |
| 14 | +ms.author: juliako |
| 15 | +--- |
| 16 | + |
| 17 | +# Create a job with multiple transform outputs |
| 18 | + |
| 19 | +This topic shows how to create a Transform with two Transform Outputs. The first one calls for the input to be encoded for adaptive bitrate streaming with a built-in [AdaptiveStreaming](encoding-concept.md#builtinstandardencoderpreset) preset. The second one calls for the audio signal in the input video to be processed with the [AudioAnalyzerPreset](analyzing-video-audio-files-concept.md#built-in-presets). After the Transform is created, you can submit a job that will process your video accordingly. Since in this example we are specifying two Transform Outputs, we must specify two Job Outputs. You can choose to direct both Job Outputs to the same Asset (as shown below), or you can have the results be written to separate Assets. |
| 20 | + |
| 21 | + |
| 22 | +> [!TIP] |
| 23 | +> Before you start developing, review [Developing with Media Services v3 APIs](media-services-apis-overview.md) (includes information on accessing APIs, naming conventions, etc.) |
| 24 | +
|
| 25 | +## Create a transform |
| 26 | + |
| 27 | +The following code shows how to create a transform that produces two outputs. |
| 28 | + |
| 29 | +```csharp |
| 30 | +private static async Task<Transform> GetOrCreateTransformAsync( |
| 31 | + IAzureMediaServicesClient client, |
| 32 | + string resourceGroupName, |
| 33 | + string accountName, |
| 34 | + string transformName) |
| 35 | +{ |
| 36 | + // Does a Transform already exist with the desired name? Assume that an existing Transform with the desired name |
| 37 | + // also uses the same recipe or Preset for processing content. |
| 38 | + Transform transform = await client.Transforms.GetAsync(resourceGroupName, accountName, transformName); |
| 39 | + |
| 40 | + if (transform == null) |
| 41 | + { |
| 42 | + // You need to specify what you want it to produce as an output |
| 43 | + TransformOutput[] output = new TransformOutput[] |
| 44 | + { |
| 45 | + new TransformOutput |
| 46 | + { |
| 47 | + Preset = new BuiltInStandardEncoderPreset() |
| 48 | + { |
| 49 | + // This sample uses the built-in encoding preset for Adaptive Bitrate Streaming. |
| 50 | + PresetName = EncoderNamedPreset.AdaptiveStreaming |
| 51 | + } |
| 52 | + }, |
| 53 | + // Create an analyzer preset with video insights. |
| 54 | + new TransformOutput(new AudioAnalyzerPreset("en-US")) |
| 55 | + }; |
| 56 | + |
| 57 | + // Create the Transform with the output defined above |
| 58 | + transform = await client.Transforms.CreateOrUpdateAsync(resourceGroupName, accountName, transformName, output); |
| 59 | + } |
| 60 | + |
| 61 | + return transform; |
| 62 | +} |
| 63 | +``` |
| 64 | +## Submit a job |
| 65 | + |
| 66 | +Create a job with an HTTPS URL input and with two job outputs. |
| 67 | + |
| 68 | +```csharp |
| 69 | +private static async Task<Job> SubmitJobAsync(IAzureMediaServicesClient client, |
| 70 | + string resourceGroup, |
| 71 | + string accountName, |
| 72 | + string transformName) |
| 73 | +{ |
| 74 | + // Output from the encoding Job must be written to an Asset, so let's create one |
| 75 | + string outputAssetName1 = $"output-" + Guid.NewGuid().ToString("N"); |
| 76 | + Asset outputAsset = await client.Assets.CreateOrUpdateAsync(resourceGroup, accountName, outputAssetName1, new Asset()); |
| 77 | + |
| 78 | + // This example shows how to encode from any HTTPs source URL - a new feature of the v3 API. |
| 79 | + // Change the URL to any accessible HTTPs URL or SAS URL from Azure. |
| 80 | + JobInputHttp jobInput = |
| 81 | + new JobInputHttp(files: new[] { "https://nimbuscdn-nimbuspm.streaming.mediaservices.windows.net/2b533311-b215-4409-80af-529c3e853622/Ignite-short.mp4" }); |
| 82 | + |
| 83 | + JobOutput[] jobOutputs = |
| 84 | + { |
| 85 | + // Since we are specifying two Transform Outputs, two Job Outputs are needed. |
| 86 | + // In this example, the first Job Output is for the results from adaptive bitrate encoding, |
| 87 | + // and the second is for the results from audio analysis. In this example, both are written to the |
| 88 | + // same output Asset. Or, you can specify different Assets. |
| 89 | + |
| 90 | + new JobOutputAsset(outputAsset.Name), |
| 91 | + new JobOutputAsset(outputAsset.Name) |
| 92 | + |
| 93 | + }; |
| 94 | + |
| 95 | + // In this example, we are using a unique job name. |
| 96 | + // |
| 97 | + // If you already have a job with the desired name, use the Jobs.Get method |
| 98 | + // to get the existing job. In Media Services v3, Get methods on entities returns null |
| 99 | + // if the entity doesn't exist (a case-insensitive check on the name). |
| 100 | + Job job; |
| 101 | + try |
| 102 | + { |
| 103 | + string jobName = $"job-" + Guid.NewGuid().ToString("N"); |
| 104 | + job = await client.Jobs.CreateAsync( |
| 105 | + resourceGroup, |
| 106 | + accountName, |
| 107 | + transformName, |
| 108 | + jobName, |
| 109 | + new Job |
| 110 | + { |
| 111 | + Input = jobInput, |
| 112 | + Outputs = jobOutputs, |
| 113 | + }); |
| 114 | + } |
| 115 | + catch (Exception exception) |
| 116 | + { |
| 117 | + if (exception.GetBaseException() is ApiErrorException apiException) |
| 118 | + { |
| 119 | + Console.Error.WriteLine( |
| 120 | + $"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'."); |
| 121 | + } |
| 122 | + throw exception; |
| 123 | + } |
| 124 | + |
| 125 | + return job; |
| 126 | +} |
| 127 | +``` |
| 128 | +## Job error codes |
| 129 | + |
| 130 | +See [Error codes](https://docs.microsoft.com/rest/api/media/jobs/get#joberrorcode). |
| 131 | + |
| 132 | +## Next steps |
| 133 | + |
| 134 | +[Azure Media Services v3 samples using .NET](https://github.com/Azure-Samples/media-services-v3-dotnet/tree/master/) |
0 commit comments