我有一个视频上传的界面.可以支持任何格式(不能限制上传格式)..当我读出来的时候,是调用系统自带的播放器.问题是系统自带的播放器支持的格式是有限的,有可能我之前上传的格式它就不支持.现在想在调用播放器的时候判断文件类型是否为播放器所支持.如果不支持就解码(网上有没有这方面的解码工具可以直接调用.如果用C#写的话,速度怎么样?).谢谢大虾们赐教.小弟万分感谢...提提意见也行.最好有这方面的例子..谢谢
就像有的电影播放网站.有的格式不支持时,它也要解码的..
------解决方案--------------------------------------------------------
你这个逻辑问题很严重
你不能给每个用户,每个视频反复重复解码.
你应该是转化成一个固定的格式,比如flv,用不支持的话,让他自己去下载播放器.
你一个用户解码一次,那不现实.会重复解码,浪费资源.而且用户看之前再解码,速度跟不上.
综上:必须上传以后编码成某称格式存储.比如FLV,然后用户看的时候直接使用固定的播放器.
------解决方案--------------------------------------------------------
我这里有一个没完成的东东
你可以参考一下
另外,我上传是用HttpModules进行上传管理的,那样可以解决大文件上传的问题,以及在写入前就可以判断文件的安全性.
- C# code
using System;using System.Configuration;public class PublicMethod:System.Web.UI.Page{ public PublicMethod() { } //文件路径 public static string ffmpegtool = "ffmpeg/ffmpeg.exe"; public static string mencodertool = "mencoder/mencoder.exe"; public static string flvtool = "flvtool/flvtool2.exe"; //flv标记工具 public static string upFile = "UpFiles" + "/"; //上传文件夹 public static string imgFile = "ImgFile" + "/"; //图片文件夹 public static string playFile = "PlayFiles" + "/"; //flv文件夹 public static string xmlFile = "xmlFiles" + "/"; //xml文件夹 public static string sizeOfImg = "240x180"; //图片的宽与高 public static string widthOfFile = "400"; //flv文件的宽度 public static string heightOfFile = "350"; //flv文件的高度 //public static string ffmpegtool = ConfigurationManager.AppSettings["ffmpeg"]; //public static string mencodertool = ConfigurationManager.AppSettings["mencoder"]; //public static string upFile = ConfigurationManager.AppSettings["upfile"] + "/"; //public static string imgFile = ConfigurationManager.AppSettings["imgfile"] + "/"; //public static string playFile = ConfigurationManager.AppSettings["playfile"] + "/"; //文件图片大小 //public static string sizeOfImg = ConfigurationManager.AppSettings["CatchFlvImgSize"]; //文件大小 //public static string widthOfFile = ConfigurationManager.AppSettings["widthSize"]; //public static string heightOfFile = ConfigurationManager.AppSettings["heightSize"]; // // //获取文件的名字 private System.Timers.Timer myTimer = new System.Timers.Timer(3000);//记时器 public static string flvName = ""; public static string imgName = ""; public static string flvXml = ""; public static int pId = 0; public static string GetFileName(string fileName) { int i = fileName.LastIndexOf("\\") + 1; string Name = fileName.Substring(i); return Name; } //获取文件扩展名 public static string GetExtension(string fileName) { int i = fileName.LastIndexOf(".")+1; string Name = fileName.Substring(i); return Name; } // #region //运行FFMpeg的视频解码,(这里是绝对路径) /// <summary> /// 转换文件并保存在指定文件夹下面(这里是绝对路径) /// </summary> /// <param name="fileName">上传视频文件的路径(原文件)</param> /// <param name="playFile">转换后的文件的路径(网络播放文件)</param> /// <param name="imgFile">从视频文件中抓取的图片路径</param> /// <returns>成功:返回图片虚拟地址; 失败:返回空字符串</returns> public void ChangeFilePhy(string fileName, string playFile, string imgFile) { //取得ffmpeg.exe的路径,路径配置在Web.Config中,如:<add key="ffmpeg" value="E:\aspx1\ffmpeg.exe" /> string ffmpeg = Server.MapPath(PublicMethod.ffmpegtool); if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName))) { return; } //获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg 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(ffmpeg); FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; FilestartInfo.Arguments = " -i " + fileName + " -ab 56 -ar 22050 -b 500 -r 15 -s " + widthOfFile + "x" + heightOfFile + " " + flv_file; //ImgstartInfo.Arguments = " -i " + fileName + " -y -f image2 -t 0.05 -s " + FlvImgSize + " " + flv_img; try { //转换 System.Diagnostics.Process.Start(FilestartInfo); //截图 CatchImg(fileName, imgFile); //System.Diagnostics.Process.Start(ImgstartInfo); } catch { } } #endregion #region 截图 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 ""; } // catchFlvTool(fileName); if (System.IO.File.Exists(flv_img)) { return flv_img; } return ""; } #endregion