Linux编译安装ffmpeg redhat /cenos

一、安装yasm

# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# tar -zxvf yasm-1.3.0.tar.gz
# cd yasm-1.3.0
# ./configure
# make && make install

二、首先是安装各种解码器

1、lame

wget https://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -zxvf lame-3.99.5.tar.gz
cd lame-3.99.5 
./configure --enable-shared
make 
make install

2、libogg

wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar -zxvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --enable-shared
make 
make install

3、a52

wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
tar -zxvf a52dec-0.7.4.tar.gz
cd a52dec-0.7.4
./configure --enable-shared
make 
make install

4、libvorbis

#libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
tar -zxvf libvorbis-1.3.5.tar.gz
cd  libvorbis-1.3.5
./configure --enable-shared
make 
make install

5、xvidcore

wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar -zxvf xvidcore-1.3.2.tar.gz 
cd xvidcore/build/generic
./configure --enable-shared
make 
make install

6、x264

last_x264.tar.bz2包
因为没有找到好的资源,给一个ftp资源,下载最新版本之后上传到linux上
ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
tar -jxvf last_x264.tar.bz2
cd x264-snapshot-20170330-2245
./configure --enable-shared
make 
make install

7、libdts

wget http://down1.chinaunix.net/distfiles/ffmpeg-0.5.tar.bz2
tar -jxvf libdca-0.0.5.tar.bz2
cd libdca-0.0.5
./configure --enable-shared
make 
make install

8、faad2

wget https://jaist.dl.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
tar -zxvf faad2-2.7.tar.gz
cd faad2-2.7
./configure --enable-shared
make 
make install

9、faac

wget https://jaist.dl.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
tar -zxvf faac-1.28.tar.gz
cd faac-1.28
./configure --enable-shared
make 
make install

编译FAAC-1.28时遇到错误
[mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’]
找到mpeg4ip.h并修改修改
解决方法:
从123行开始修改此文件mpeg4ip.h,到129行结束。
修改前:
#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

修改后:
#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

10、amr-nb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-10.0.0.0.tar.bz2
tar -jxvf amrnb-10.0.0.0.tar.bz2
cd amrnb-11.0.0.0
./configure --enable-shared
make 
make install

111、amr-wb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2
tar -jxvf amrwb-11.0.0.0.tar.bz2
cd amrwb-11.0.0.0
./configure --enable-shared
make 
make install

三、安装ffmpeg

wget http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
tar -jxvf http://ffmpeg.org/releases/ffmpeg-3.2.4.tar.bz2
cd ffmpeg-3.2.4
#其中–enable-shared表示生成动态链接库,可以供以后编程使用,同时生成的可执行程序也依赖这些动态库。如果不加上–enable-shared选项则使用静态链接的方式编译,此时不会生成动态库,同时生成的ffmpeg等的可执行文件也比较大,但他们不需要动态库就可以直接运行
./configure --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads  --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libxvid --enable-postproc --enable-ffplay
#可根据提示自行优化
#安装完成后
vi /etc/ld.so.conf/
把/usr/local/ffmpeg/lib填写到该文件中(我这里安装的所有解码器都注入到/usr/local/lib中了,故此,我这里写的是/usr/local/lib)
再执行ldconfig,使修改生效

vi /etc/profile
加入以下内容:

FFMPEG=/usr/local/ffmpeg
PATH加入:$FFMPEG/bin
#使修改立即生效
source /etc/profile

#测试安装是否成功
cd /usr/local/ffmpeg/bin
#执行
./ffmpeg
#出现如下内容说明安装成功
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
  configuration: --enable-shared --prefix=/usr/local/ffmpeg
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.100 / 57. 64.100
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

四、使用ffmpeg

//转码
/usr/ffmpeg-3.1/ffmpeg-3.1/bin/./ffmpeg -i /usr/video-test/1.mp4  /usr/video-test/2.flv  
/usr/local/ffmpeg/bin/./ffmpeg -i /usr/video-test/tt.mp4  -vcodec libx264 -b:v 500000 -r 25 -acodec libmp3lame -b:a 64000 -ar 22050  /usr/video-test/tt.flv

//截图
/usr/ffmpeg-3.1/ffmpeg-3.1/bin/./ffmpeg -i /usr/video-test/1.mp4 -ss 5 -s 880x496 -f image2 -vframes 1  /usr/video-test/2.jpg


你可能感兴趣的:(linux)