2

I have written an Azure function in C# which will cut a big mp4 files into some small duration. I have copied everything that is required (ffmpeg executeable, video file) in home directory via KUDU console. But when I run the the function it runs for more than 5 minutes and it doesn't give any files in the home directory.

Function :

using System;
using System.Diagnostics;

public static void Run(string input, TraceWriter log)
{
    log.Info("Executing");
    using (var process = new Process())
    {
        process.StartInfo.FileName = @"D:\home\ffmpeg.exe";
        process.StartInfo.Arguments = @"-i D:\home\AmnestyInternational.mp4 -ss 00:00:03 -t 00:00:08 -async 1 D:\home\cut.mp4";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        log.Info(Directory.GetCurrentDirectory());
        log.Info("Cutting starts:"+DateTime.Now.ToString("h:mm:ss tt"));
        process.Start();
        string output = process.StandardOutput.ReadToEnd();
        process.WaitForExit();
        log.Info("Cutting ends :"+DateTime.Now.ToString("h:mm:ss tt"));
        log.Info(output);
    }
}

Output seen on Azure function Console:

2017-03-24T11:06:00.705 Function started (Id=df082f54-719a-415f-b7f1-b10548a213be)
2017-03-24T11:06:00.721 Executing
2017-03-24T11:06:00.721 D:\Windows\system32
2017-03-24T11:06:00.721 Cutting start :11:06:00 AM
2017-03-24T11:07:14  No new trace in the past 1 min(s).
2017-03-24T11:08:14  No new trace in the past 2 min(s).
2017-03-24T11:09:14  No new trace in the past 3 min(s).
2017-03-24T11:10:14  No new trace in the past 4 min(s).
2017-03-24T11:11:00.758 Microsoft.Azure.WebJobs.Host: Timeout value of 00:05:00 was exceeded by function: Functions.ManualTriggerCSharp1.

When I try to execute this same command on KUDU console or my own PC it only take 1.5 mins and I get a file of the desired duration

Could anyone please help me with this? What I might be missing?

8
  • maybe your computer is just faster than the cloudoption you booked? Commented Mar 24, 2017 at 11:19
  • Event when I am executing the above command in KUDU console it takes around 1.5 mins. Commented Mar 24, 2017 at 11:23
  • Did you check if you azure-vm has hardware acceleration for video transcoding? Commented Mar 24, 2017 at 11:31
  • No, I haven't. How do I check that? Commented Mar 24, 2017 at 11:37
  • I doubt it has, since you'd need an i7 or a mid/high end graphics card for it. but you can just check with the console which hardware you "have" an then check if it supports it. Commented Mar 24, 2017 at 12:25

2 Answers 2

2

One improvement would be to get incremental progress updates from stdout, assuming that your process has output. I believe that ReadToEnd() will block until your process exits (and here it appears to timeout first). See some sync & async examples here: Process.start: how to get the output?

The maximum timeout for consumption plan is 5 minutes, but if you run your function on a dedicated app service then you can set the timeout to any value of your choice.

Sign up to request clarification or add additional context in comments.

Comments

0

I couldn't figure out why FFMPEG wasn't executing, until I realized I needed to be in the same folder as the EXE (in your case, D:\home). This was the line of code I was missing:

Directory.SetCurrentDirectory(@"D:\home");

After that:

process.StartInfo.WorkingDirectory = @"D:\home";
process.StartInfo.FileName = "ffmpeg.exe";

etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.