public void NETSorununuCozenConvert()
{
/* 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.
**/
string strSRC = "c:\\video1.avi";
string strDEST = "c:\\video1.flv";
Process ffmpeg = new Process();
//string VideoFileDuration = Vuzz.BLL.Common.CommonMethodBLL.GetSystemParameters("Video File Duration");
string VideoFileDuration = "00:10:00";
string ffmpegargs = "-y -i \"" + strSRC + "\" -t " + VideoFileDuration + " -f flv -sameq \"" + strDEST + "\"";
// creating process
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.RedirectStandardOutput = false;
//ffmpeg.StartInfo.LoadUserProfile = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ffmpeg.StartInfo.Arguments = ffmpegargs;
ffmpeg.StartInfo.WorkingDirectory = Path.GetDirectoryName(Page.MapPath("~/ffmpeg/ffmpeg.exe"));
ffmpeg.StartInfo.FileName = Page.MapPath("~/ffmpeg/ffmpeg.exe");
ffmpeg.Start();
StreamReader objStreamReader = ffmpeg.StandardError;
StringBuilder sbOutPut = new StringBuilder();
while (!ffmpeg.WaitForExit(1000))
{
sbOutPut.Append(objStreamReader.ReadToEnd().ToString());
}
if (ffmpeg.ExitCode == 0)
{
ffmpeg.Close();
if (objStreamReader != null)
{
objStreamReader.Close();
}
//PrepareFileForPseudoStreaming(strMetaDatinsert, objList);
}
else
{
ffmpeg.Close();
if (objStreamReader != null) objStreamReader.Close();
//UpdateConversionStatusinDB(ffmpeg, objList);
}
}
public void VideoConvert(string Sourcevideo)
{
/* CMD ekranında bu iş şöyledir:
* C:\>ffmpeg -i test.avi test.flv
**/
Process ffmpeg = new Process();
// Output name
string formatedvideo = DateTime.Now.Ticks.ToString() + ".flv";
// video = Page.MapPath("1.wmv"); // setting video input name with path
string mpg= Page.MapPath("~/Videos/") + formatedvideo;
// ffmpeg -i "c:\my_folder\test.avi" "c:\my folder\test.flv"
ffmpeg.StartInfo.Arguments = " -i \"" + Sourcevideo + "\" -target vcd \"" + mpg + "\""; // arguments !
ffmpeg.StartInfo.FileName = Page.MapPath("~/ffmpeg/ffmpeg.exe");
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.StartInfo.RedirectStandardOutput = false;
ffmpeg.Start(); // start !
/* Resim çekme
*
* ffmpeg.StartInfo.Arguments = " -i \"" + input + "video.flv" + "\" -vframes 1 -f mjpeg \"" + output + "video.jpg\"";
*
**/
/*
* P.S how i caught the bug in my code was by setting the
* ProcessStartInfo.RedirectStandardOutput = true;
* and
* ProcessStartInfo.RedirectStandardError = true;
*
* Then on my process object i got the standard output and error stream ->
* StreamReader sr = Proc.StandardOutput;
* StreamReader sre = Proc.StandardError;
*
* then i use
* Response.Write(sr.ReadToEnd());
* and
* sre.ReadToEnd();
**/
}
public int ConvertEtResimCek()
{
try
{
Process pVideo = new Process();
Process pResim = new Process();
string AppPath = ConfigurationSettings.AppSettings.Get("AppFolder");
string input = ConfigurationSettings.AppSettings.Get("inputFolder");
string output = ConfigurationSettings.AppSettings.Get("inputFolder");
// Video Convert et
string fileargs = " -i " + "\"" + input + "video.avi\" -ar 22050 -acodec mp3 \"" + output + "video.flv\"";
// İçinden resim çek
string fileargs2 = " -i \"" + input + "video.flv" + "\" -vframes 1 -f mjpeg \"" + output + "video.jpg\"";
pVideo.StartInfo.WorkingDirectory = AppPath;
pVideo.StartInfo.FileName = AppPath + "ffmpeg.exe";
pVideo.StartInfo.Arguments = fileargs;
pVideo.StartInfo.UseShellExecute = false;
pVideo.StartInfo.CreateNoWindow = false;
pVideo.StartInfo.RedirectStandardOutput = true;
pVideo.StartInfo.RedirectStandardError = true;
pResim.StartInfo.WorkingDirectory = AppPath;
pResim.StartInfo.FileName = AppPath + "ffmpeg.exe";
pResim.StartInfo.Arguments = fileargs2;
pResim.StartInfo.UseShellExecute = false;
pResim.StartInfo.CreateNoWindow = false;
pResim.StartInfo.RedirectStandardOutput = true;
pResim.StartInfo.RedirectStandardError = true;
pVideo.Start();
pVideo.WaitForExit();
// Get & Log the error
int errCode = pVideo.ExitCode;
if (errCode == 0)
{
// Başarılı
pResim.Start();
pResim.WaitForExit();
if (pResim.ExitCode == 0)
{
return 0;
}
else
{
return -1; // no thumb image will be add
}
}
else
{
// LogaYaz("ERROR --> " + " An error occurred while converting the file");
return 1;
}
}
catch (Exception e)
{
// LogaYaz("ERROR --> " + e.Message);
return 2;
}
}
http://alexgorbatchev.com/wiki/SyntaxHighlighter:Demo:collapse
pre class="brush: csharp;white-space: nowrap; gutter: false;wrap-lines:true;"
Hiç yorum yok:
Yorum Gönder