带有 .Net create transform 的 Azure 媒体服务会出现冲突错误

Azure media services with .Net create transform gives conflicts error

问题:

我正在尝试使用 azure 函数和 .Net core.In 将视频上传到 azure 媒体服务,在那里我创建了一个函数来创建转换。但是那个函数失败了,给我这个错误。

Exception occurred running the function.
Exception Data: Message- One or more errors occurred. (Operation returned an invalid status code 'Conflict'); InnerException- Microsoft.Azure.Management.Media.Models.ErrorResponseException: Operation returned an invalid status code 'Conflict'
[2021-11-07T04:23:25.745Z]    at Microsoft.Azure.Management.Media.TransformsOperations.CreateOrUpdateWithHttpMessagesAsync(String resourceGroupName, String accountName, String transformName, IList`1 outputs, String description, Dictionary`2 customHeaders, CancellationToken cancellationToken)
[2021-11-07T04:23:25.751Z]    at Microsoft.Azure.Management.Media.TransformsOperationsExtensions.CreateOrUpdateAsync(ITransformsOperations operations, String resourceGroupName, String accountName, String transformName, IList`1 outputs, String description, CancellationToken cancellationToken

这是我的 getOrCreateTransformAsync 函数。

 public async Task<Transform> GetOrCreateTransformAsync(
            Dictionary<string, string> config, 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.
            IAzureMediaServicesClient client = await CreateMediaServicesClientAsync(config);
            bool createTransform = false;
            Transform transform = null;
            try
            {
                transform = client.Transforms.Get(
                   config.GetValueOrDefault("ResourceGroup"), config.GetValueOrDefault("AccountName"), transformName);
            }
            catch (ErrorResponseException ex) when (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                createTransform = true;
            }

            if (createTransform)
            {
                // 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 the "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(
                    config.GetValueOrDefault("ResourceGroup"), config.GetValueOrDefault("AccountName"), transformName, output);
            }
            return transform;
        }

这是我的 CreateMediaServiceClientAsync 函数

private async Task<IAzureMediaServicesClient> CreateMediaServicesClientAsync(Dictionary<string, string> config)
        {
            var credentials = await GetCredentialsAsync(config);

            return new AzureMediaServicesClient(credentials)
            {
                SubscriptionId = config.GetValueOrDefault("SubscriptionId"),
            };
        }

 private async Task<ServiceClientCredentials> GetCredentialsAsync(Dictionary<string, string> config)
        {
            // Use ApplicationTokenProvider.LoginSilentAsync to get a token using a service principal with symmetric key
            var scopes = new[] { config.GetValueOrDefault("ArmAadAudience") + "/.default" };
            var app = ConfidentialClientApplicationBuilder.Create(config.GetValueOrDefault("AadClientId"))
       .WithClientSecret(config.GetValueOrDefault("AadSecret"))
       .WithAuthority(AzureCloudInstance.AzurePublic, config.GetValueOrDefault("AadTenantId"))
       .Build();

            var authResult = await app.AcquireTokenForClient(scopes)
                                                     .ExecuteAsync()
                                                     .ConfigureAwait(false);

            return new TokenCredentials(authResult.AccessToken);
        }

有人可以帮我解决这个问题吗?我尝试了很多来找到解决这个问题的方法。但是我做不到so.Thank你

谢谢Gaurav-Mantri。将您的建议作为答案发布,以便对面临类似问题的其他社区成员有所帮助。

根据转换输出 Class 文档尝试将 TransformOutputOnError 属性 指定为 ContinueJob

描述 TransformOutput 的属性,这些属性是生成所需输出时要应用的规则。

public class TransformOutput