using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace learun.util
{
/// <summary>
/// ffmpeg视频相关处理的类
/// </summary>
public class FFmpegUtil
{
public static int Run(string cmd)
{
try
{
//string ffmpeg = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"FFmpeg\ffmpeg.exe";
string ffmpeg = ConfigHelper.GetConfig().MultimediaFile.Replace("/", "\\") + @"FFmpeg\ffmpeg.exe";
ProcessStartInfo startInfo = new ProcessStartInfo(ffmpeg);
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = cmd;
Process process = Process.Start(startInfo);
//process.WaitForExit(3000);
process.Kill();
return 1;
}
catch (Exception ex)
{
return -1;
}
}
public static int Run1(string cmd)
{
int r = 0;
try
{
//string ffmpeg = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"FFmpeg\ffmpeg.exe";
string ffmpeg = ConfigHelper.GetConfig().MultimediaFile.Replace("/", "\\") + @"FFmpeg\ffmpeg.exe";
Process p = new Process();
p.StartInfo.FileName = ffmpeg;
p.StartInfo.Arguments = cmd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string a = string.Empty;
p.ErrorDataReceived += new DataReceivedEventHandler((s, message) =>
{
//Response.Write(message.Data);
a = message.Data;
});//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN