Cent OS安装使用ffmpeg
centos作为主流后台linux 系统,ffmpeg作为视频流解析的主力,尤其是ffmpeg配合opencv使用,则是视觉操作的基础
版本:
ffmpeg3.1 + opencv 2.4.13.6
1.ffmpeg安装准备
1)安装必要的扩展
yum install automake autoconf make gcc gcc-c++ libtool zlib zlib-devel curl curl-devel alsa-lib alsa-lib-devel gettext gettext-devel expat expat-devel nasm pkgconfig
2)安装yasm - 支持编译x264
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -zxvf yasm-1.3..tar.gz
cd yasm-1.3.
./configure
make -j8
make install
3)安装gnutls、lame
yum install gnutls gnutls-devel
yum install lame lame-devel
4)安装 x264库
卸载系统自带的旧版x264
yum remove x264 x264-devel
安装 x264
wget -c ftp://ftp.videolan.org/pub/x264/snapshots/x264-snapshot-20120718-2245-stable.tar.bz2
# 未安装 bzip2 则执行安装命令
yum install bzip2
tar jxvf x264-snapshot---stable.tar.bz2
cd x264-snapshot---stable
./configure --enable-shared --enable-static
make -j8
make install
2.安装ffmpeg
wget http://www.ffmpeg.org/releases/ffmpeg-3.1.tar.gz
tar -zxvf ffmpeg-3.1.tar.gz
cd ffmpeg-3.1
./configure --prefix=/usr/local/ --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-zlib --enable-bzlib --enable-libmp3lame --enable-libx264 --enable-pic
make -j8
make install
3.检查ffmpeg 是否安装成功
更新资源
updatedb # yum install mlocate
检查ffmpeg版本
ffmpeg -v
如果提示找不到 libavdevice ... ,在 /etc/ld.so.conf 中配置 /usr/local/lib
vi /etc/ld.so.conf
// 新增 : /usr/local/lib
ldconfig
此时检查ffmpeg版本则返回:
ffmpeg version 3.1 Copyright (c) - the FFmpeg developers
built with gcc 4.8. (GCC) (Red Hat 4.8.-)
configuration: --prefix=/usr/local/ --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-zlib --enable-bzlib --enable-libmp3lame --enable-libx264 --enable-pic
libavutil . 27.100 / . 27.100
libavcodec . 48.101 / . 48.101
libavformat . 40.101 / . 40.101
libavdevice . 0.101 / . 0.101
libavfilter . 46.102 / . 46.102
libswscale . 1.100 / . 1.100
libswresample . 1.100 / . 1.100
libpostproc . 0.100 / . 0.100
4.opencv准备
Java的安装 - 略
ant的安装
yum install ant
5.opencv 安装
wget https://github.com/opencv/opencv/archive/2.4.13.6.zip
unzip opencv-2.4.13.6.zip # yum install zip unzip
cd opencv-2.4.13.6
mkdir build && cd build
检查opencv安装依赖
cmake ..
如果没有ffmpeg :
这里,参见 https://*.com/questions/5492919/cmake-cant-find-ffmpeg-in-custom-install-path ,需配置 PKG_CONFIG_PATH 变量,而centos默认没有locate,故有以下处理:
yum install mlocate // centos 下安装locate
locate pkgconfig
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
再去执行cmake即发现ffmpeg已就绪。
执行编译、安装
make -j8
make install
6.opencv检查
检查很简单,build/lib 目录下是否包含:
libopencv_java2413.so
需要用到 opencv - jar 的, build/bin 目录下查看是否包含:
opencv-.jar
实际使用中,将 jar包导入项目,或者maven 本地仓库即可。