FFmpeg的使用及常用参数
一.下载:
二.demo:
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 string srcFileName = @"F:资料DemoFFmpeg_DemovideooldPROMO.wmv";
6 string destFileName = @"F:资料DemoFFmpeg_DemovideonewPROMO.mp4";
7
8 Process p = new Process();
9 p.StartInfo.FileName = @"F:资料DemoFFmpeg_Demomencoderffmpeg.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 }
三.ffmpeg各种视频处理:(注意参数顺序)
1.视频转换:
avi-------------------------->flv
ffmpeg -i file.avi output.flv
MPEG-1--------------->MPEG-4
ffmpeg -i inputfile.mpg -f mp4 -acodec libfaac -vcodec mpeg4 -b 256k -ab 64k outputfile.mp4
MP3------------------->MPEG-4
ffmpeg -i inputfile.mp3 -f mp4 -acodec libaac -vn -ab 64k outputfile.mp4
DVD的VOB---------->VideoCD格式的MPEG-1
ffmpeg -i inputfile.vob -f mpeg -acodec mp2 -vcodec mpeg1video -s 352x240 -b 1152k -ab 128k outputfile.mpg
AVI------------------->H.264格式的M4V
ffmpeg -i inputfile.avi -f mp4 -acodec libfaac -vcodec libx264 -b 512k -ab 320k outputfile.m4v
任何------------------->东芝REGZA可辨识的MPEG2
ffmpeg -i inputfile -target ntsc-svcd -ab 128k -aspect 4:3 -s 720x480 outputfile.mpg
2.音频视频合并:ok
ffmpeg -i input1.avi -i input2.mp3 -vcodec copy -acodec copy out.avi
3.拆分音频视频:ok
提取音频:
ffmpeg -i input.flv -vn -acodec copy out.mp3
提取视频:
ffmpeg -i input.flv -an -vcodec copy out.flv ok
ffmpeg -i input.flv out.flv -an -vcodec copy error------->注意参数顺序
音视频都提取:
ffmpeg -i input.flv -an out1.flv -vn out2.mp3
4.提取图片:ok
ffmpeg -i input.avi -y -f image2 -ss 8 -t 0.001 -s 350x240 out.jpg
5.压缩文件:ok
ffmpeg -i input.mp3 -ab 128 out.mp3
6.截取指定的时间间隔的视频:ok
ffmpeg -ss 00:00:10 -t 00:01:22 -i 五月天-突然好想你.mp3 out.mp3
7.屏幕录像:
ffmpeg -f x11grab -s xga -r 10 -i :0.0+0+0 wheer.avi
ffmpeg -f x11grab -s 320x240 -r 10 -i :0.0+100+200 wheer.avi
ffmpeg -f x11grab -s xga -qscale 5 -r 10 -i :0.0+0+0 wheer.avi
8.屏幕录像,同时录音:
ffmpeg -f oss -i /dev/dsp -f x11grab -r 30 -s 1024x768 -i :0.0 output.mkv
ffmpeg -ac 2 -f oss -i /dev/dsp -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv
9.屏幕录像,指定窗口:
10.视频连接:
ffmpeg -i input1.avi -i input2.avi output.avi -vcodec copy -acodec copy
11.分割视频:ok
ffmpeg -ss 01:00:00 -i input.mp4 -vcodec copy -acodec copy -t 00:06:00 out.mp4
四.参数:
1.常用参数:
-ab bitrate 设置音频码率
-acodec codec 使用codec编解码
-ac channels 设置通道,缺省为1
-ar freq 设置音频采样率
-r fps 设置帧频,缺省25
-b bitrate 设置比特率,缺省200kb/s
-qscale 6或4 使用动态码率来设置
-vcodec libx264 这个应该是个编码设置,网上查到 libx264.dll
2.更多参数:
参考官网:http://ffmpeg.org/ffmpeg-all.html