ffmpeg 视频合并

        /// <summary>
        /// 视频合并
        /// </summary>
        /// <param name="File1">第一个视频地址</param>
        /// <param name="File2">第二个视频地址</param>
        /// <param name="DstFile">合成后存放路径</param>
        /// <returns></returns>
        static string Combine(string File1, string File2, string DstFile)
        {
            string strTmp1 = File1 + ".ts";
            string strTmp2 = File2 + ".ts";
            string strCmd1 = " -i " + File1 + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + strTmp1 + " -y ";
            string strCmd2 = " -i " + File2 + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + strTmp2 + " -y ";


            //string strCmd = " -i concat:"" + strTmp1 + "|" +
            //strTmp2 + "" -c copy -bsf:a aac_adtstoasc -movflags +faststart " + DstFile + " -y ";
            string strCmd = " -i "concat:" + strTmp1 + "|" + strTmp2 + "" -c copy -bsf:a aac_adtstoasc -movflags +faststart " + DstFile + " -y ";



            //转换文件类型,由于不是所有类型的视频文件都支持直接合并,需要先转换格式
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "D:\Work\tpp20190322\uploadtemp\ffmpeg.exe";//要执行的程序名称 
            p.StartInfo.Arguments = " " + strCmd1;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = false;//可能接受来自调用程序的输入信息 
            p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息 
            p.StartInfo.RedirectStandardError = false;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = false;//不显示程序窗口


            p.Start();//启动程序 
            p.WaitForExit();


            //转换文件类型,由于不是所有类型的视频文件都支持直接合并,需要先转换格式
            p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "D:\Work\tpp20190322\uploadtemp\ffmpeg.exe";//要执行的程序名称 
            p.StartInfo.Arguments = " " + strCmd2;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = false;//可能接受来自调用程序的输入信息 
            p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息 
            p.StartInfo.RedirectStandardError = false;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = false;//不显示程序窗口


            p.Start();//启动程序 
            p.WaitForExit();




            //合并
            p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "D:\Work\tpp20190322\uploadtemp\ffmpeg.exe";//要执行的程序名称 
            p.StartInfo.Arguments = " " + strCmd;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = false;//可能接受来自调用程序的输入信息 
            p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息 
            p.StartInfo.RedirectStandardError = false;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = false;//不显示程序窗口


            p.Start();//启动程序


            //向CMD窗口发送输入信息: 
            // p.StandardInput.Write("ipconfig");


            //string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();//等待程序执行完退出进程
            //-ss表示搜索到指定的时间 -i表示输入的文件 -y表示覆盖输出 -f表示强制使用的格式


            if (System.IO.File.Exists(DstFile))
            {
                return DstFile;
            }
            return "";
        }
原文地址:https://www.cnblogs.com/Mzg121584668/p/10937906.html