ffmpeg+mencoder的视频格式转换

一、ffmpeg+mencoder知识普及

"  ffmpeg+mencoder几乎可以完成目前基于web的播客平台任何音视频处理的操作.如果还需要添加一些什么的话,那么就是视频在线录制功能了,这个也可以用ffmpeg+fms来完成,因此一般的类似于YouTube的一些可见功能都可以在ffmpeg+mencoder+fms来做后台实现.由于fms没有实践,因此这里不描述.   本文档有三部分:   1)ffmpeg+mencoder环境搭建   2)常见操作说明   3)个人的一些使用心得  1.ffmpeg+mencoder环境搭建   1)概论   音视频界众多的编解码协议和各个公司定义的专用格式导致目前的视频音频文件纷繁复杂,单纯的ffmpeg支持的格式并不完全包括所有种类,至少swf,rmvb(rv4)目前的版本是不支持的.同时wma9似乎可以支持了.但没有测试.同时mencoder能支持rm,rmvb等格式,但是从视频中获取某帧截图的工作只能由ffmpeg完成.因此可以采用ffmpeg+mencoder完成目前所有流行格式的视频压缩转换,设置视频信息,截取视频中的图片等功能了,同时,采用其他的一些开源工具如MediaInfo可以获取视频的元数据信息.

2.常见操作说明   对于ffmpeg,可以将除swf,rmvb,wmav9以外的视频/音频格式转换成flv/mp3,同时可以截取这些视频文件中的某个时间的该帧图片.这些实际上就是一个视频播客显示的部分.对于mencoder,支持各种常见格式的视频/音频转换成flv/mp3.或者转换成avi.   1)ffmpeg篇:    ffmpeg进行操作的常用方法:       1.转换成flv文件:ffmpeg -i infile.* -y (-ss second_offset -ar ar -ab ab -r vr -b vb -s vsize) outfile.flv           其中second_offset是从开始的多好秒钟.可以支持**:**:**格式,至于ar,ab是音频的参数,可以指定ar=22050,24000,44100(PAL制式),48000(NTSC制式),后两种常见,ab=56(视音频协议的codec而定,如果要听高品质,则80以上).vr,vb,vsize是视频参数,可以指定vr=15,25(PAL),29(NTSC),vb=200,500,800,1500(视视频协议的codec而定,可以通过查看专业的codec说明文档获取,如果你手头有一份详细的各种codec的文档,请提供一份给我,不胜感激.)             还有一些参数-acodec ac -vcodec vc(ac指定音频codec,ar和ab可以省去,vc指定视频codec,vr和vb可以省去,自动采用相应的codec参数)           2.截取图片:ffmpeg -i infile.* -y (-ss second_offset) -t 0.001 -s msize (-f image_fmt) outfile.jpg            其中second_offset同上,msize同vsize,图片大小.image_fmt=image2强制使用jpg,image_fmt=gif,强制使用gif格式.       2)mencoder篇:     mencoder的作用主要在视频转码方面.在安装完mplayer后,mencoder也编译生成了.可以man mencoder获取mencoder的说明文档. mencoder的参数更加复杂,不过也无非是音频处理视频处理两个方面,可以参看网络例子:http://www.masoncn.com/post/144.html.这里不作详细的列举了.       mencoder进行操作的常用方法: mencoder infile.* -o outfile.* [-ovc 目标视频格式] [-oac 目标音频格式] [-of 目标文件格式]       1.转换成flv文件: mencoder infile.* -o outfile.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=150:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050              mencoder infile.rmvb -o outfile.flv -vf scale=-3:150 -ofps 12 -oac mp3lame -ovc xvid -xvidencopts bitrate=112        2.转换成avi文件: mencoder infile.* -o outfile.avi -of avi -oac mp3lame -lameopts preset=64 -ovc xvid -xvidencopts bitrate=600       3.转换成wmv文件(复杂写法,其中高级参数可以省去): mencoder infile.* -o outfile.wmv -of lavf -ofps 25 -oac mp3lame -lameopts cbr:preset=128 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=768:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=320:240 -srate 22050 -sws 9 -subcp cp936 -subpos 0 -subalign 0 -subfont-text-scale 3 -lavfopts i_certify_that_my_video_strea       4.截图:  mplayer infile -ss START_TIME -noframedrop -nosound -vo jpeg -frames N       其中-ovc,-oac和-of是必须的,-ovc是指定视频codec,指定了ovc之后通常带一个该codec的opt参数,-oac是指定音频codec,也会在其后带一个codec的opt参数.可以指定细节以决定视频音频质量和转换速率.具体的细节可以参看专业的技术文档."

