0

Within an Azure Function App I am trigger a Function by a blob upload, using ffprobe to retrieve the metadata of the uploaded blob (video files).

Somehow I am not getting the desired output. The ffprobe executable is recognized (I get { } as a response), but no metadata output.

Here is the code for my function:

[FunctionName("ToConvertFileFunction")]
    public static void Run([BlobTrigger("input/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, ILogger log)
    {
        trace = log;
        trace.LogInformation($"ConvertFile function processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        var output = "";
        var error = "";

        var videoTempDir = string.Format(Path.GetDirectoryName("D:\\home\\site\\wwwroot\\tempfiles\\"));
        var videoTempFile = name + ".MOV";
        string videoTemp = Path.Combine(videoTempDir, videoTempFile);

        using (var ms = new MemoryStream())
        {
            myBlob.CopyTo(ms);
            File.WriteAllBytes(videoTemp, ms.ToArray());
        }

        var process = new Process();
        process.StartInfo.FileName = Environment.GetEnvironmentVariable("ffprobePath");
        process.StartInfo.Arguments = $"-v quiet -print_format json -show_entries stream_tags:format_tags -i {videoTemp}";
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.UseShellExecute = false;

        process.Start();
        trace.LogInformation("***Checking metadata***");

        while (!process.StandardOutput.EndOfStream)
        {
            output += process.StandardOutput.ReadLine();
        }

        while (!process.StandardError.EndOfStream)
        {
            error += process.StandardError.ReadLine();
        }
        process.WaitForExit();

        trace.LogInformation($"ffprobe output: {output}");
        trace.LogInformation($"ffprobe error: {error}");

        //Delete temp file
        File.Delete(videoTemp);

        trace.LogInformation("Done!");
    }

I run the executable from the path D:\home\site\wwwroot\tools\ffprobe.exe and save my temporary video file in D:\home\site\wwwroot\tempfiles\

The log output is the following:

2019-07-20 12:21:51.453 
***Checking metadata***
Information
2019-07-20 12:22:07.114 
ffprobe output: {}
Information
2019-07-20 12:22:07.290 
ffprobe error:
Information
2019-07-20 12:22:08.739 
Done!
Information
2019-07-20 12:22:09.310 
Executed 'ToConvertFileFunction' (Succeeded, Id=a873200e-965c-4f58-92d7-1f3b16ebc779)
Information

Does anybody have a clue what is causing the error here? Many thanks for the help!

JJuice
  • 1,015
  • 2
  • 12
  • 21
  • In my experience, ffprobe will output `{}` if it doesn't understand the file. Have you tested this locally? – ProgrammingLlama Jul 20 '19 at 12:50
  • Thanks, you are probably right. I tested it locally, without using the same blob file and then it worked. Checked it again: when I download the blob file (a .MOV file) I am not able to play it, so there is something wrong with uploading the .MOV to Azure Blob Storage. – JJuice Jul 20 '19 at 13:14
  • 1
    Tested it when manually adding the .MOV file to blobstorage and now it works. Problem is coming from my upload Function. – JJuice Jul 20 '19 at 13:48

1 Answers1

0

Instead of delegating the read video metadata task to an out of process executable, try using MediaInfo -

There's a nice wrapper for MediaInfo.dll here - https://github.com/StefH/MediaInfo.DotNetWrapper

MediaInfoWrapper w = new MediaInfoWrapper(@"C:\tmp\input.mov");

metadata sample

Sometimes, given a stranger or older container as input, ffmpeg fails to read metadata (not very often but still, not ideal). MediaInfo works just fine in these cases.

And here's one more, for FFmpeg this time - https://github.com/cmxl/FFmpeg.NET

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • Thanks for the suggestion, will check this out! Already got some unexpected behavior working with FFprobe and reading metadata. Is the FFmpeg wrapper also capable of merging separate videos into one? – JJuice Jul 20 '19 at 15:46
  • what vs theme is this ? – HariHaran Jul 22 '19 at 04:18
  • **@HariHaran**: [_Overnight Slumber_](https://marketplace.visualstudio.com/items?itemName=cev.overnight). **@JJuice**: Concatenation isn't implemented (or i least i couldn't find it in the 2 minutes i looked for it), send in a PR, should be easy to code, just follow the convert logic and add multiple inputs. Unless all your inputs are MPEG-TS segments you'll need to reencode. – evilSnobu Jul 22 '19 at 05:32