日期:2014-05-18  浏览次数:20525 次

请问如何上传视频,并且更改视频的文件名,最后生成缩略图阿
请问各位adp.net中如何上传视频,最后生成缩略图啊。
能给个源代码吗?

------解决方案--------------------
Google "ffmpeg "
------解决方案--------------------
private void btAdd_Click(object sender, System.EventArgs e)
{
if(this.txtTitle.Text.Trim().Length ==0)
{
this.lblMsg.Text = "标题不能为空 ";
return;
}

string strBaseLocation = System.Configuration.ConfigurationSettings.AppSettings[ "TargetFolder "] ;
string filename = " ";

if (null != uplTheFile.PostedFile && uplTheFile.PostedFile.ContentLength > 0 )
{
if(uplTheFile.PostedFile.ContentLength> 4 * 1024 * 1024)
{
lblMsg.Text = "文件大小超过4M! ";
return;
}
System.IO.FileInfo fi = new System.IO.FileInfo(uplTheFile.PostedFile.FileName);
if(fi.Extension.ToLower() != ".avi " && fi.Extension.ToLower() != ".wmv " && fi.Extension.ToLower() != ".flv ")
{
lblMsg.Text = "文件格式应为AVI, WMV, FLV视频! 现在格式为: " + fi.Extension.ToLower();
return;
}

filename = Guid.NewGuid().ToString() + fi.Name;

try
{
uplTheFile.PostedFile.SaveAs(strBaseLocation + @ "old\ " + filename);
}
catch (Exception ee)
{
throw ee;
}
}

string itemID = Framework.AddNewItem(this._userID,CMS.HandleString(this.txtTitle.Text),
CMS.HandleString(this.txtDesc.Text), CMS.HandleString(this.txtDesc.Text));

string fileName = System.Configuration.ConfigurationSettings.AppSettings[ "FFMpeg "];

string orginalFile = strBaseLocation + @ "old\ " + filename;
string targetFile = strBaseLocation + itemID + ".flv ";
string argu = @ "-i " + orginalFile + " -ab 56 -ar 22050 -b 500 -r 15 -s 480x360 " + targetFile;

try
{
if(! fileName.EndsWith( ".flv "))
{
try
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(fileName,argu);
System.Diagnostics.Process.Start(startInfo);
}
catch
{
throw;
}

System.Threading.Thread.Sleep(6000);
}
else
{
System.IO.File.Copy(orginalFile, targetFile);
}

//picture
argu = @ "-i " + targetFile + " -y -f image2 -ss 08.010 -t 0.001 -s 352x240 " + strBaseLocation + itemID + ".jpg ";
System.Diagnostics.ProcessStartInfo startInfo1 = new System.Diagnostics.ProcessStartInfo(fileName,argu);
System.Diagnostics.Process.Start(startInfo1);
System.Threading.Thread.Sleep(2000);

if(! System.IO.File.Exists(strBaseLocation + itemID + ".jpg "))
{
System.IO.File.Copy(strBaseLocation + "17.jpg ", strBaseLocation + itemID + ".jpg ");
}

}
catch(Exception ee)
{
throw ee;
}

if(System.IO.File.Exists(targetFile) && (new System.IO.FileInfo(targetFile)).Length> 10000)
{
this.lblMsg.Text = " <a href= 'viewitem.aspx?itemid= " + itemID + " '> 添加成功! </a> ";
}
else
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(fileName,argu);