.Net视频格式转换器源码 视频格式转为Flv

方便快捷的C#视频格式转换帮助类库,

输入原视频文件地址即可得到转换后的Flv新视频文件



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AutoHome.CommonHelper
{
    public class VideoConvert
    {
        //.Net视频格式转换器源码 视频格式转为Flv
        #region 转换参数配置
        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 视频格式转为Flv
        /// <summary>
        /// 视频格式转为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 获得当前绝对路径
        /// <summary>
        /// 获得当前绝对路径
        /// </summary>
        /// <param name="strPath">指定的路径</param>
        /// <returns>绝对路径</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视频格式转换器源码 视频格式转为Flv