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篇
首先获取软件包:ffmpeg,lame(支持mp3),ogg vorbis,x264(h264 codec),xvid,3gp,libdts,mpeg4 aac.这些软件包在71.21的/home/zhengyu/tools里面都能找到.如果需要网上下载的话,可以提供下载地址.
ffmpeg官网下载:
http://ffmpeg.mplayerhq.hu... 如果官网下载有问题的,
xplore也提供了1月30的snapshot:
下载ffmpeg.
lame下载:当前版本为3.97,
http://sourceforge.net/pro... 或者到xplore
下载lame.
ogg vorbis:这个一般的redhat自带,不需要下载.可以去看看/usr/lib/libvorbis.a在不在,如果不在可以yum install或apt-get install.
xvid下载:
http://downloads.xvid.org/..., xplore
下载xvid.
x264下载:这个可以去
ftp://ftp.videolan.org/下寻找最近的snapshot下载,或者svn获取,注意如果ffmpeg是什么时候的,x264的snapshot也应该是什么时候的,不然编译的时候容易报错.
ftp://ftp.videolan.org/pub... xplore
下载x264的1月29日的snapshot.
libdts:
http://download.chinaunix...., xplore
下载libdts:
上面的软件包除了ffmpeg之外,在下载完成后解包,编译的参数都是./configure --prefix=/usr --enable-shared;make;sudo make install
mpeg4 aac/aad2:
http://www.audiocoding.com...,
http://www.audiocoding.com... faac和faad2在下载解包之后需要自己automake生成编译文件.其中faac的1.25版本需要将内置的configure.in文件最后的AM_OUTPUT中的几个续行去掉,并取消分行.然后按照bootstrap里面的操作进行,无非是aclocal -I .;autoheader;libtoolize --automake;automake -a --copy;autoconfig(或者前面的由autoreconf -vif替代);./configure --prefix=/usr --enable-shared;make;sudo make install;
faad2的2.5版本需要修改内置的configure.in文件,不然会在没有libbmp时编译会通不过.找到configure.in中下面一段:
引用
if test x$WITHBMP = xyes; then
AC_DEFINE([HAVE_BMP], 1, [User wants beep media player plugin built])
AM_CONDITIONAL([HAVE_XMMS], true)
AM_CONDITIONAL([HAVE_BMP], true)
fi
if test x$WITHDRM = xyes; then
改成
if test x$WITHBMP = xyes; then
AC_DEFINE([HAVE_BMP], 1, [User wants beep media player plugin built])
AM_CONDITIONAL([HAVE_XMMS], true)
AM_CONDITIONAL([HAVE_BMP], true)
else
AC_MSG_NOTICE(no bmp build configured)
AM_CONDITIONAL([HAVE_BMP], false)
fi
if test x$WITHDRM = xyes; then
然后autoreconf -vif;./configure --prefix=/usr --enable-shared;make;sudo make install;
这里提供两个已经修改好的.只需要make clean;make;sudo make install;的tar包.
faac1.25下载,
faad2.5下载.
3gp支持:在编译ffmpeg加入--enable-amr_nb --enable-amr_wb的时候,会有提示,下载:
http://www.3gpp.org/ftp/Sp...,解压的源代码文件以后把里面的文件都拷贝到ffmpeg的源代码目录下libavcodec/amrwb_float;然后下载:
http://www.3gpp.org/ftp/Sp...,解压得源代码文件以后把里面的文件都拷贝到ffmpeg解包目录下的libavcodec/amr_float,然后交给ffmpeg编译去做了.
也可以在这里下载这两个包:
amrwb_float下载,
amr_float下载.
PS: 其实上面很多lib库可以不需要手动编译的.在安装开源的vlc播放器时有很多自己都可以通过yum自动安装好.如果嫌麻烦可以先用yum安装好vlc,例如这样:
引用
sudo rpm -ivh
http://rpm.livna.org/livna...sudo yum install vlc
/* sudo yum install python-vlc mozilla-vlc (optionnal) */
于是,便可以看到:
引用
Installing:
vlc i386 0.8.6c-4.lvn6 livna 6.5 M
Installing for dependencies:
a52dec i386 0.7.4-10.lvn6 livna 49 k
aalib i386 1.4.0-0.11.rc5.fc6 extras 74 k
dirac-libs i386 0.7.0-1.fc6 extras 386 k
faac i386 1.25-2.lvn6 livna 82 k
faad2 i386 2.0-19.20050131.lvn6 livna 209 k
ffmpeg-libs i386 0.4.9-0.37.20070503.lvn6 livna 1.6 M
freeglut i386 2.4.0-11.fc6 extras 142 k
gsm i386 1.0.12-3.fc6 extras 27 k
imlib2 i386 1.3.0-3.fc6 extras 576 k
jack-audio-connection-kit i386 0.103.0-1.fc6 extras 138 k
lame-libs i386 3.97-4.lvn6 livna 331 k
libcaca i386 0.99-0.1.beta11.fc6 extras 160 k
libcddb i386 1.3.0-1.fc6 extras 71 k
libcdio i386 0.78.2-2.fc6 extras 268 k
libdca i386 0.0.2-3.lvn6 livna 103 k
libdvbpsi i386 0.1.5-2.lvn6 livna 39 k
libdvdnav i386 0.1.10-3.20070503.lvn6 livna 123 k
libdvdread i386 0.9.7-2.fc6 extras 66 k
libebml i386 0.7.7-2.fc6 extras 72 k
libfreebob i386 1.0.0-3.fc6 extras 155 k
libid3tag i386 0.15.1b-3.fc6 extras 44 k
libmatroska i386 0.8.0-4.fc6 extras 199 k
libmodplug i386 1:0.8.4-1.fc6 extras 167 k
libmp4v2 i386 1.5.0.1-3.fc6 extras 279 k
libmpcdec i386 1.2.2-4.fc6 extras 30 k
libshout i386 2.2.2-1.fc6 extras 43 k
libsndfile i386 1.0.17-2.fc6 extras 227 k
libtar i386 1.2.11-8.fc6 extras 29 k
libupnp i386 1.6.0-1.fc6 extras 101 k
lirc i386 0.8.1-1.fc6 extras 240 k
mpeg2dec i386 0.4.1-2.lvn6 livna 101 k
svgalib i386 1.9.25-3.fc6 extras 465 k
twolame i386 0.3.10-1.lvn6 livna 79 k
vcdimager i386 0.7.23-3.lvn6 livna 657 k
x264 i386 0-0.8.20061028.lvn6 livna 241 k
xosd i386 2.2.14-9.fc6 extras 47 k
xvidcore i386 1.1.3-1.lvn6 livna 242 k
这些codec都安装完毕之后便可以编译ffmpeg了,编译参数如下:
./configure --prefix=/usr/local --enable-gpl --enable-shared --enable-mp3lame --enable-amr_nb --enable-amr_wb --enable-amr_if2 --enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin --enable-faadbin --enable-dts --enable-pp --enable-faad --enable-faac --enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
make
(sudo make install)
然后就可以尝试用ffmpeg做视频转换截图了.
当然,上面那些codec的编译是相当乏味的.你也可以根本不理会这些.因为最新版本的ffmpeg已经比以前支持更多的格式了.因此也可以只安装lame,xvid,x264就可以了.下面是两种配置下支持的格式diff -w的结果:
引用
2c2
< configuration: --prefix=/usr --enable-gpl --enable-shared --enable-mp3lame --enable-amr_nb --enable-amr_wb --enable-amr_if2 --enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin --enable-faadbin --enable-dts --enable-pp --enable-faad --enable-faac --enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
---
> configuration: --prefix=/usr/local --enable-mp3lame
6c6
< built on Jan 30 2007 17:55:22, gcc: 4.1.1 20061011 (Red Hat 4.1.1-30)
---
> built on Jan 30 2007 17:46:19, gcc: 4.1.1 20061011 (Red Hat 4.1.1-30)
40c40
< DE gxf GXF format
---
> D gxf GXF format
72c72
< DE ogg Ogg Vorbis
---
> D ogg Ogg
111d110
< DEA aac
113c112
< DEA ac3
---
> EA ac3
132,133d130
< DEA amr_nb
< DEA amr_wb
147d143
< D A dts
164c160
< DEV DT h264
---
> D V DT h264
190d185
< D A mpeg4aac
275d269
< EV xvid
3)mencoder篇
首先获取mplayer软件包极其mplayer官网上自带的codecs.如果喜欢mplayer,也可以下载gui和font.关于mplayer-1.0rc1在71.21的/home/zhengyu/tools中能找到.如果需要网上下载,可以去官网:
http://www.mplayerhq.hu/de...下载rc1地址如下:
http://www1.mplayerhq.hu/M...最新的svn版本:
http://www1.mplayerhq.hu/M...官网同时也给出了一些codec,其中就有rm格式的codec:
http://www1.mplayerhq.hu/M... 下载完成之后,将tar vxjf essential-20061022.tar.bz2;sudo mkdir -p /usr/lib/codecs;sudo cp -rf essential-20061022/* /usr/lib/codecs;然后解包mplayer,按如下方式编译:
./configure --prefix=/usr/local --enable-gui --enable-largefiles --enable-gif --enable-png --enable-jpeg --language=zh_CN --with-codecsdir=/usr/lib/codecs/
make
(sudo make install)
然后就可以使用mencoder,当然也有一个没有gui的mplayer可以播放各种视频了.不过我们需要的是mencoder.至此,ffmpeg+mencoder搭建完成.
2.常见操作说明
对于ffmpeg,可以将除swf,rmvb,wmav9以外的视频/音频格式转换成flv/mp3,同时可以截取这些视频文件中的某个时间的该帧图片.这些实际上就是一个视频播客显示的部分.对于mencoder,支持各种常见格式的视频/音频转换成flv/mp3.或者转换成avi.
1)ffmpeg篇:
ffmpeg的命令行参数因为太多,这里不列出,可以用ffpmeg -h可以查看到.列出非高级参数如下:
引用
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