tags:

views:

26

answers:

1

I have below methods to encode videos uploaded to a web site with ffmpeg. It works fine for videos up to 8-9 MB but, if video size is larger than 8-9 MB it hangs web site. Only way to recover it is restarting iis.

When i watch the process i can see that ffmpeg encodes video and exits. Resulted video is just fine. Problem starts as soon as ffmpeg exists.

Application runs on win2003 x86 webserver iis6

Anyone got experience with encoding large files from asp.net web app using 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();
    }
A: 

i am not a asp.net person i work with php and in php.ini which is a config file i can set the max amount of megabytes i am able to upload. maybe if you check the config file to see anything about uploading and set it to the maximum.

sarmen
this is nothing to do with upload
nLL