From:http://wf.xplore.cn/read.php/90.htm

       二、参数设置说明

           上一篇http://wf.xplore.cn/read.php/90.htm也有很详细的参数说明,只是是英文的,摘录部分如下:

“引用

Main options: -L                  show license -h                  show help -version            show version -formats            show available formats, codecs, protocols, ... -f fmt              force format -i filename         input file name -y                  overwrite output files -t duration         set the recording time -fs limit_size      set the limit file size -ss time_off        set the start time offset -itsoffset time_off  set the input ts offset -title string       set the title -timestamp time     set the timestamp -author string      set the author -copyright string   set the copyright -comment string     set the comment -album string       set the album -v verbose          control amount of logging -target type        specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...) -dframes number     set the number of data frames to record -scodec codec       force subtitle codec ('copy' to copy stream) -newsubtitle        add a new subtitle stream to the current output stream -slang code         set the ISO 639 language code (3 letters) of the current subtitle stream Video options: -vframes number     set the number of video frames to record -r rate             set frame rate (Hz value, fraction or abbreviation) -s size             set frame size (WxH or abbreviation) -aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) -croptop size       set top crop band size (in pixels) -cropbottom size    set bottom crop band size (in pixels) -cropleft size      set left crop band size (in pixels) -cropright size     set right crop band size (in pixels) -padtop size        set top pad band size (in pixels) -padbottom size     set bottom pad band size (in pixels) -padleft size       set left pad band size (in pixels) -padright size      set right pad band size (in pixels) -padcolor color     set color of pad bands (Hex 000000 thru FFFFFF) -vn                 disable video -vcodec codec       force video codec ('copy' to copy stream) -sameq              use same video quality as source (implies VBR) -pass n             select the pass number (1 or 2) -passlogfile file   select two pass log file name -newvideo           add a new video stream to the current output stream Subtitle options: -scodec codec       force subtitle codec ('copy' to copy stream) -newsubtitle        add a new subtitle stream to the current output stream -slang code         set the ISO 639 language code (3 letters) of the current subtitle stream Audio/Video grab options: -vd device          set video grab device -vc channel         set video grab channel (DV1394 only) -tvstd standard     set television standard (NTSC, PAL (SECAM)) -ad device          set audio device -grab format        request grabbing using -gd device          set grab device Advanced options: -map file:stream[:syncfile:syncstream]  set input stream mapping -map_meta_data outfile:infile  set meta data information of outfile from infile -benchmark          add timings for benchmarking -dump               dump each input packet -hex                when dumping packets, also dump the payload -re                 read input at native frame rate -loop_input         loop (current only works with images) -loop_output        number of times to loop output in formats that support looping (0 loops forever) -threads count      thread count -vsync              video sync method -async              audio sync method -vglobal            video global header storage type -copyts             copy timestamps -shortest           finish encoding within shortest input -dts_delta_threshold   timestamp discontinuity delta threshold -ps size            set packet size in bits -muxdelay seconds   set the maximum demux-decode delay -muxpreload seconds  set the initial demux-decode delay

查看中文的参数说明,可以参考:http://www.lougoo.com/blog/article.asp?id=649

    三、实例篇

http://www.cnblogs.com/xiucai/archive/2007/06/19/788598.html

http://hi.baidu.com/assassionman/blog/item/cc4082a18d914883471064ac.html

http://hi.baidu.com/ligg/blog/item/03dd1dd5629123c350da4b54.html

    四、经验篇

    “可能的难点:因为这ffmpeg 和 Mencoder都是命令行工具(当然你也可以下载源代码自己修改成com之类的),在C#只能用Process调用,前面我提过要获得输出信息(获取视频相关信息、获取当前的转换进度、获取什么时候完成转换),必须设置process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true;然后必须通过异步编程的方式获取Process.StandardOutput和Process.StandardError的值,相关说明可以见(ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemDiagnosticsProcessClassStandardOutputTopic.htm)(必须安装了msdn的才能看)。”

http://www.cnblogs.com/csky/archive/2007/03/13/673140.html

    五、相关下载链接:

    ffmpeg最新版本的下载地址:http://ffdshow.faireal.net/mirror/ffmpeg/     Mencoder新版本的下载地址:http://www5.mplayerhq.hu/MPlayer/releases/win32/

原文地址:https://www.cnblogs.com/cnzryblog/p/2973331.html