資源簡介
C#使用ffmpeg轉換格式,截圖,旋轉
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Web;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Diagnostics;
public?partial?class?VideoUpload?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????}
????#region
????///?
????///?視頻格式轉換
????///?
????///?原文件相對路徑
????///?轉換后保存路徑
????public?string?VideoConvertFlv(string?FromName)
????{
????????string?ffmpeg?=?Server.MapPath(“.“)?+?“?\\ffmpeg\\ffmpeg.exe“;
????????string?ExportName?=?“flv“?+?“\\“?+?DateTime.Now.ToString(“yyyyMMddhhmmss“)?+?“.flv“;
????????string?WidthAndHeight?=?“320x240“;
????????System.Diagnostics.ProcessStartInfo?startInfo?=?new?System.Diagnostics.ProcessStartInfo(ffmpeg);
????????startInfo.Windowstyle?=?System.Diagnostics.ProcessWindowstyle.Hidden;
????????startInfo.Arguments?=?“?-i?“?+?Server.MapPath(FromName)?+?“?-ab?56?-ar?22050?-b?500?-r?15?-s?“?+?WidthAndHeight?+?“?“?+?Server.MapPath(ExportName);
????????Process?proc?=?Process.Start(startInfo);
????????proc.WaitForExit();
????????return?ExportName??;
?
????}
????/**/
????///?
????///?從視頻畫面中截取一幀畫面為圖片
????///?
????///?視頻文件pic/guiyu.mov
????///?圖片的尺寸如:240*180
????///?ame“>開始截取的時間如:“1“
????///?
????public?string?GetPicFromVideo(string?VideoName?string?WidthAndHeight?string?CutTimeframe)
????{
????????string?ffmpeg?=?Server.MapPath(“.“)?+?“?\\ffmpeg\\ffmpeg.exe“;
????????string?PicName?=?Server.MapPath(“img\\“?+?DateTime.Now.ToString(“yyyyMMddhhmmss“)?+?“.jpg“);
????????System.Diagnostics.ProcessStartInfo?startInfo?=?new?System.Diagnostics.ProcessStartInfo(ffmpeg);
????????startInfo.Windowstyle?=?System.Diagnostics.ProcessWindowstyle.Minimized;
????????startInfo.Arguments?=?“?-i?“?+?Server.MapPath(VideoName)?+?“?-y?-f?image2?-ss?“?+?CutTimeframe?+?“?-t?0.001?-s?“?+?WidthAndHeight?+?“?“?+?PicName;
????????try
????????{
????????????Process?proc?=?Process.Start(startInfo);
????????????proc.WaitForExit();
????????????return?PicName;
????????}
????????catch?(Exception?err)
????????{
????????????return?err.Message;
????????}
????}
????public?string?GetPicFromVideo1(string?VideoName)
????{
????????string?VideoName1?=?“Upload\\tp1584351056226261.mp4“;
????????string?ffmpeg?=?Server.MapPath(“.“)?+?“?\\ffmpeg\\ffmpeg.exe“;
????????string?PicName?=?Server.MapPath(“img\\“?+?DateTime.Now.ToString(“yyyyMMddhhmmss“)?+?“.jpg“);
????????System.Diagnostics.ProcessStartInfo?startInfo?=?new?System.Diagnostics.ProcessStartInfo(ffmpeg);
????????startInfo.Windowstyle?=?System.Diagnostics.ProcessWindowstyle.Minimized;
?????
?????????string??sed=“\“rotate?=?90?*?PI?/?180\““;
????????string?sdgf?=?“\“transpose=1\““;
????????startInfo.Arguments?=?“?-i?“?+?Server.MapPath(VideoName)?+?“?-vf?“+?sdgf?+?“?“?+?Serv
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???24364544??2013-10-21?07:52??VideoCenter\ffmpeg\ffmpeg.exe
?????文件???????4529??2015-12-04?16:23??VideoCenter\img\20151204042349.jpg
?????文件???????4529??2015-12-04?16:23??VideoCenter\img\20151204042354.jpg
?????文件???????4529??2015-12-04?16:23??VideoCenter\img\20151204042358.jpg
?????文件????8752428??2015-12-18?11:10??VideoCenter\Upload\tp158435105622626.mp4
?????文件????1725402??2015-12-18?16:31??VideoCenter\Upload\tp1584351056226261.mp4
?????文件????????736??2015-12-18?16:46??VideoCenter\VideoUpload.aspx
?????文件???????3941??2015-12-18?16:46??VideoCenter\VideoUpload.aspx.cs
?????文件????????431??2010-11-01?11:01??VideoCenter\web.config
?????文件????????171??2010-11-19?09:59??VideoCenter\說明.txt
?????目錄??????????0??2015-12-04?16:14??VideoCenter\ffmpeg
?????目錄??????????0??2010-11-19?09:50??VideoCenter\flv
?????目錄??????????0??2015-12-18?16:30??VideoCenter\img
?????目錄??????????0??2015-12-18?16:30??VideoCenter\Upload
?????目錄??????????0??2015-12-18?16:46??VideoCenter
-----------?---------??----------?-----??----
?????????????34861240????????????????????15
評論
共有 條評論