给你看看我用的private void GenerateBatFile(string batfileaddress, string extname,bool genmetadata,string source_file,string dest_file,string filename_prefix)
        {
            FileStream fs = File.Create(batfileaddress);
            fs.Flush();
            fs.Close();
            StreamWriter sw = new StreamWriter(batfileaddress, true);            StringBuilder sb = new StringBuilder();            switch (extname)
            {
                case ".rm":
                case ".rmvb":
                    sb.Append(ConfigurationManager.AppSettings["WisMencoderPath"].ToString());
                    sb.Append("mencoder.exe");
                    sb.Append(" -vf scale=320:240 -ffourcc FLV1 -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -ovc lavc -lavcopts vcodec=flv:vbitrate=200 -srate 22050 -oac lavc -lavcopts acodec=mp3:abitrate=56 " + source_file + " -o " + dest_file);                    break;
                default:
                    sb.Append( ConfigurationManager.AppSettings["FFMpegPath"].ToString());
                    sb.Append ("ffmpeg.exe");
                    sb.Append(" -i " + source_file + " -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 " + dest_file);
                    break;
            }            sw.Write(sb.ToString());
            sw.WriteLine("");
            sb.Remove(0,sb.Length);            if (genmetadata)
            {
                
                sb.Append(ConfigurationManager.AppSettings["FlvMdiPath"].ToString());
                sb.Append("FlvMdi.exe");
                sb.Append(" "+dest_file + " " + dest_file);
                sw.Write(sb.ToString());
                sw.WriteLine("");
                sb.Remove(0,sb.Length);
            }            sb.Append(ConfigurationManager.AppSettings["FFMpegPath"].ToString());
            sb.Append("FFMpeg.exe");
            sb.Append(" -i " + dest_file + " -t 0.1 -s 256x192 -ss 00:00:" + ConfigurationManager.AppSettings["CutTime"].ToString() + " -y -f mjpeg " + Server.MapPath(ConfigurationManager.AppSettings["PicPath"].ToString()) + "\\" + filename_prefix + ".jpg");
           
            sw.Write(sb.ToString());
            sw.Flush();
            sw.Close();        }先生成一个bat文件,
然后再Process.Start(Server.MapPath(FilePath) + newbatfilename);

