解决方案 »

  1.   

    http://hi.baidu.com/lefthandlife/item/57c0753787076c5d81f1a758
      

  2.   


    您好,我已经是用了这段代码,可是PlayFiles里面,和ImgFiles里面没有数据。请问这是什么原因呢?
      

  3.   

    先用命令行手工转看看能不能成功,再用asp.net调用转换
      

  4.   

    将视频文件转换成flv格式,并保存到playFile文件夹下
     public static  bool  changeVideoType(string fileName, string playFile, string imgFile)
        {
            //获取视频转换工具的路径
            string ffmpeg= System.Web.HttpContext.Current.Server.MapPath("../") + ffmpegtool;
            //获取需要转换的视频路径
            string Name = System.Web.HttpContext.Current.Server.MapPath("../") + upFile + "/" + fileName;
            if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(Name)))
            {
                return false;
            }              
            //获取视频转换后需要保存的路径
            string flv_file = playFile;
            //创建Process对象
            Process pss = new Process();
            //不显示窗口
            pss.StartInfo.CreateNoWindow = false;
            //设置启动程序的路径
            pss.StartInfo.FileName = ffmpeg;
            //设置执行的参数
            pss.StartInfo.Arguments = " -i " + Name + " -ab 128 -ar 22050 -qscale 6 -r 29.97 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file;   
            try
            {
                //启动转换工具          
                pss.Start();
                while (!pss.HasExited)
                {
                    continue;               
                }
               
                //截取视频的图片
                catchImg(Name, imgFile);
                System.Threading.Thread.Sleep(4000);
                if (!File.Exists(imgFile))
                {
                    File.Copy(System.Web.HttpContext.Current.Server.MapPath("../") + "imgHead\\default.gif", imgFile);
                }            return true;
            }
            catch
            {
                return false;
            }       
           
        }
        // 显示视频
        public static string GetFlashText(string url)
        {
            url = "player.swf?fileName=" + url;
            string str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='452' height='360'  id='index' name='index'><param name='allowScriptAccess' value='always' /><param name='movie' value='" +
                url + "'><embed src='" +
                url + "' id='index1' name='index1' type='application/x-shockwave-flash' swLiveConnect=true allowScriptAccess='always' width='452' height='360'></embed></object>";
            return str;
        }
        //截取字符串CodeGo.net/
        public static  string interceptStr(string str, int len)
        {
            if (str.Length > len)
            {
                str = str.Substring(0,len)+ "...";
            }
            return str;
        }
        public static string filtrateHtml(string str)
        {
            str = str.Trim();
            str = str.Replace("'", "&quot;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt;");
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("\n", "<br>");
            return str;
        }
         public static string resumeHtml(string str)
        {
            str = str.Trim();
            str = str.Replace("&quot;", "'");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("<br>", "\n");
            return str;
        }    
        public static void catchImg(string fileName,string imgFile)
        {
            //获取截图工具路径
            string ffmpeg = System.Web.HttpContext.Current.Server.MapPath("../") + ffmpegtool; 
            //获取截图后保存的路径
            string flv_img = imgFile; 
            //获取截取图片的大小
            string FlvImgSize = sizeOfImg;
            Process pss = new Process();     
            //设置启动程序的路径
            pss.StartInfo.FileName = ffmpeg;       
            pss.StartInfo.Arguments = "   -i   " + fileName + "  -y  -f  image2   -ss 2 -vframes 1  -s   " + FlvImgSize + "   " + flv_img;
            //启动进程
            pss.Start();       
        }