FFmpeg的使用及常用参数
一.下载:
二.demo:
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 string srcFileName = @"F:\资料\Demo\FFmpeg_Demo\videoold\PROMO.wmv";
6 string destFileName = @"F:\资料\Demo\FFmpeg_Demo\videonew\PROMO.mp4";
7
8 Process p = new Process();
9 p.StartInfo.FileName = @"F:\资料\Demo\FFmpeg_Demo\mencoder\ffmpeg.exe";
10 p.StartInfo.UseShellExecute = false;
11
12 p.StartInfo.Arguments = "-i " + srcFileName + GenerateDefaultSetting() + destFileName;
13
14
15 p.StartInfo.RedirectStandardInput = true;
16 p.StartInfo.RedirectStandardOutput = true;
17 p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中
18 p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
19 p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
20 p.Start();
21 p.BeginErrorReadLine();//开始异步读取
22 p.WaitForExit();//阻塞等待进程结束
23 p.Close();//关闭进程
24 p.Dispose();//释放资源
25 Console.WriteLine("ok");
26 Console.ReadKey();
27 }
28 private static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
29 {
30 Console.WriteLine(e.Data);
31 }
32 private static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
33 {
34 Console.WriteLine(e.Data);
35 }
36
37 private static string GenerateDefaultSetting()
38 {
39 string setting = string.Empty;
40 setting += " -y ";
41 //setting += " -b 800 ";//-b大于0就模糊【?】
42 setting += " -ab 56 ";
43 setting += " -ar 22050 ";
44 setting += " -qscale 4 ";
45 setting += " -r " + 29.970;
46 setting += " -ac 2 ";
47 setting += " -s " + 640 + "x" + 480 + " ";
48 return setting;
49 }
50 }