当前位置:网站首页>ffmpeg合并视频功能
ffmpeg合并视频功能
2022-07-27 02:56:00 【勤学路无边】
合并视频,文件为几MB的视频合并没有问题,大文件没有声音。等以后找到方法在补充。 或者谁知道怎么解决,求指教!!!
ffmpeg官方地址http://www.ffmpeg.org/download.html
//打开文件夹选择视频
private void Button1_Click(object sender, EventArgs e)
{
var f = new OpenFileDialog();
if (f.ShowDialog() == DialogResult.OK)
{
String filepath = f.FileName;//G:\新建文件夹\新建文本文档.txt
String filename = f.SafeFileName;//新建文本文档.txt
this.textBox1.Text = filepath;
}
}
//合并按钮
private void Button4_Click(object sender, EventArgs e)
{
//合并后的地址
string newPath = " D:\\Video\\abc.mp4";
List<string> fileList = new List<string>();
fileList.Add(textBox1.Text);//选择的文件1地址
fileList.Add(textBox2.Text);//选择的文件2地址
fileList.Add(textBox3.Text);//选择的文件3地址
MergeVideoService.MergeVideo(progressBar1, newPath, fileList.ToArray());
//Combine(textBox1.Text, textBox2.Text, textBox3.Text, newPath);
label1.Text = "合并后的地址:" + newPath;
}
/// <summary>
/// 合并两个或多个视频
/// </summary>
/// <param name="progressBar">进度条</param>
/// <param name="mergeFilePath">合并后的视频路径</param>
/// <param name="filePaths">要合并的视频文件路径数组</param>
/// <returns></returns>
public static bool MergeVideo(ProgressBar progressBar, string mergeFilePath, params string[] filePaths)
{
if (filePaths == null || filePaths.Length < 2) return false;
//进度条设置
progressBar.Maximum = 100;//设置最大长度值
progressBar.Value = 0;//设置初始值为0
progressBar.Step = 90 / filePaths.Length;//设置每次增长多少
//转换后文件名list
List<string> strTmpList = new List<string>();
Process p = new Process();
foreach (string item in filePaths)
{
//文件转换为.ts文件
string strTmp = Path.ChangeExtension(item, "ts");
strTmpList.Add(strTmp);
string strCmdItem = " -i " + item + " -vcodec copy -acodec copy -vbsf h264_mp4toannexb " + strTmp + " -y ";
//转换文件类型,由于不是所有类型的视频文件都支持直接合并,需要先转换格式
p = new System.Diagnostics.Process();
//要执行的程序名称
p.StartInfo.FileName = "ffmpeg.exe";
p.StartInfo.Arguments = " " + strCmdItem;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = false;//可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = false;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = false;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序
p.WaitForExit();
progressBar.Value += progressBar.Step;
}
//合并命令的拼写
string strCmd = "-i concat:\"";
foreach (string tmp in strTmpList)
{
strCmd += tmp + "|";
}
string cmd = strCmd;
strCmd = cmd.Substring(0, cmd.Length - 1);
strCmd += "\" -vcodec copy -acodec copy " + mergeFilePath + " -y";
//合并
p = new System.Diagnostics.Process();
p.StartInfo.FileName = "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 = true;//不显示程序窗口
p.Start(); //启动程序
p.WaitForExit();//阻塞等待进程结束
progressBar.Value = 100;
p.Close();//关闭进程
p.Dispose();//释放资源
foreach (string tmp in strTmpList)
{
//删除后缀.ts文件
if (File.Exists(tmp))
{
File.Delete(tmp);
}
}
return true;
}
边栏推荐
- Application of one-dimensional array
- Use tag tag in golang structure
- C语言学习笔记 —— 内存管理
- Greenplum [deployment 08] database small version upgrade process and problem handling error: open-source-greenplum-db-6 conflicts with
- 2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作
- 整理字符串
- [Yugong series] July 2022 go teaching course 018 switch of branch structure
- Introduction to JVM principle
- Collating strings
- 面试题 02.05. 链表求和
猜你喜欢
随机推荐
0726~简历梳理面试总结
真正意义上的数字零售应当具有更加丰富的内涵和意义
大咖说·图书分享|精益产品开发:原则、方法与实施
Maximum nesting depth of parentheses
Day 28 of leetcode
想要获得 Apache 官方域名邮箱吗?专访 Apache Linkis 五位新晋 Committer告诉你怎么做
Introduction to JVM principle
Message queue learning -- Concepts
什么是动画效果?什么是过渡效果?
Chapter 4 decision tree and random forest
C # using sqlsugar updatable system to report invalid numbers, how to solve it? Ask for guidance!
Startup process and rescue mode
H.265网页播放器EasyPlayer对外开放录像的方法
【SemiDrive源码分析】【驱动BringUp】41 - LCM 驱动 backlight 背光控制原理分析
B. ICPC Balloons
面试题 02.05. 链表求和
二叉树的坡度
Leetcode daily exercise: sort sentences
Interview question 16.05 factorial mantissa
Subject 3: Jinan Zhangqiu line 2









