public FFMpegProcessWrapper() { settings = new VideoSettings(); if (SPContext.Current != null) { settings = settings.Load(); } }
internal void GetVideoPoster(VideoFile video) { if (settings == null) { settings = new VideoSettings(); settings = settings.Load(); } StringBuilder argsBuilder = new StringBuilder(); argsBuilder.AppendFormat(" -i \"{0}\"", Path.Combine(settings.InputVideoPath, video.Path)); argsBuilder.AppendFormat(" -ss {0}", settings.StartTimeOffset); argsBuilder.Append(" -vframes 1"); argsBuilder.Append(" -f image2"); argsBuilder.AppendFormat(" -y \"{0}\"", Path.Combine(settings.OutputImagePath, video.UniqueId.ToString() + ".jpg")); /* * ProcessStartInfo oInfo = new ProcessStartInfo(); * oInfo.FileName = string.Format("\"{0}\"", Path.Combine(settings.FFMpegPath, "ffmpeg.exe")); * //oInfo.WorkingDirectory = Path.GetDirectoryName(this.FFmpegPath); * oInfo.UseShellExecute = false; * oInfo.CreateNoWindow = true; * oInfo.RedirectStandardOutput = true; * oInfo.RedirectStandardError = true; * * using (Process ffmpegProcess = System.Diagnostics.Process.Start(oInfo)) * { * using (StreamReader srOutput = ffmpegProcess.StandardError) * { * System.Text.StringBuilder output = new System.Text.StringBuilder(); * * using (StreamReader objStreamReader = ffmpegProcess.StandardError) * { * System.Text.StringBuilder sbOutPut = new StringBuilder(); * * while (!ffmpegProcess.WaitForExit(settings.ProcessTimeout * 1000)) * { * sbOutPut.Append(objStreamReader.ReadToEnd().ToString()); * } * * if (sbOutPut.Length == 0) * { * sbOutPut.Append(objStreamReader.ReadToEnd().ToString()); * } * * if (ffmpegProcess.ExitCode == 0) * { * ffmpegProcess.Close(); * if (objStreamReader != null) * { * objStreamReader.Close(); * } * } * else * { * ffmpegProcess.Close(); * if (objStreamReader != null) * { * objStreamReader.Close(); * } * } * //return sbOutPut.ToString(); * } * * } * } */ // Create a process to generate the preview image. using (Process ffmpegProcess = new Process()) { ffmpegProcess.StartInfo.FileName = string.Format("\"{0}\"", Path.Combine(settings.FFMpegPath, "ffmpeg.exe")); ffmpegProcess.StartInfo.Arguments = argsBuilder.ToString(); ffmpegProcess.StartInfo.UseShellExecute = false; ffmpegProcess.StartInfo.RedirectStandardOutput = true; ffmpegProcess.StartInfo.RedirectStandardError = true; // Execute the process. ffmpegProcess.Start(); ffmpegProcess.WaitForExit(settings.ProcessTimeout * 1000); // Kill the process if necessary. if (ffmpegProcess.HasExited == false) { ffmpegProcess.Kill(); } } }
public FFMpegProcessWrapper(SPContext context) { settings = new VideoSettings(); settings.Context = context; settings = settings.Load(); }
internal void GetVideoInfo(VideoFile video) { if (settings == null) { settings = new VideoSettings(); settings = settings.Load(); } string output = string.Empty; // Create the ffmpeg.exe command line. StringBuilder argsBuilder = new StringBuilder(); argsBuilder.AppendFormat(" -i \"{0}\"", Path.Combine(settings.InputVideoPath, video.Path)); /* * ProcessStartInfo oInfo = new ProcessStartInfo(); * oInfo.FileName = string.Format("\"{0}\"", Path.Combine(settings.FFMpegPath, "ffmpeg.exe")); * //oInfo.WorkingDirectory = Path.GetDirectoryName(this.FFmpegPath); * oInfo.UseShellExecute = false; * oInfo.CreateNoWindow = true; * oInfo.RedirectStandardOutput = true; * oInfo.RedirectStandardError = true; */ /* * using (Process ffmpegProcess = System.Diagnostics.Process.Start(oInfo)) * { * using (StreamReader srOutput = ffmpegProcess.StandardError) * { * System.Text.StringBuilder output = new System.Text.StringBuilder(); * * using (StreamReader objStreamReader = ffmpegProcess.StandardError) * { * System.Text.StringBuilder sbOutPut = new StringBuilder(); * * while (!ffmpegProcess.WaitForExit(settings.ProcessTimeout * 1000)) * { * sbOutPut.Append(objStreamReader.ReadToEnd().ToString()); * } * * if (sbOutPut.Length == 0) * { * sbOutPut.Append(objStreamReader.ReadToEnd().ToString()); * } * * if (ffmpegProcess.ExitCode == 0) * { * ffmpegProcess.Close(); * if (objStreamReader != null) * { * objStreamReader.Close(); * } * } * else * { * ffmpegProcess.Close(); * if (objStreamReader != null) * { * objStreamReader.Close(); * } * } * * string soutput = sbOutPut.ToString(); * if (!string.IsNullOrEmpty(soutput)) * { * video.RawInfo = soutput; * video.Duration = ExtractDuration(video.RawInfo); * video.BitRate = ExtractBitrate(video.RawInfo); * video.RawAudioFormat = ExtractRawAudioFormat(video.RawInfo); * video.AudioFormat = ExtractAudioFormat(video.RawAudioFormat); * video.RawVideoFormat = ExtractRawVideoFormat(video.RawInfo); * video.VideoFormat = ExtractVideoFormat(video.RawVideoFormat); * video.Width = ExtractVideoWidth(video.RawInfo); * video.Height = ExtractVideoHeight(video.RawInfo); * video.infoGathered = true; * } * else * { * video.infoGathered = false; * } * * } * * } * } */ using (Process ffmpegProcess = new Process()) { ffmpegProcess.StartInfo.FileName = string.Format("\"{0}\"", Path.Combine(settings.FFMpegPath, "ffmpeg.exe")); ffmpegProcess.StartInfo.Arguments = argsBuilder.ToString(); ffmpegProcess.StartInfo.UseShellExecute = false; ffmpegProcess.StartInfo.RedirectStandardOutput = true; ffmpegProcess.StartInfo.RedirectStandardError = true; ffmpegProcess.Start(); ffmpegProcess.WaitForExit(settings.ProcessTimeout * 1000); // Kill the process if necessary. if (ffmpegProcess.HasExited == false) { ffmpegProcess.Kill(); } output = ffmpegProcess.StandardError.ReadToEnd(); } if (!string.IsNullOrEmpty(output)) { video.RawInfo = output; video.Duration = ExtractDuration(video.RawInfo); video.BitRate = ExtractBitrate(video.RawInfo); video.RawAudioFormat = ExtractRawAudioFormat(video.RawInfo); video.AudioFormat = ExtractAudioFormat(video.RawAudioFormat); video.RawVideoFormat = ExtractRawVideoFormat(video.RawInfo); video.VideoFormat = ExtractVideoFormat(video.RawVideoFormat); video.Width = ExtractVideoWidth(video.RawInfo); video.Height = ExtractVideoHeight(video.RawInfo); video.infoGathered = true; } else { video.infoGathered = false; } }