Why is the external executable I bundled with my azure function not being found at runtime, despite it being present in the expected location?

384 Views Asked by At

I have a group of Azure functions that I publish to a functions app. One of these is a blob triggered function, meant to extract thumbnails from videos uploaded to Azure storage, and to do so, uses ffmpeg.exe.

I have published the project via Visual Studio, adding the executable in a directory in the root of the project. The relative path is exe/ffmpeg.exe. To include the executable in the published bundle I followed the instructions in this Microsoft Developer instructional video.

After publication, If I enter the Kudu debug console for this function app, I can find the file under C:\home\site\wwwroot\exe\ffmpeg.exe, as expected. I can even use that absolute path to execute ffmpeg inside the Kudu console.

This is the code I use to call the ffmpeg executable in the blob function:

using (var process = new Process())
{
    process.StartInfo = new ProcessStartInfo
    {
        FileName = @"C:\home\site\wwwroot\exe\ffmpeg.exe",
        Arguments = $"-hide_banner -loglevel error -i {videoTempPath} -frames:v 1 {thumbTempPath}",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        CreateNoWindow = true
    };

    process.Start();
    await process.WaitForExitAsync();
}

However, this does not work. I get the following error in the logs:

An error occurred trying to start process 'C:\home\site\wwwroot\exe\ffmpeg.exe' with working directory 'C:\Program Files (x86)\SiteExtensions\Functions 4.25.2132bit. The system cannot find the file specified.

And indeed my thumbnails are never created. How can I solve this, or why does it happen?

1

There are 1 best solutions below

1
On

An error occurred trying to start process 'C:\home\site\wwwroot\exe\ffmpeg.exe' with working directory 'C:\Program Files (x86)\SiteExtensions\Functions 4.25.2132bit. The system cannot find the file specified.

Check and adjust file permissions in Azure Blob Storage or via Kudu console if needed.

  • I have reproduced with another approach. Firstly, I created a blob trigger function app in visual studio and configured according to the requirement to create thumbnails from video files using FFmpeg.

Function1.cs:

using System;
using System.IO;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using System.Diagnostics;

namespace FunctionApp14
{
    public class Function1
    {
        private readonly ILogger _logger;

        public Function1(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<Function1>();
        }

        [Function("GenerateThumbnail")]
        public void Run([BlobTrigger("test/{name}", Connection = "AzureWebJobsStorage")] Stream videoStream, string name)
        {
            _logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name}");

            // Specify the path where you want to save the thumbnail
            string thumbnailPath = $"C:/Users/suresh/Desktop/t1/test_thumbnail.jpg";

            // Use FFmpeg to generate a thumbnail (adjust the time and output path as needed)
            ProcessStartInfo psi = new ProcessStartInfo("ffmpeg", $"-i {videoStream} -ss 00:00:05 -vframes 1 {thumbnailPath}")
            {
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process process = new Process
            {
                StartInfo = psi,
                EnableRaisingEvents = true
            };

            process.Exited += (sender, args) =>
            {
                // Check if FFmpeg command completed successfully
                if (process.ExitCode == 0)
                {
                    _logger.LogInformation($"Thumbnail generated for {name}");

                    // Here, you can upload the thumbnail to another Azure Storage container or perform other actions as needed
                }
                else
                {
                    _logger.LogError($"Thumbnail generation failed for {name}. FFmpeg exited with code {process.ExitCode}");
                }

                process.Dispose();
            };

            process.Start();
            process.WaitForExit();
        }
    }
}

Deployment status:

enter image description here

  • Here I deployed the ffmpeg-master-latest-win64-gpl Zip file inside the application folder and unzipped in kudu by using command unzip ffmpeg-master-latest-win64-gpl and installed.

enter image description here

Below is the latest version installed in kudu.

enter image description here

Then I uploaded a test.mp4 file into the container.

enter image description here

I am able to access the storage container with the function app, below are the app insights.

enter image description here

  • I ran the application in the Debug console using func start and able to get the Thumbnail at the adjusted time 00:00:05.

enter image description here

Result:

enter image description here

Note:

Instead of manually calling ffmpeg, consider using Azure Media Services for video processing tasks. Azure Media Services provides a platform for encoding, transforming, and streaming media, and it can simplify video processing tasks in Azure.