ffplay flv mp4 转_FLV与MP4格式视频转换
【實例簡介】
這個是一windows服務程序,可以通過配置指定的視頻文件夾轉換flv的視頻為MP4格式。
此服務調用ffmpeg.exe應用程序進行視頻轉換
【實例截圖】
【核心代碼】
string ffmpeg = Transfrom.ffmpegtool;
string ? path ? = ? System.IO.Directory.GetCurrentDirectory();//Environment.CurrentDirectory
if (string.IsNullOrEmpty(ffmpeg))
{
ffmpeg = path ffmpeg;
}
else
{
//ffmpeg = ffmpeg "\\ffmpeg\\ffmpeg.exe";
}
FileLog.Error("文件路徑:" ffmpeg);
//判斷轉換工具,轉換文件是否存在
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
{
//Log.Info("ffmpeg.exe或轉換文件不存在!");
return "false";
}
//獲得(.flv)文件
string flv_file = System.IO.Path.ChangeExtension(playFile, extenName);
Process p = new Process();//建立外部調用線程
try
{
//執行文件轉換
p.StartInfo.FileName = ffmpeg;//要調用外部程序的絕對路徑
p.StartInfo.Arguments = @"-y -i " fileName " -acodec libfaac -ab 64k -vcodec libx264 -threads 0 -coder 1 -flags loop -cmp chroma -partitions parti8x8 parti4x4 partp8x8 partb8x8 -me_method umh -subq 8 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -directpred 3 -trellis 1 -flags2 bpyramid mixed_refs wpred dct8x8 fastpskip -wpredp 2 -rc_lookahead 50 -refs 6 -bf 5 -b_strategy 2 -crf 22 " "" " -s 640x" 360 " " flv_file;
// " -i " fileName " -ab 56 -ar 22050 -b 500 -r 15 -s " widthSize "x" heightSize " " flv_file; //" -i " fileName " -ar 22050 ?" flv_file;//參數(這里就是FFMPEG的參數了)
p.StartInfo.UseShellExecute = false;//不使用操作系統外殼程序啟動線程(一定為FALSE,詳細的請看MSDN)
p.StartInfo.RedirectStandardError = true;//把外部程序錯誤輸出寫到StandardError流中(這個一定要注意,FFMPEG的所有輸出信息,都為錯誤輸出流,用StandardOutput是捕獲不到任何消息的...這是我耗費了2個多月得出來的經驗...mencoder就是用standardOutput來捕獲的)
//p.StartInfo.CreateNoWindow = false;//不創建進程窗口
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();//啟動線程
//p.WaitForExit();//等待完成
p.StandardError.ReadToEnd();//開始同步讀取
}
catch (Exception e)
{
//Log.Info("視頻轉碼出錯 Error={0}", e.ToString());
return "false";
}
finally
{
p.Close();//關閉進程
p.Dispose();//釋放資源
}
總結
以上是生活随笔為你收集整理的ffplay flv mp4 转_FLV与MP4格式视频转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android stuido拨打电话,A
- 下一篇: 鼠标右键失灵怎么办鼠标右键失灵原因与解决