生活随笔
收集整理的這篇文章主要介紹了
视频上传
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、用戶上傳視頻文件
注意:調(diào)整允許上傳文件的大小:
ASP.Net為了防止過大的http惡意請求阻塞網(wǎng)站,所以限定了每次上傳文件最大4M,asp.net1.1中把用戶上傳的文件先放到內(nèi)存中,2.0后如果上傳的文件過大(默認(rèn)256K)則會把文件保存到磁盤中。
不要修改全局的web.config來解除限制,保證安全,只對視頻上傳的ashx文件夾添加獨(dú)立的web.config
<system.web>
<httpRuntime maxRequestLength=
"204800" requestLengthDiskThreshold=
"1024"/>
</system.web>
?
maxRequestLength 表示最大上傳文件的長度(KB為單位)。requestLengthDiskThreshold表示最多上傳204800K(200M),大于1024K以后保存到磁盤,防止占用內(nèi)存空間。
通過根文件夾和子文件夾中設(shè)置不同的AppSettings值來看到:子文件夾中的Web.Config可以覆蓋父文件夾中的設(shè)置。這樣對于上傳的文件夾才把上傳限制放開到200MB。
2、啟動FFMepg進(jìn)行轉(zhuǎn)碼、抓縮略圖
最牛的:利用ffmpeg讓用戶上傳任意格式的視頻、生成預(yù)覽圖片、動態(tài)gif預(yù)覽圖片,然后轉(zhuǎn)換為flv、多線程。
//創(chuàng)建并啟動一個新進(jìn)程
Process p =
new Process();
//設(shè)置進(jìn)程啟動信息屬性StartInfo,這是ProcessStartInfo類,包括了一些屬性和方法:
p.StartInfo.FileName = Server.MapPath(
"/ffmpeg/ffmpeg.exe");
//程序名
p.StartInfo.UseShellExecute =
false;
//-y選項(xiàng)的意思是當(dāng)輸出文件存在的時候自動覆蓋輸出文件,不提示“y/n”這樣才能自動化// string srcFileName = Server.MapPath("/Video/aa.avi");
//string destFile =Server.MapPath("/Video/1.jpg");
//p.StartInfo.Arguments = "-i " + srcFileName + " -y -f image2 -ss 53 -t 0.001 -s 600x500 " + destFile; //執(zhí)行參數(shù)string srcFileName = Server.MapPath(
"/Video/aa.avi");
string destFileName = Server.MapPath(
"/Video/a.flv");
p.StartInfo.Arguments =
"-i " + srcFileName +
" -y -ab 56 -ar 22050 -b 800 -r 29.97 -s 420x340 " + destFileName;
//執(zhí)行參數(shù)
p.StartInfo.RedirectStandardInput =
true;
p.StartInfo.RedirectStandardOutput =
true;
p.StartInfo.RedirectStandardError =
true;
//把外部程序錯誤輸出寫到StandardError流中
p.ErrorDataReceived +=
new DataReceivedEventHandler(p_ErrorDataReceived);
p.OutputDataReceived +=
new DataReceivedEventHandler(p_OutputDataReceived);
p.Start();
p.BeginErrorReadLine();//開始異步讀取
p.WaitForExit();
//阻塞等待進(jìn)程結(jié)束
p.Close();
//關(guān)閉進(jìn)程
p.Dispose();
//釋放資源 ?
轉(zhuǎn)碼結(jié)束后p.WaitForExit()才會返回
這樣在轉(zhuǎn)碼、抓圖結(jié)束后在數(shù)據(jù)庫中添加一條記錄(建一個和視頻表:Id、Title、FlvPath:Flv的路徑、ThumbPath:縮略圖的路徑)
3、做一個頁面展示所有的視頻,點(diǎn)擊某個視頻后打開頁面,使用OsFLVPlayer播放視頻
轉(zhuǎn)載于:https://www.cnblogs.com/guohuiru/archive/2013/05/03/3057051.html
總結(jié)
以上是生活随笔為你收集整理的视频上传的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。