网站页面代码:
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Modify_Video.aspx.cs" Inherits="Manager_NewHouse_Modify_Video" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>楼盘视频管理</title>
<link href="../../lib/css/css_admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.progressBar { WIDTH: 250px; HEIGHT: 18px }
.progressInfo { BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; FONT-SIZE: 9pt; OVERFLOW: hidden; BORDER-LEFT: #000000 1px solid; WIDTH: 250px; PADDING-TOP: 1px; BORDER-BOTTOM: #000000 1px solid; POSITION: absolute; HEIGHT: 18px; TEXT-ALIGN: center }
.progress { OVERFLOW: hidden; WIDTH: 0%; HEIGHT: 18px; BACKGROUND-COLOR: #5fff3f }
</style>
<script src="../../lib/Js/xmlLib.js" type="text/javascript"></script>
<script type="text/javascript">
var r = "传输: {0}K 还未完成";
var s = "您的文件已经上传完成";
var t = "上传失败";
function progressBar()
{ this.totalSize = 100;
this.sizeCompleted = 0;
this.percentDone = "0%";
this.setSize = function(totalSize, size)
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgress == null || oProgressInfo == null)
return; if (totalSize <= 0)
return; this.totalSize = totalSize;
this.sizeCompleted = size;
if (size < 0)
this.sizeCompleted = 0;
else if (size > this.totalSize)
this.sizeCompleted = this.totalSize; var sizeLeft = 0;
var progressInfoText = "";
sizeLeft = this.totalSize - this.sizeCompleted; this.percentDone = Math.round(size / this.totalSize * 100) + "%";
oProgress.style.width = this.percentDone;
if (sizeLeft > 0)
progressInfoText = r.replace("{0}", sizeLeft);
else
progressInfoText = s; oProgressInfo.innerHTML = progressInfoText;
}
this.UploadError = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = t;
if (oProgress != null)
oProgress.style.width = "0";
}
this.UploadComplete = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = s;
if (oProgress != null)
oProgress.style.width = "100%";
}
}
var iTimerID = null;
var xmlHttp = XmlHttpPool.pick();
var url = "progress.aspx?UploadID=<%=Request.QueryString["UploadID"]%>"
var pb = new progressBar();
function LoadProgressInfo()
{
try
{
xmlHttp.open("GET", url + "&t=" + Math.random(), true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function()
{
LoadData(xmlHttp);
}
}
catch(e)
{
alert(e)
}
} function LoadData(xmlhttp)
{
if (xmlhttp.readyState == 4)
{
iTimerID = window.setTimeout("LoadProgressInfo()", 500);
try{
eval(xmlhttp.responseText);
}
catch(e)
{
alert(e)
}
}
}
function ClearTimer()
{
if (iTimerID != null)
{
window.clearTimeout(iTimerID);
iTimerID = null;
}
}
function UploadCancel()
{
location.href = location.href;
} </script>
</head>
<body>
<form id="form1" runat="server">
<table cellspacing="0" cellpadding="0" width="100%" border="0" class="table_3d">
<tr>
<th colspan="2">楼盘视频管理</th>
</tr>
<tr>
<td align="right" height="25" style="width: 16%">
楼盘名称 :
</td>
<td align="left" height="25" width="*">
<asp:Literal ID="lblFloorName" runat="server"></asp:Literal></td>
</tr>
<tr>
<td height="25" align="right" style="width: 16%">
视频名称 :</td>
<td height="25" width="*" align="left">
<asp:TextBox ID="txtVO_Description" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td height="25" align="right" style="width: 16%">
上传视频 :</td>
<td height="25" width="*" align="left">
<p>
<input id="uploadFile" type="file" runat="server" />
</p>
<div id="progressBar" class="progressBar">
<div class="progressInfo" id="progressInfo" onselectstart="return false;">
</div>
<div class="progress" id="progress">
</div>
</div>
<iframe name="uploadData" src="about:blank" style="height: 51px" style="display:none;"></iframe>
</td>
</tr>
<tr>
<td></td>
<td height="25" align="left">
<asp:Button ID="btnUpload" runat="server" Text=" 上传 " OnClick="btnUpload_Click"></asp:Button>
<input id="Button1" type="button" value=" 取消 " onclick="UploadCancel()" />
</td>
</tr>
</table>
</form>
</body>
</html>
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Modify_Video.aspx.cs" Inherits="Manager_NewHouse_Modify_Video" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>楼盘视频管理</title>
<link href="../../lib/css/css_admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.progressBar { WIDTH: 250px; HEIGHT: 18px }
.progressInfo { BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; FONT-SIZE: 9pt; OVERFLOW: hidden; BORDER-LEFT: #000000 1px solid; WIDTH: 250px; PADDING-TOP: 1px; BORDER-BOTTOM: #000000 1px solid; POSITION: absolute; HEIGHT: 18px; TEXT-ALIGN: center }
.progress { OVERFLOW: hidden; WIDTH: 0%; HEIGHT: 18px; BACKGROUND-COLOR: #5fff3f }
</style>
<script src="../../lib/Js/xmlLib.js" type="text/javascript"></script>
<script type="text/javascript">
var r = "传输: {0}K 还未完成";
var s = "您的文件已经上传完成";
var t = "上传失败";
function progressBar()
{ this.totalSize = 100;
this.sizeCompleted = 0;
this.percentDone = "0%";
this.setSize = function(totalSize, size)
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgress == null || oProgressInfo == null)
return; if (totalSize <= 0)
return; this.totalSize = totalSize;
this.sizeCompleted = size;
if (size < 0)
this.sizeCompleted = 0;
else if (size > this.totalSize)
this.sizeCompleted = this.totalSize; var sizeLeft = 0;
var progressInfoText = "";
sizeLeft = this.totalSize - this.sizeCompleted; this.percentDone = Math.round(size / this.totalSize * 100) + "%";
oProgress.style.width = this.percentDone;
if (sizeLeft > 0)
progressInfoText = r.replace("{0}", sizeLeft);
else
progressInfoText = s; oProgressInfo.innerHTML = progressInfoText;
}
this.UploadError = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = t;
if (oProgress != null)
oProgress.style.width = "0";
}
this.UploadComplete = function()
{
var oProgressInfo = document.getElementById("progressInfo");
var oProgress = document.getElementById("progress");
if (oProgressInfo != null)
oProgressInfo.innerHTML = s;
if (oProgress != null)
oProgress.style.width = "100%";
}
}
var iTimerID = null;
var xmlHttp = XmlHttpPool.pick();
var url = "progress.aspx?UploadID=<%=Request.QueryString["UploadID"]%>"
var pb = new progressBar();
function LoadProgressInfo()
{
try
{
xmlHttp.open("GET", url + "&t=" + Math.random(), true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function()
{
LoadData(xmlHttp);
}
}
catch(e)
{
alert(e)
}
} function LoadData(xmlhttp)
{
if (xmlhttp.readyState == 4)
{
iTimerID = window.setTimeout("LoadProgressInfo()", 500);
try{
eval(xmlhttp.responseText);
}
catch(e)
{
alert(e)
}
}
}
function ClearTimer()
{
if (iTimerID != null)
{
window.clearTimeout(iTimerID);
iTimerID = null;
}
}
function UploadCancel()
{
location.href = location.href;
} </script>
</head>
<body>
<form id="form1" runat="server">
<table cellspacing="0" cellpadding="0" width="100%" border="0" class="table_3d">
<tr>
<th colspan="2">楼盘视频管理</th>
</tr>
<tr>
<td align="right" height="25" style="width: 16%">
楼盘名称 :
</td>
<td align="left" height="25" width="*">
<asp:Literal ID="lblFloorName" runat="server"></asp:Literal></td>
</tr>
<tr>
<td height="25" align="right" style="width: 16%">
视频名称 :</td>
<td height="25" width="*" align="left">
<asp:TextBox ID="txtVO_Description" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td height="25" align="right" style="width: 16%">
上传视频 :</td>
<td height="25" width="*" align="left">
<p>
<input id="uploadFile" type="file" runat="server" />
</p>
<div id="progressBar" class="progressBar">
<div class="progressInfo" id="progressInfo" onselectstart="return false;">
</div>
<div class="progress" id="progress">
</div>
</div>
<iframe name="uploadData" src="about:blank" style="height: 51px" style="display:none;"></iframe>
</td>
</tr>
<tr>
<td></td>
<td height="25" align="left">
<asp:Button ID="btnUpload" runat="server" Text=" 上传 " OnClick="btnUpload_Click"></asp:Button>
<input id="Button1" type="button" value=" 取消 " onclick="UploadCancel()" />
</td>
</tr>
</table>
</form>
</body>
</html>
protected static long tempid = 0;
// 扩展名定义
string[] strArrFfmpeg = new string[] { "asf", "avi", "mpg", "3gp", "mov" };
string[] strArrMencoder = new string[] { "wmv", "rmvb", "rm" };
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
long.TryParse(HNLP.Utils.Utils.Query("FiID"), out tempid);
HNLP.Model.NewFloorInfo newhouse = new HNLP.BLL.NewFloorInfo_BLL().GetModel(tempid);
if (newhouse == null)
{
HNLP.Utils.Clew.AlertBack("您要编辑的楼盘不存在!");
}
else
{
this.lblFloorName.Text = newhouse.FI_FloorName;
}
}
// 使用UploadID来唯一标识是当前的上传
//
if (Request.QueryString["UploadID"] == null)
Response.Redirect("Modify_Video.aspx?UploadID=" + Guid.NewGuid().ToString()+"&FiID="+tempid); // 当提交的时候,开始加载进度条
btnUpload.Attributes.Add("onclick", "window.setTimeout('LoadProgressInfo()', 500)");
}
/// <summary>
/// 上传视频
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUpload_Click(object sender, EventArgs e)
{
btnUpload.Enabled = false;
string upFileName = "";
try
{
string fileName = PublicMethod.GetFileName(this.uploadFile.PostedFile.FileName);// GetFileName();
//if ((string)Session["file"] == fileName)
//{
// return;
//}
upFileName = Server.MapPath(PublicMethod.upFile + fileName);
this.uploadFile.PostedFile.SaveAs(upFileName);//保存源文件
string saveName = System.Guid.NewGuid().ToString().Replace("-", "");
string playFile = Server.MapPath(PublicMethod.playFile + saveName);//播放文件路径
string imgFile = Server.MapPath(PublicMethod.imgFile + saveName);//图片文件路径
//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.uploadFile.PostedFile.FileName).ToLower();
if (m_strExtension == "flv")
{//直接拷贝到播放文件夹下
System.IO.File.Copy(upFileName, playFile + ".flv");//如果是flv格式 直接拷贝到播放文件
pm.CatchImg(upFileName, imgFile);//截图
}
string Extension = CheckExtension(m_strExtension);//判断用什么解码器转换
if (Extension == "ffmpeg")//用ffmpeg.exe 转换
{
pm.ChangeFilePhy(upFileName, playFile, imgFile);
}
else if (Extension == "mencoder")//用mencoder.exe 转换
{
pm.MChangeFilePhy(upFileName, playFile, imgFile);
}
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
btnUpload.Enabled = true;
} #region 检查视频格式
private string CheckExtension(string extension)
{
string m_strReturn = "";
foreach (string var in this.strArrFfmpeg)
{
if (var == extension)
{
m_strReturn = "ffmpeg"; break;
}
}
if (m_strReturn == "")
{
foreach (string var in strArrMencoder)
{
if (var == extension)
{
m_strReturn = "mencoder"; break;
}
}
}
return m_strReturn;
}
#endregion #region //运行tool的视频解码,
// <summary>
/// @从视频文件截图,生成在视频文件所在文件夹
/// 在Web.Config 中需要两个前置配置项:
/// 1.ffmpeg.exe文件的路径
/// <add key="ffmpeg" value="E:\aspx1\ffmpeg.exe" />
/// 2.截图的尺寸大小
/// <add key="CatchFlvImgSize" value="240x180" />
/// 3.视频处理程序ffmpeg.exe
/// </summary>
/// <param name="vFileName">视频文件地址,如:/Web/FlvFile/User1/00001.Flv</param>
/// <returns>成功:返回图片虚拟地址; 失败:返回空字符串</returns>
public string CatchImg(string vFileName, string playFile, string imgFile)
{
//取得ffmpeg.exe的路径,路径配置在Web.Config中,如:<add key="ffmpeg" value="E:\aspx1\ffmpeg.exe" /> // string tool = PublicMethod.ffmpegtool;
string tool = PublicMethod.mencodertool;
tool = Server.MapPath(tool);
if ((!System.IO.File.Exists(tool)) || (!System.IO.File.Exists(vFileName)))
{
return "";
} //获得图片和(.flv)文件相对路径/最后存储到数据库的路径,如:/Web/User1/00001.jpg
string flv_img = System.IO.Path.ChangeExtension(imgFile, ".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(tool);
System.Diagnostics.ProcessStartInfo ImgstartInfo = new System.Diagnostics.ProcessStartInfo(tool); FilestartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
ImgstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//此处组合成tool.exe文件需要的参数即可,此处命令在tool 0.4.9调试通过
//tool -i F:\01.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:\test.flv
// FilestartInfo.Arguments = " -i " + vFileName + " -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 " + flv_file;
// ImgstartInfo.Arguments = " -i " + vFileName + " -y -f image2 -t 0.001 -s " + FlvImgSize + " " + flv_img;
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=512:-3 -ofps 12 -srate 22050";
try
{
System.Diagnostics.Process.Start(FilestartInfo);
System.Diagnostics.Process.Start(ImgstartInfo);
}
catch
{
return "";
} ///注意:图片截取成功后,数据由内存缓存写到磁盘需要时间较长,大概在3,4秒甚至更长;
///这儿需要延时后再检测,我服务器延时8秒,即如果超过8秒图片仍不存在,认为截图失败;
///此处略去延时代码.如有那位知道如何捕捉tool.exe截图失败消息,请告知,先谢过!
if (System.IO.File.Exists(flv_img))
{
return flv_img;
} return "";
}
//
#endregion