我有以下方法来编码使用ffmpeg上传到网站的视频。它适用于高达8-9 MB的视频,但如果视频大小超过8-9 MB,它会挂起网站。恢复它的唯一方法是重启iis。
当我观看该过程时,我可以看到ffmpeg对视频进行编码并退出。结果视频很好。一旦ffmpeg存在,问题就会开始。
应用程序在win2003 x86 webserver iis6上运行
任何人都有使用ffmpeg编译来自asp.net web app的大文件的经验吗?
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();
}
答案 0 :(得分:2)
您在proc.WaitForExit
方法之前调用proc.StandardError.ReadToEnd
,这似乎导致死锁。
来自MSDN的参考:
如果是,则可能导致死锁情况 父进程调用WaitForExit 在StandardOutput.ReadToEnd和之前 子进程写入足够的文本 填充重定向的流。该 父进程会无限期地等待 让子进程退出。该 子进程会无限期地等待 为父母从完整阅读 StandardOutput流。
将您的while
周期替换为:
string output = objStreamReader.ReadToEnd();
proc.WaitForExit();
应该解决你的问题。
答案 1 :(得分:0)
我不是一个asp.net的人,我使用php和php.ini这是一个配置文件,我可以设置我能够上传的最大兆字节数。也许如果您检查配置文件以查看有关上传的任何内容并将其设置为最大值。