asp.net ffmpeg кодирование видео зависает

У меня есть следующие методы кодирования видео, загруженных на веб-сайт с помощью ffmpeg. Он отлично работает для видео размером до 8-9 МБ, но, если размер видео больше 8-9 МБ, веб-сайт зависает. Единственный способ восстановить его - это перезапустить iis.

Когда я смотрю процесс, я вижу, что ffmpeg кодирует видео и завершает работу. Полученное видео в порядке. Проблема начинается, как только существует ffmpeg.

Приложение работает на веб-сервере win2003 x86 iis6

Кто-нибудь имел опыт кодирования больших файлов из веб-приложения asp.net с помощью ffmpeg?

public EncodedVideo EncodeVideo(VideoFile input, string encodingCommand, string outputFile)
    {
        EncodedVideo encoded = new EncodedVideo();
        Params = string.Format("-i \"{0}\" {1} \"{2}\"", input.Path, encodingCommand, outputFile);
        //string output = RunProcess(Params);
        string output = RunProcessLargeFile(Params);
        encoded.EncodingLog = output;
        encoded.EncodedVideoPath = outputFile;

        if (File.Exists(outputFile))
        {
            encoded.Success = true;
        }
        else
        {
            encoded.Success = false;
        }
        //System.Web.HttpContext.Current.Response.Write(Params);
        return encoded;

    }

private string RunProcessLargeFile(string Parameters)
    {
        /* The below will be the right solution ....
         * The while loop which reads the stream is very improtant 
         * for FFMPEG as .NET does not provide more memory to FFMPEG. 
         * When converting large files, FFMPEG's out put stream gets filled...
         * And waits for .NET to allocate memory resources but is never done. 
         * In order to utilize less memory, we are clearing the buffer periodically.
         **/

        ProcessStartInfo oInfo = new ProcessStartInfo(this.FFmpegPath, Parameters);
        oInfo.WorkingDirectory = Path.GetDirectoryName(this.FFmpegPath);
        oInfo.UseShellExecute = false;
        oInfo.CreateNoWindow = true;
        oInfo.RedirectStandardOutput = true;
        oInfo.RedirectStandardError = true; 
        Process proc = System.Diagnostics.Process.Start(oInfo);
        StreamReader srOutput = proc.StandardError;
        System.Text.StringBuilder output = new System.Text.StringBuilder();

        StreamReader objStreamReader = proc.StandardError;
        System.Text.StringBuilder sbOutPut = new StringBuilder();

        while (!proc.WaitForExit(1000))
        {
            sbOutPut.Append(objStreamReader.ReadToEnd().ToString());
        }

        if (proc.ExitCode == 0)
        {
            proc.Close();
            if (objStreamReader != null)
            {
                objStreamReader.Close();
            }
        }
        else
        {
            proc.Close();
            if (objStreamReader != null) objStreamReader.Close();
        }

        return sbOutPut.ToString();
    }
1
задан nLL 7 October 2010 в 16:43
поделиться