centos7源码安装ffmpeg
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7源码安装ffmpeg相关的知识,希望对你有一定的参考价值。
参考技术A如果正常只编译安装ffmpeg 会出缺少lib264 的情况
其他软件版本:
ffmpeg-3.0
cmake-3.5.0
last_x264
x265_1.9
yasm-1.3.0
相关地址:
ffmpeg是一个很强大的音视频处理工具, 官网介绍ffmpeg是:一个完整的、跨平台的解决方案,可以记录、转换和传输音频和视频。ffmpeg既可以播放视频,也提供命令行工具来处理视频,另外还有强大的视频处理库用于开发,
如果大于3.5就不用安装cmake
执行时会弹出界面选项, 按\'c\'再按\'g\'键保存退出
动静态库在/usr/local/lib
x265.pc库的配置文件在/usr/local/lib/pkgconfig
(这只是临时的,如果想永久生效写在/etc/profile内)
ffmpeg源码安装
官网下载地址
http://www.ffmpeg.org/download.html
https://sourceforge.net/projects/opencore-amr/
参考资料:官网及以下网站
http://blog.csdn.net/5iasp/article/details/50913855
http://blog.csdn.net/zhangwu1241/article/details/52354604
http://www.cnblogs.com/wanghetao/p/3386311.html
http://www.cnblogs.com/bugutian/p/5111067.html
http://www.linuxidc.com/Linux/2013-01/78495.htm
——————————————华丽的分割线—————————————————————————
部署环境:CentOS 6.8
百度安装包分享:http://pan.baidu.com/s/1pLDlNSZ 密码:egsw
安装记录
yum install -y autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
mkdir /software
tar -zxvf ffmpeg_sources.tar.gz -C /software
tar -zxvf nasm-2.13.02rc2.tar.gz -C /software
cd /software/nasm-2.13.02rc2
./configure --prefix="/software/nasm"
make
make install
修改环境变量vim /etc/profile
加入export PATH=/software/nasm/bin:/software/ffmpeg_build/bin:$PATH
然后source /etc/profile
cd /software/ffmpeg_sources/yasm
autoreconf -fiv
./configure --prefix="/software/ffmpeg_build" --bindir="/software/ffmpeg_build/bin"
make && make install
cd /software/ffmpeg_sources/x264
#PKG_CONFIG_PATH="/software/ffmpeg_build/lib/pkgconfig" ./configure --prefix=/software/ffmpeg_build --bindir=/software/ffmpeg_build/bin --enable-static
PKG_CONFIG_PATH="/software/ffmpeg_build/lib/pkgconfig" ./configure --prefix=/software/ffmpeg_build --bindir=/software/ffmpeg_build/bin --enable-static --disable-asm
make && make install
cd /software/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/software/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make && make install
cd /software/ffmpeg_sources/fdk-aac
autoreconf -fiv
./configure --prefix="/software/ffmpeg_build" --disable-shared
make && make install
cd /software/ffmpeg_sources/lame-3.99.5
./configure --prefix="/software/ffmpeg_build" --bindir="/software/ffmpeg_build/bin" --disable-shared --enable-nasm
make && make install
cd /software/ffmpeg_sources/opus
autoreconf -fiv
./configure --prefix="/software/ffmpeg_build" --disable-shared
make && make install
cd /software/ffmpeg_sources/libogg-1.3.2
./configure --prefix="/software/ffmpeg_build" --disable-shared
make && make install
make distclean
cd /software/ffmpeg_sources/libvorbis-1.3.4
LDFLAGS="-L/software/ffmeg_build/lib" CPPFLAGS="-I/software/ffmpeg_build/include" ./configure --prefix=/software/ffmpeg_build --with-ogg=/software/ffmpeg_build --disable-shared
此时如果有如下报错
checking for OGG... no
checking for Ogg... no
*** Could not run Ogg test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding Ogg or finding the wrong
*** version of Ogg. If it is not finding Ogg, you\'ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
configure: error: must have Ogg installed!
我们上面已经安装过libogg了,此时这个提示没有安装,可能是路径问题
解决方案,创建库文件
[root@restapi_1 libvorbis-1.3.4]# cat /etc/ld.so.conf.d/local-libraries.conf
/software/ffmpeg_build/lib
[root@restapi_1 libvorbis-1.3.4]# ldconfig -v
此时解决了库依赖问题,在次跑编译安装,没有报错了
LDFLAGS="-L/software/ffmeg_build/lib" CPPFLAGS="-I/software/ffmpeg_build/include" ./configure --prefix=/software/ffmpeg_build --with-ogg=/software/ffmpeg_build
make && make install
cd /software/ffmpeg_sources/libvpx
./configure --prefix="/software/ffmpeg_build" --enable-pic --enable-shared
make && make install
cd /software/ffmpeg_sources/ffmpeg3
PKG_CONFIG_PATH="/software/ffmpeg_build/lib/pkgconfig" ./configure --prefix="/software/ffmpeg_build" --extra-cflags="-I/software/ffmpeg_build/include" --extra-ldflags="-L/software/ffmpeg_build/lib" --bindir="/software/ffmpeg_build/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-pic --enable-shared --enable-gray --enable-avresample --enable-openssl
此时如果有编译报错,如下
/usr/bin/ld: /software/ffmpeg_build/lib/libx264.a(common.o): relocation R_X86_64_32 against `.rodata.str1.1\' can not be used when making a shared object; recompile with -fPIC
/software/ffmpeg_build/lib/libx264.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libavcodec/libavcodec.so.57] Error 1
解决方法是:
config.mak L75加入 -fPIC,然后重新编译
HOSTCFLAGS=-O3 -g -std=c99 -Wall -fPIC
我比较着急,直接去掉最后几个参数(询问开发,说不用这些模块),开始搞
PKG_CONFIG_PATH="/software/ffmpeg_build/lib/pkgconfig" ./configure --prefix="/software/ffmpeg_build" --extra-cflags="-I/software/ffmpeg_build/include" --extra-ldflags="-L/software/ffmpeg_build/lib" --bindir="/software/ffmpeg_build/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
然后不报错了,make && make install
安装完成后启动报错,发现是没有文件库
ffmpeg: error while loading shared libraries: libvpx.so.4: cannot open shared object file: No such file or directory
进入相关库查看
[root@zookeeper_rest-api-node1 ffmpeg3]# cd /usr/lib64
ls -l 查看后发现没有,于是从安装目录/software/ffmpeg_build/lib/libvpx.so.4找到这个文件,并做好软链接
[root@zookeeper_rest-api-node2 lib64]# ln -s /software/ffmpeg_build/lib/libvpx.so.4 /usr/lib64/libvpx.so.4
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ffmpeg -v
ffmpeg: error while loading shared libraries: libvpx.so.4: cannot open shared object file: No such file or directory
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ln -s /software/ffmpeg_build/lib/libvpx.so.4 /usr/lib64/libvpx.so.4
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ffmpeg -v
ffmpeg: error while loading shared libraries: libvorbisenc.so.2: cannot open shared object file: No such file or directory
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ln -s /software/ffmpeg_build/lib/libvorbisenc.so.2 /usr/lib64/libvorbisenc.so.2
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ffmpeg -v
ffmpeg: error while loading shared libraries: libvorbis.so.0: cannot open shared object file: No such file or directory
[root@iZ2zehjeved0zzfkdndbc5Z ffmpeg3]# ln -s /software/ffmpeg_build/lib/libvorbis.so.0 /usr/lib64/libvorbis.so.0
此时解决了问题,ffmpeg -v后如下图所示,没有报错
以上是关于centos7源码安装ffmpeg的主要内容,如果未能解决你的问题,请参考以下文章