想把其他格式的视频通过程序转换成flv格式的在网上也看了些相关的文章可是运行后都没有成功    private void test()
    {
        string root = System.Web.HttpContext.Current.Server.MapPath("~");
        //转换视频:                                            
        string strCmd1 = root + Server.MapPath("input/05.avi") + " " + root + Server.MapPath("output/05.mpg"); //转换成mpg格式
        //Response.Write(strCmd1);
        RunFFMpeg(strCmd1);
        string strCmd2 = root + Server.MapPath("input/05.avi") + " " + root + Server.MapPath("output/05.flv"); //转换成flv格式
        RunFFMpeg(strCmd2);        //视频抓图:  
        string strCmd3 = root + Server.MapPath("input/05.avi") + " -y -f image2 -t 0.001 -s 300*200 "  + Server.MapPath("output/05.jpg"); //获取静态图 
        RunFFMpeg(strCmd3);
        string strCmd4 = root + Server.MapPath("input/05.avi") + " -vframes 30 -y -f gif "  + Server.MapPath("output/05.gif"); //获取动态图 
        RunFFMpeg(strCmd4);    }    //运行FFMpeg的视频解码,
    public void RunFFMpeg(string strCmd)
    {
        //创建并启动一个新进程
        Process p = new Process();        //设置进程启动信息属性StartInfo,这是ProcessStartInfo类,包括了一些属性和方法:
        p.StartInfo.FileName = Server.MapPath("ffmpeg/ffmpeg.exe");          //程序名
        p.StartInfo.Arguments = " -i " + strCmd;    //执行参数
        p.Start();
    }有一个是这样写的,大家帮忙指点下

解决方案 »

  1.   

        protected void btnUpload_Click(object sender, EventArgs e)--上传事件
        {
            string upFileName = "";
            if (this.FileUpload1.HasFile)
            {
                string fileName = PublicMethod.GetFileName(this.FileUpload1.FileName);// GetFileName();            upFileName = Server.MapPath(PublicMethod.upFile + fileName);
                this.FileUpload1.SaveAs(upFileName);
                string saveName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string playFile = Server.MapPath(PublicMethod.playFile + saveName);
                FileUpload1.SaveAs(playFile);
                string imgFile = Server.MapPath(PublicMethod.imgFile + saveName);
                FileUpload1.SaveAs(imgFile);
                //System.IO.File.Copy(Server.MapPath(PublicMethod.playFile + "00000002.jpg"), Server.MapPath(PublicMethod.imgFile+"aa.jpg"));
                PublicMethod pm = new PublicMethod();
                string m_strExtension = PublicMethod.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();            if (m_strExtension == "flv")
                {//直接拷贝到播放文件夹下
                    Response.Write("11111111111");
                    //System.IO.File.Copy(upFileName, playFile + ".flv");
                    //pm.CatchImg(upFileName, imgFile);
                }
                string Extension = CheckExtension(m_strExtension);
                if (Extension == "ffmpeg")
                {
                    Response.Write("222222222222222");
                    pm.ChangeFilePhy(upFileName, playFile, imgFile);
                }
                else if (Extension == "mencoder")
                {
                    Response.Write("333333333333333<br />");
                    Response.Write(pm.MChangeFilePhy(upFileName, playFile, imgFile));--程序调用了这个方法
                }
            }    }    public string MChangeFilePhy(string vFileName, string playFile, string imgFile)
        {
            string tool = Server.MapPath(PublicMethod.mencodertool);
          
            //string mplaytool = Server.MapPath(PublicMethod.ffmpegtool);        if ((!System.IO.File.Exists(tool)) || (!System.IO.File.Exists(vFileName)))
            {
               
                return "0111111111111111111111111";
            }        string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv");
            //截图的尺寸大小,配置在Web.Config中,如:<add   key="CatchFlvImgSize"   value="240x180"   />   
            string FlvImgSize = PublicMethod.sizeOfImg;        System.Diagnostics.ProcessStartInfo FilestartInfo = new System.Diagnostics.ProcessStartInfo(tool);        FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            FilestartInfo.Arguments = " " + vFileName + " -o " + flv_file + " -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=200:mbd=2:mv0:trell:v4mv:cbp:last_pred=1:dia=-1:cmp=0:vb_strategy=1 -vf scale=" + widthOfFile + ":" + heightOfFile + " -ofps 12 -srate 22050";
            try
            {
                System.Diagnostics.Process.Start(FilestartInfo);
                CatchImg(flv_file, imgFile);---方法在下面
            }
            catch
            {
                
                return "0222222222222222222";
            }
            //
           
            return "0333333333333333333333333";
        }    public string CatchImg(string fileName, string imgFile)
        {
            //
            string ffmpeg = Server.MapPath(PublicMethod.ffmpegtool);
            //
            string flv_img = imgFile + ".jpg";
            //
            string FlvImgSize = PublicMethod.sizeOfImg;
            //
            System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
            ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            //
            ImgstartInfo.Arguments = "   -i   " + fileName + "  -y  -f  image2   -ss 2 -vframes 1  -s   " + FlvImgSize + "   " + flv_img;
            try
            {
                System.Diagnostics.Process.Start(ImgstartInfo);
            }
            catch
            {
                return "";
            }
            //
            if (System.IO.File.Exists(flv_img))
            {
                return flv_img;
            }        return "";
        }
    ---这个方法也不行,根本就没有转换,只把原文件上传上去了,上传完成后,程序跳到这方法里了,可是没有转换成功,没有报异常
      

  2.   

    FileUpload1.SaveAs(playFile); --这个是没有的
      

  3.   

    楼主的两个标红色的方法都执行到了吗?
    会不会return ""; 了~~
      

  4.   

    为什么要  return ""; 
    那你要的是什么效果呢??
    System.Diagnostics.Process.Start(ImgstartInfo); 是开始转换吧?
      

  5.   

    为什么要  return ""; 那个return "" 又没有在另外的地方调用了,有没有返回值都无所谓,那个返回值也没有作用
      

  6.   

    ffmpeg这个插件我三年前一句实现了,不过当时的代码找不到了。
      

  7.   

    http://tieba.koolea.com/disp.aspx?bid=200711300833314095&id=82280
     你看看
      

  8.   

    路径重复了
    把 string root = System.Web.HttpContext.Current.Server.MapPath("~"); 
    改成 string root = "";