• 视频转码


    /// <summary>
            /// 转换成MP4格式
            /// </summary>
            /// <param name="fromFilePath"></param>
            /// <returns></returns>
            public static string ToMp4(string fromFilePath)
            {
                string ffmpeg = HttpContext.Current.Server.MapPath("/") + "ffmpeg\bin\ffmpeg.exe";//ffmpeg执行文件的路径
                int lastIndexPort = fromFilePath.LastIndexOf(".");
                string toPathFileName = fromFilePath.Substring(0, lastIndexPort) + ".mp4";
                if ((!System.IO.File.Exists(ffmpeg)))
                {
                    return string.Empty; ;
                }
                //转mp4格式
                string Command = " -i "" + fromFilePath + ""  -c:v libx264 -strict -2 "" + toPathFileName + """;
                using (System.Diagnostics.Process p = new System.Diagnostics.Process())
                {
                    p.StartInfo.FileName = ffmpeg;
                    p.StartInfo.Arguments = Command;
                    //p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/temp/");
                    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.Dispose();
                    return toPathFileName;
                }
            }
  • 相关阅读:
    第二章 信息的表示和处理(下)
    第二章 信息的表示和处理
    IDEA中新建子模块
    手动实现一个可重入锁
    Lock接口的认识和使用
    JDK提供的原子类原理与使用
    深入理解volatile原理与使用
    模拟死锁
    模拟自旋锁
    grep 如何自动标注颜色
  • 原文地址:https://www.cnblogs.com/tangchun/p/7907529.html
Copyright © 2020-2023  润新知