c# - asp.net ffmpeg video encoding hangs -


i have below methods encode videos uploaded web site ffmpeg. works fine videos 8-9 mb but, if video size larger 8-9 mb hangs web site. way recover restarting iis.

when watch process can see ffmpeg encodes video , exits. resulted video fine. problem starts ffmpeg exists.

application runs on win2003 x86 webserver iis6

anyone got experience encoding large files 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)     {         /* below right solution ....          * while loop reads stream improtant           * ffmpeg .net not provide more memory ffmpeg.           * when converting large files, ffmpeg's out put stream gets filled...          * , waits .net allocate memory resources never done.           * in order utilize less memory, clearing 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();     } 

smells typical deadlock.

you call proc.waitforexit before proc.standarderror.readtoend method , seems cause deadlock.

a reference msdn:

a deadlock condition can result if parent process calls waitforexit before standardoutput.readtoend , child process writes enough text fill redirected stream. parent process wait indefinitely child process exit. child process wait indefinitely parent read full standardoutput stream.

so replacing while cycle to:

string output = objstreamreader.readtoend(); proc.waitforexit(); 

should solve problem.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -