.Net視頻格式轉(zhuǎn)換器源碼 視頻格式轉(zhuǎn)為Flv
方便快捷的C#視頻格式轉(zhuǎn)換幫助類庫,
輸入原視頻文件地址即可得到轉(zhuǎn)換后的Flv新視頻文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AutoHome.CommonHelper
{
public class VideoConvert
{
//.Net視頻格式轉(zhuǎn)換器源碼 視頻格式轉(zhuǎn)為Flv
#region 轉(zhuǎn)換參數(shù)配置
private static string ffmpegtool = GetMapPath("bin/tool/ffmpeg.exe");
private static string mencodertool = GetMapPath("bin/tool/mencoder.exe");
private static string workpath = GetMapPath("bin/tool/");
#endregion
#region 視頻格式轉(zhuǎn)為Flv
/// <summary>
/// 視頻格式轉(zhuǎn)為Flv
/// </summary>
/// <param name="vFileName">原視頻文件地址</param>
/// <param name="ExportName">生成后的Flv文件地址</param>
public static bool ToMp3(string vFileName, string ExportName)
{
try
{
if ((!System.IO.File.Exists(ffmpegtool)) || (!System.IO.File.Exists(vFileName)))
{
return false;
}
string Command = " -i \"" vFileName "\" \"" ExportName "\"";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = ffmpegtool;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = workpath;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}
catch (Exception ex)
{
return false;
}
}
#region 獲得當(dāng)前絕對(duì)路徑
/// <summary>
/// 獲得當(dāng)前絕對(duì)路徑
/// </summary>
/// <param name="strPath">指定的路徑</param>
/// <returns>絕對(duì)路徑</returns>
public static string GetMapPath(string strPath)
{
if (strPath.ToLower().StartsWith("http://"))
{
return strPath;
}
if (HttpContext.Current != null)
{
string path = System.Web.HttpContext.Current.Server.MapPath("/") strPath;
return path;
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
#endregion
#endregion
}
}
原文鏈接:.Net視頻格式轉(zhuǎn)換器源碼 視頻格式轉(zhuǎn)為Flv