zoukankan      html  css  js  c++  java
  • 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 "";
            }
  • 相关阅读:
    曾今的代码系列——获取当天最大流水号存储过程
    曾今的代码系列——生产者消费者模式
    利用Microsoft.VisualBasic中TextFieldParser解析器把CSV格式倒入数据库
    曾今的代码系列——自己的分页控件+存储过程实现分页
    ASP.NET那点不为人知的事(四)
    SharePoint下用C#代码上传文档至文档库的子文件夹中
    Entity Framework 4 in Action读书笔记——第四章:使用LINQ to Entities查询:使用函数
    Entity Framework 4 in Action读书笔记——第四章:使用LINQ to Entities查询:预先加载和延迟加载
    这几天Colorbox让我寝食难安
    使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四)——完成篇
  • 原文地址:https://www.cnblogs.com/Mzg121584668/p/10937906.html
Copyright © 2011-2022 走看看