Search code examples
c#azure-media-services.net-5video-thumbnails

Azure media service job stay long in processing status


I developing C# .NET 5 Web API. I need to create thumbnail image for video and I did it using Azure media service, but when I submit job it is in status processing long period. Should I need to upgrade my service plan or there is another solution? This is my code: First, I create 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[]
                    {
                        // Generate a set of PNG thumbnails
                        new PngImage(
                            start: "5%",
                            step: "100%",
                            range: "1",
                            layers: new PngLayer[]{
                                new PngLayer(
                                    width: "50%",
                                    height: "50%"
                                )
                            }
                        )
                    },
                        new PngFormat(
                            filenamePattern: "videothumb-{Index}{Extension}"
                        )
                    }
                ),
                onError: OnErrorType.StopProcessingJob,
                relativePriority: Priority.Normal
            )
        };
        // Create the custom Transform with the outputs defined above
        transform = client.Transforms.CreateOrUpdate(resourceGroupName, accountName, transformName, outputs, description);

Then I create and submit my job.

string uniqueness = Guid.NewGuid().ToString().Substring(0, 13);
            string jobName = "job-" + uniqueness;
            string inputAssetName = "input-" + uniqueness;
            string outputAssetName = "output-" + uniqueness;

            // The input to the Job is a HTTPS URL pointing to an MP4 file
            var input = new JobInputHttp(
                           
                                files: new List<String> { blobUrl }
                            );

            Asset outputAsset = CreateOutputAsset(client, config.ResourceGroup, config.AccountName, outputAssetName);
            string thumbContainerName = $"asset-{outputAsset.AssetId}";
            Job job = SubmitJob(client, config.ResourceGroup, config.AccountName, transformName, jobName, input, outputAsset.Name);

            DateTime startedTime = DateTime.Now;
            job = WaitForJobToFinish(client, config.ResourceGroup, config.AccountName, transformName, jobName);
            TimeSpan elapsed = DateTime.Now - startedTime;

elapsed is between 15 and 25 seconds.

When I go to Azure portal, I can see that my job is in processing status long time. The video I want to process lasts 4 sec.


Solution

  • For simple FFMPEG based functions that need to return super fast, you could look at using an Azure Function like this Sample we provide. https://github.com/Azure-Samples/media-services-v3-dotnet-core-functions-integration/blob/master/Encoding/Encoding/VodFunctions/ffmpeg-encoding.cs