当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
![Article main content extraction software [based on NLP technology]](/img/1c/7c1b0e9bc9af62308f4124104f6110.png)
Article main content extraction software [based on NLP technology]

PSINS工具箱中轨迹生成工具详细解析

356页14万字高端商业办公综合楼弱电智能化系统2022版

Stm32cubemx learning notes (41) -- eth interface +lwip protocol stack use (DHCP)

Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!

ApacheCon Asia 预热直播之孵化器主题全回顾

C语言学习笔记 —— 内存管理

SkyWalking分布式系统应用程序性能监控工具-中

Golang sends email to the mail Library

Function pointer and callback function
随机推荐
Daily question 1: delete continuous nodes with a total value of zero from the linked list
《MySQL》认识MySQL与计算机基础知识
开机启动流程及营救模式
DataX cannot connect to the corresponding database (yes under windows, but failed under Linux)
Application of one-dimensional array
Use tag tag in golang structure
【OBS】circlebuf
Want to get the Apache official domain name mailbox? Exclusive interview with Apache linkis five new committers to tell you how to do it
Is it safe for tongdaxin to open an account
C language learning notes - memory management
Knowledge atlas: knowledge representation
Interview question 02.05. sum of linked list
Abstract intelligent extraction [based on Bert technology]
科目三: 济南章丘二号线
List Simulation Implementation
Chapter 5 decision tree and random forest practice
C # using sqlsugar updatable system to report invalid numbers, how to solve it? Ask for guidance!
Parallels Desktop启动虚拟机“操作失败”问题解决
JS to realize page Jump and parameter acquisition and loading
【OBS】circlebuf