解决方案 »

  1.   

    或者用这个类
    public class Cmd
    {
    private string FileRoot; private string ExeFileName; private string ExeCommand; //private bool _IsSuccessful; private Process p; /// <summary>
    /// CMD执行命令 
    /// </summary>
    /// <returns>返回执行后的结果</returns>
    public string Execute()
    {
    string argm=FileRoot+ExeFileName+ExeCommand;
    string output;
     
    //开始创建文件 
    p = new Process(); 
    p.StartInfo.FileName = "cmd.exe"; 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.RedirectStandardInput = true; 
    p.StartInfo.RedirectStandardOutput = true; 
    p.StartInfo.RedirectStandardError = true; 
    p.StartInfo.CreateNoWindow = true; 
         
    try 


    //p.StandardInput.WriteLine(argm); 
    //p.StandardInput.WriteLine("exit"); 
    p.StartInfo.Arguments=argm;

    p.Start();
    p.StandardInput.AutoFlush=true;
    p.StandardInput.WriteLine(argm); 
    p.StandardInput.WriteLine("exit"); 
    output=p.StandardOutput.ReadToEnd(); 
    p.WaitForExit();
    p.StandardInput.Flush();
    p.StandardOutput.Close();
    p.Close(); 
    p.Dispose();

    return output; 

    catch (Exception ex)
    {  return ex.Message;

     
    } /// <summary>
    /// 要执行的文件所在的路径
    /// </summary>
    public string FILEROOT
    {
    set
    {
    FileRoot=value;
    }
    get
    {
    return FileRoot;
    }

    }
    /// <summary>
    /// 要执行的文件的文件名
    /// </summary>
    public string FILENAME
    {
    set
    {
    ExeFileName=value;
    }
    get
    {
    return ExeFileName;
    }
    } /// <summary>
    /// 要执行的命令
    /// </summary>
    public string COMMAND
    {
    set
    {
    ExeCommand=value;
    }
    get
    {
    return ExeCommand;
    }
    }
    }Cmd be = new Cmd();
                be.FILEROOT = ConfigurationManager.AppSettings["FFMpegPath"].ToString(); ;
                be.FILENAME = @"ffmpeg.exe";
                be.COMMAND = @" -i " + tmpFilePath + FileName.Value.ToString() + ".flv -t 0.1 -s 256x192 -ss 00:00:" + ConfigurationManager.AppSettings["CutTime"].ToString() + " -y -f mjpeg " + Server.MapPath(ConfigurationManager.AppSettings["PicPath"].ToString()) + "\\" + FileName.Value.ToString() + ".jpg";
                be.Execute();
      

  2.   

    我试着用了您的方法。。
    可是没有反应。。
    然后测试时就把。p.StartInfo.CreateNoWindow = true;  true改成了false;
    照理应该会把DOS命令窗口打开。。
    可是我机子根本没有打开。。
    请问这是什么原因啊
      

  3.   

    主要的问题,就是我现在连DOS窗口都打不开哦
      

  4.   

    后台运行就可以了,不需要打开DOS窗口的。
      

  5.   

    你要是在任务管理器里可以看到一个ffmpeg的进程,那就没问题
      

  6.   

    呵呵..
    我搞定啦``
    以下是我测试成功的代码哦``using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;/// <summary>
    /// ConvertVideo 的摘要说明
    /// </summary>
    public class ConvertVideo
    {
    public ConvertVideo()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
        /**/
        /// <summary>
        /// 视频(avi,mov等等格式)转换为flv格式视频
        /// </summary>
        /// <param name="FromName">被转换的视频文件</param>
        /// <param name="ExportName">转换flv后的文件名</param>
        /// <param name="ExportName">视频大小的尺寸</param>
        /// <returns></returns>
    //其中System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"]是存放ffmpeg.exe的路径
    //bs.GetVideoFilePath() 是工作目录。比如你想把生成的文件放在E:\VideoDemo 就这样
        public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
        {
             Base bs = new Base();
             string ffmpeg = System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"];
             string Command = ffmpeg + " -i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName;      ////Flv格式
             //string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -ab 56 -ar 22050 -b 500 -r 15 -s 320*240 "+ ExportName;
             System.Diagnostics.Process p = new System.Diagnostics.Process();
             p.StartInfo.FileName = "cmd.exe";
             p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoFilePath());
             p.StartInfo.UseShellExecute = false;
             p.StartInfo.RedirectStandardInput = true;
             p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = false;
            //开始执行
            p.Start();
            p.StandardInput.WriteLine(Command);
            p.StandardInput.WriteLine("Exit") ;
            return ExportName;
        }
        public static string VideoConvertImg(string FromName, string WidthAndHeight, string ExportName)
        {
            Base bs = new Base();
            string ffmpeg = System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"];
            string Command = ffmpeg + " -i " + FromName + " -y -f image2 -t 0.001 -s " + WidthAndHeight + " " + ExportName;          //获取静态图
            //string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -f image2 -t 0.001 -s 300*200 " + ExportName;     
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoImagePath());
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = false;
            //开始执行
            p.Start();
            p.StandardInput.WriteLine(Command);
            p.StandardInput.WriteLine("Exit");
            return ExportName;
        }
    }
      

  7.   

    要调用的话.
    ConvertVideo.VideoConvertFlv("上传文件路径", "300*200", "Test.flv");
      

  8.   

    OK,不过建议你还是生成bat以后再执行
    因为视频处理以后会有一系列的动作要执行的。
      

  9.   

    说的是。。在上传时,,页面总是会很慢,,请问一下如何让他生成Bat文件。。然后执行。。
    多谢
      

  10.   

    我给你的第一个例子就是关于生成bat文件的。
      

  11.   

    好的。。谢啦。。
    要不你发到我邮箱里也行。。
    发到这里也行。。
    [email protected]
    谢啦
      

  12.   

    System.Threading.Thread.Sleep(4000);
    为什么用这个,是打算等待4秒后开始吗?是命令行还是应用程序项目?
    可能是MAIN的主程序进程已结束,方法没进行完就被KILL掉了。
    是否需要AutoResetEvent 类来让主进程在关闭前等待方法的完成?
    我提个醒吧。我也看不出来。
      

  13.   

    System.Threading.Thread.Sleep(4000);这个是刚开始测试的程序代码。。后面的没有。。后面那个是好报