您的位置:首页 > 编程语言 > C#

C#视频处理,调用强大的ffmpeg

2020-06-04 06:25 736 查看

我是转载的博客 原链接:https://blog.csdn.net/cctvcqupt/article/details/80695879
ffmpeg的官网:https://ffmpeg.org/

ffmpeg是一个强大的视频处理软件(控制台程序),可以通过C# 调用ffmpeg,并传入指令参数,即可实现视频的编辑。

///
/// 设置ffmpeg.exe的路径
///
static string FFmpegPath = @“C:\Users\Downloads\ffmpeg-20180613-67747c8-win64-static\bin\ffmpeg.exe”;

static void Main(string[] args)
{
string videoUrl = @"D:\video\Wildlife.wmv";
string targetUrl = @"D:\video\newFile.mp4";

//视频转码
string para = string.Format("-i {0} -b 1024k -acodec copy -f mp4 {1}", videoUrl, targetUrl);
RunMyProcess(para);

Console.WriteLine("完成!");
Console.ReadKey();
}

static void RunMyProcess(string Parameters)
{
var p = new Process();
p.StartInfo.FileName = FFmpegPath;
p.StartInfo.Arguments = Parameters;
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
//不显示程序窗口
p.StartInfo.CreateNoWindow = true;
p.Start();
Console.WriteLine("\n开始转码...\n");
p.WaitForExit();
p.Close();
}

合并视频
string para = string.Format(" -f concat -safe 0 -i {0} -c copy {1}", @“D:\video\filelist.txt”, @“D:\video\c.mp4”);
filelist.txt的内容:

file ‘D:\video\input1.mp4’
file ‘D:\video\input2.mp4’

————————————————
版权声明:本文为CSDN博主「布里渊区」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cctvcqupt/article/details/80695879

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: