http://www.nginxs.com/linux/57.html
最近关注了一下 ffmpeg 发现他又增加了不少模块,这下估计所有的视频格式都支持了吧~
所需要一的一些开源包:
amrnb-7.0.0.2.tar.bz2 libtheora-1.1.1.tar.bz2 amrwb-7.0.0.3.tar.bz2 opencore-amr-0.1.2.tar.gz dirac-1.0.2.tar.gz openjpeg_v1_3.tar.gz faac-1.28.tar.bz2 speex-1.2rc1.tar.gz faad2-2.7.tar.bz2 x264-snapshot-20100314-2245.tar.bz2 ffmpeg-0.5.1.tar.bz2 xvidcore-1.2.2.tar.bz2 libdca-0.0.5.tar.bz2 yasm-0.8.0.tar.gz
先看下
./configure --help --enable-avisynth enable reading of AVISynth script files [no] --enable-bzlib enable bzlib [autodetect] --enable-libamr-nb enable libamr-nb floating point audio codec [no] --enable-libamr-wb enable libamr-wb floating point audio codec [no] --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no] --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no] --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 and libraw1394 [no] --enable-libdirac enable Dirac support via libdirac [no] --enable-libfaac enable FAAC support via libfaac [no] --enable-libfaad enable FAAD support via libfaad [no] --enable-libfaadbin open libfaad.so.0 at runtime [no] --enable-libgsm enable GSM support via libgsm [no] --enable-libmp3lame enable MP3 encoding via libmp3lame [no] --enable-libnut enable NUT (de)muxing via libnut, native (de)muxer exists [no] --enable-libopenjpeg enable JPEG 2000 decoding via OpenJPEG [no] --enable-libschroedinger enable Dirac support via libschroedinger [no] --enable-libspeex enable Speex decoding via libspeex [no] --enable-libtheora enable Theora encoding via libtheora [no] --enable-libvorbis enable Vorbis encoding via libvorbis, native implementation exists [no] --enable-libx264 enable H.264 encoding via x264 [no] --enable-libxvid enable Xvid encoding via xvidcore, native MPEG-4/Xvid encoder exists [no] --enable-mlib enable Sun medialib [no] --enable-zlib enable zlib [autodetect]
首先用懒人方法 安装开发工具包,和一些库文件
shell $> apt-get install libgsm1-dev liblame-dev libdc1394-13-dev zlib1g-dev libvorbis-dev libschroedinger-dev pkg-config
安装 yasm 汇编器
shell $> tar zxvf yasm-0.8.0.tar.gz
shell $> cd yasm-0.8.0
shell $> ./configure
shell $> make
shell $> make install
让ffmpeg 支持 3GP
shell $> tar jxvf amrnb-7.0.0.2.tar.bz2
shell $> cd amrnb-7.0.0.2
shell $> ./configure
shell $> make
shell $> make install
shell $> tar jxvf amrwb-7.0.0.3
shell $> ./configure
shell $> make
shell $> make install
安装ffmpeg 支持 mpeg 库 aac 编码器
shell $> tar jxvf faac-1.28.tar.bz2
shell $> cd faac
shell $> ./configure --prefix=/usr --with-mp4v2
shell $> make
shell $>make install
shell $>tar jxvf faad2-2.7.tar.bz2
shell $> cd faad2
shell $> ./configure --prefix=/usr --with-mpeg4ip
shell $> make
shell $> make install
安装ffmpeg 支持开源的 3GP 库
shell $> tar zxvf opencore-amr-0.1.2.tar.gz
shell $> cd opencore-amr-0.1.2
shell $> ./configure
shell $> make
shell $> make install
安装 theora视频压缩模块
shell $> tar jxvf libtheora-1.1.1.tar.bz2 shell $> cd libtheora-1.1.1 shell $> ./configure shell $> make shell $> make install
安装 ffmpeg 支持 X264 编码器
shell $> tar jxvf x264-snapshot-20100314-2245.tar.bz2
shell $> cd x264-snapshot-20100314-2245
shell $> ./configure --enable-shared
shell $> make
shell $>make install
安装 ffmpeg 支持 xvid 编码器
shell $> tar jxvf xvidcore-1.2.2.tar.bz2
shell $> cd xvidcore/build/generic/
shell $> ./configure
shell $> make
shell $> make install
编译安装 ffmpeg
shell $> tar jxvf ffmpeg-0.5.1.tar.bz2
shell $> cd ffmpeg
shell $> ./configure --enable-shared --enable-gpl --enable-version3 --enable-nonfree --disable-ffplay --disable-ffserver --disable-ipv6 --enable-small --enable-bzlib --enable-libamr-nb --enable-libamr-wb --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --disable-debug --target-os=linux
shell $> make
好了现在开始编译,如果你出现这个问题:
./libavutil/common.h:46:1: warning: this is the location of the previous definition libavcodec/libdiracenc.c: In function ‘libdirac_encode_frame’: libavcodec/libdiracenc.c:288: error: ‘ENC_STATE_EOS’ undeclared (first use in this function) libavcodec/libdiracenc.c:288: error: (Each undeclared identifier is reported only once libavcodec/libdiracenc.c:288: error: for each function it appears in.) libavcodec/libdiracenc.c:315: error: ‘dirac_encoder_t’ has no member named ‘enc_pparams’ libavcodec/libdiracenc.c:324: error: ‘dirac_encoder_t’ has no member named ‘enc_pparams’ libavcodec/libdiracenc.c:326: error: ‘dirac_encoder_t’ has no member named ‘enc_pparams’ libavcodec/libdiracenc.c:326: error: ‘INTRA_PICTURE’ undeclared (first use in this function) libavcodec/libdiracenc.c:327: error: ‘dirac_encoder_t’ has no member named ‘enc_pparams’ libavcodec/libdiracenc.c:327: error: ‘REFERENCE_PICTURE’ undeclared (first use in this function) make: *** [libavcodec/libdiracenc.o] Error 1
说明你的 dirac 版本太低,安装新版本的
shell $> tar zxvf dirac-1.0.2.tar.gz
shell $> ./configure
shell $> make
shell $> make install
如果出现下面的提示
peg-0.5.1"/libavformat -Wl,-rpath-link,"/root/ffmpeg/ffmpeg-0.5.1"/libavcodec -Wl,-rpath-link,"/root/ffmpeg/ffmpeg-0.5.1"/libavutil -Wl,-Bsymbolic -o ffmpeg_g ffmpeg.o cmdutils.o -lavdevice -lavformat -lavcodec -lavutil -lz -lm -lamrnb -lm -lamrwb -lm -ldirac_decoder -ldirac_encoder -lfaac -lfaad -lgsm -lmp3lame -lm -lnut -lopencore-amrnb -lm -lopencore-amrwb -lm -lopenjpeg -lschroedinger-1.0 -lpthread -loil-0.3 -lm -lrt -lspeex -ltheora -logg -lvorbisenc -lvorbis -logg -lx264 -lm -lxvidcore -ldc1394_control -lraw1394 -ldl /root/ffmpeg/ffmpeg-0.5.1/libavcodec/libavcodec.so: undefined reference to `opj_decode_with_info' /root/ffmpeg/ffmpeg-0.5.1/libavcodec/libavcodec.so: undefined reference to `speex_header_free' collect2: ld returned 1 exit status make: *** [ffmpeg_g] Error 1
或者你会出现:
libavcodec/libavcodec.so: undefined reference to `speex_header_free'
说明你的 speex 版本与 ffmpeg 版本不符合,下在符合版本
删除以前的懒人包安装版本:
shell $> apt-get purge libspeex-dev
shell $> apt-get autoremove
安装新版本:
shell $> tar zxvf speex-1.2rc1.tar.gz
shell $> cd speex-1.2rc1
shell $> ./configure
shell $> make
shell $> make install
或许你会出现这个错误:
libavcodec.so: undefined reference to `opj_decode_with_info'
这行错误说明你的 openjpeg 版本与ffmpeg 版本有冲突,请下载最新版本
shell $> tar zxvf openjpeg_v1_3.tar.gz
shell $> cd OpenJPEG_v1_3
shell $> make
shell $> make install
好了现在可以编译了
shell $> cd ffmpeg
shell $> make
shell $> make install
现在转换一个 mp4 转为 flv文件
shell $> ffmpeg -i 2.mp4 -y -ab 32 -ar 22050 -qscale 10 -r 15 b.flv
如果提示以下信息:
libmp3lame : output buffer too small (ubuntu)
lame :: output buffer too small
错误解决办法修改
解决办法:
我是参考: http://blog.csdn.net/warsour/archive/2009/08/06/4418664.aspx
1.找到/ffmpeg/libavcodec/libmp3lame.c这个文件
2.结构体增加一个成员
typedef struct Mp3AudioContext {
lame_global_flags *gfp;
int stereo;
uint8_t buffer[BUFFER_SIZE];
int buffer_index;
int flushed; } Mp3AudioContext;
3.把函数MP3lame_encode_frame里面这几行修改为这样
if(data){ if (s->stereo) { lame_result = lame_encode_buffer_interleaved( s->gfp, data, avctx->frame_size, s->buffer + s->buffer_index, BUFFER_SIZE - s->buffer_index ); } else { lame_result = lame_encode_buffer( s->gfp, data, data, avctx->frame_size, s->buffer + s->buffer_index, BUFFER_SIZE - s->buffer_index ); } s->flushed = 0; }else{ if (s->flushed) lame_result = 0; else { s->flushed = 1; lame_result= lame_encode_flush( s->gfp, s->buffer + s->buffer_index, BUFFER_SIZE - s->buffer_index ); } }
PS:大家注意SVN获取的新版本
--enable-libamr-nb
--enable-libamr-wb
已经被
-enable-libopencore-amrnb
--enable-libopencore-amrwb
替换了,但是不知道为什么他的 整合包里面还有。所以我把两个模块都编译上了。
当然你只可以只编译后两个选项~