首先,我们部署一下文件夹.在工程的目录下新建几个文件夹如下图:
UpFiles文件夹是要保存你上传的文件,PlayFiles文件夹是用于你转换后保存的文件(用于网上播放)
ImgFile文件夹是保存截取视频文件的图片,然后那两个mencoder和ffmpeg文件夹是视频转换工具.此视频转换也
可叫做mencoder+ffmpeg视频转换.
首先,在配置文件中给这些文件夹进行路径的配置.如下
CODE:
<appSettings>
<!--工具文件夹-->
<add key="ffmpeg" value="ffmpeg/ffmpeg.exe"/>
<add key="mencoder" value="mencoder/mencoder.exe"/>
<add key="mplayer" value="mencoder/mplayer.exe"/>
<!--上传文件的路径-->
<add key="upfile" value="UpFiles"/>
<!--上专文件图片路径-->
<add key="imgfile" value="ImgFile"/>
<!--上传文件图片大小-->
<add key="CatchFlvImgSize" value="240x180"/>
<add key="widthSize" value="400"/>
<add key="heightSize" value="350"/>
<!--转换后文件路径-->
<add key="playfile" value="PlayFiles"/>
</appSettings>
在上传.ASPX页面中
CODE:
标题:<asp:TextBox ID="txtTitle" runat="server" Width="358px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtTitle"
ErrorMessage="标题不为空"></asp:RequiredFieldValidator>
<br />
<asp:FileUpload ID="FileUpload1" runat="server" Width="339px" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="上传视频" Width="70px" />
文件类型<span style="color:Red;">(.asf|.flv|.avi|.mpg|.3gp|.mov|.wmv|.rm|.rmvb)</span>
<asp:RegularExpressionValidator ID="imagePathValidator" runat="server" ErrorMessage="文件类型不正确"
ValidationGroup="vgValidation" Display="Dynamic" ValidationExpression="^[a-zA-Z]:(\\.+)(.asf|.flv|.avi|.mpg|.3gp|.mov|.wmv|.rm|.rmvb)$"
ControlToValidate="FileUpload1">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="文件不为空"></asp:RequiredFieldValidator></div>
<div style=" height:0px; border-top:solid 1px red; font-size:0px;"></div>
<div>上传列表.</div>
程序工作的原理是:视频先上传上去,然后跟着就是开始转换.
所以.在CS 文件中有
这里为了方便我是用sqlDatasource数据控件做数据的操作.
CODE:
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;
public partial class _Default : System.Web.UI.Page
{
// 扩展名定义
string[] strArrFfmpeg = new string[] {"asf","avi","mpg","3gp","mov" };
string[] strArrMencoder = new string[] {"wmv","rm","rmvb" };
protected void Page_Load(object sender, EventArgs e)
{
}
//
protected void btnUpload_Click(object sender, EventArgs e)
{
string upFileName = "";
if (this.FileUpload1.HasFile)
{
string fileName = PublicMethod.GetFileName(this.FileUpload1.FileName);// GetFileName();
if ((string)Session["file"] == fileName)
{
return;
}
upFileName = Server.MapPath(PublicMethod.upFile + fileName);
this.FileUpload1.SaveAs(upFileName);
string saveName = DateTime.Now.ToString("yyyyMMddHHmmssffff") ;
string playFile = Server.MapPath(PublicMethod.playFile + saveName);
string imgFile = Server.MapPath(PublicMethod.imgFile + saveName);
//System.IO.File.Copy(Server.MapPath(PublicMethod.playFile + "00000002.jpg?http://www.xvna.com"), Server.MapPath