@(gr_self)[ffmpeg | openCV]c++
#@author: gr #@date: 2015-09-02 #@email: forgerui@gmail.com
yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
Yasm is an assembler used by x264 and FFmpeg.git
mkdir ~/ffmpeg_sources cd ~/ffmpeg_sources curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz tar xzvf yasm-1.2.0.tar.gz cd yasm-1.2.0 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install make distclean export "PATH=$PATH:$HOME/bin"
H.264 video encoder.github
cd ~/ffmpeg_sources git clone --depth 1 git://git.videolan.org/x264 cd x264 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static make make install make distclean
cd ~/ffmpeg_sources wget https://bitbucket.org/multicoreware/x265/downloads/x265_1.7.tar.gz (ffmpeg3.2.5, 须要新的x265, 能够使用2.4版本,wget https://bitbucket.org/multicoreware/x265/downloads/x265_2.4.tar.gz) tar xzvf x265_1.7.tar.gz cd x265_1.7/build/linux ./make-Makefiles.bash make -j20 make install
若是出现找不到ccmake命令,能够直接修改make-Makefiles.bash将ccmake改成cmake,或者安装sudo apt install cmake-curses-gui。web
AAC audio encoder.bash
cd ~/ffmpeg_sources git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac cd fdk-aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
Opus audio decoder and encoder.curl
# wget http://nchc.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz # tar xzvf lame-3.99.5.tar.gz # cd lame-3.99.5 # ./configure --prefix="$HOME/ffmpeg_build" # make # make install
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz tar xzvf opus-1.1.tar.gz cd opus-1.1 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
Ogg bitstream library. Required by libtheora and libvorbis.ide
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz tar xzvf libogg-1.3.1.tar.gz cd libogg-1.3.1 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
Vorbis audio encoder. Requires libogg.svn
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz tar xzvf libvorbis-1.3.4.tar.gz cd libvorbis-1.3.4 ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared make make install make distclean
VP8/VP9 video encoder.ui
cd ~/ffmpeg_sources git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git cd libvpx ./configure --prefix="$HOME/ffmpeg_build" --disable-examples make make install make clean
注意:因为国内最近没法访问Google因此libvpx没法git clone ,此时能够去别处下载:http://yunpan.cn/QhNk5tDqQV3MM 访问密码 45f6
cd ~/ffmpeg_sources svn checkout http://svn.xvid.org/trunk --username anonymous cd trunk/xvidcore/build/generic ./configure make && make install cp /usr/local/lib/libxvidcore.so /usr/lib ldconfig
wget http://libav.org/releases/libav-10.7.tar.gz tar xzvf libav-10.7.tar.gz cd libav-10.7 ./configure --enable-shared --extra-cflags=-fPIC make && make install
cd ~/ffmpeg_sources git clone --depth 1 git://source.ffmpeg.org/ffmpeg cd ffmpeg PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" export PKG_CONFIG_PATH ./configure --prefix="$HOME/ffmpeg_build" --enable-shared --extra-cflags=-fPIC --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid make make install make distclean hash -r . ~/.bash_profile
安装结束查看版本
ffpmeg -version
cd opencv mkdir -p build && cd build cmake ../ make all -j24 && make install
问题一:
/usr/lib64/gcc/x86_64-linux/4.2.0/../../../../x86_64-linux/bin/ld: /usr/local/libavcodec.a(z.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
解决方法:
加上fPIC选项,./configure --enable-shared --extra-cflags=-fPIC
。
问题二:
In file included from /home/aman/opencv/opencv/modules/videoio/src/cap_ffmpeg.cpp:45:0: /home/aman/opencv/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’: /home/aman/opencv/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1269:72: error: ‘avcodec_encode_video’ was not declared in this scope out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
This is because libav has changed API and removed some stuff it's still used in OpenCV. Ubuntu 14.10 uses libav API version 11 and OpenCV still uses API version 9. The problem is that CODEC_ID_* was changed to AV_CODEC_ID_*.
解决方法:
以前下载的libav版本太新,opencv不支持。从新下载libav9,编译安装。
问题三:
装了许多视频解码器,仍没法播放视频。
解决方法:
cmake ../
发现v4l没有找到,安装v4l。命令:yum install libv4l-devel
。