zoukankan      html  css  js  c++  java
  • ### OpenCV安装(Linux)

    ### OpenCV安装(Linux)

    @(gr_self)[ffmpeg | openCV]

    #@author:       gr
    #@date:         2015-09-02
    #@email:        forgerui@gmail.com   
    

    1.安装基础依赖包

    yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
    

    2. 安装其它依赖

    Yasm

    Yasm is an assembler used by x264 and FFmpeg.

    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"  
    

    libx264

    H.264 video encoder.

    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  
    

    libx265

    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。

    libfdk_aac

    AAC audio encoder.

    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  
    

    libmp3lame

    Opus audio decoder and encoder.

    # 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
    

    opus

    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  
    

    libogg

    Ogg bitstream library. Required by libtheora and libvorbis.

    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  
    

    libvorbis

    Vorbis audio encoder. Requires libogg.

    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  
    

    libvpx

    VP8/VP9 video encoder.

    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

    xvid

    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
    

    libav

     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
    

    FFmpeg

    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
    

    3. OpenCV

    cd opencv
    mkdir -p build && cd build
    cmake ../
    make all -j24 && make install
    
    1. 如果需要装一个intel加速包ippcv,这个东西下载很慢,并且有时会断掉,可以手动下载之后再安装。
    2. 如果是opencv3以上,要使用SIFT等特征,需要一个第三方包,可以到github上(https://github.com/opencv/opencv_contrib)找对应的release版本下来,再通过-DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules去配置编译。
    3. 如果要把opencv编译成静态库,加上-D BUILD_SHARED_LIBS=NO

    4. Problems

    问题一:

    /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

  • 相关阅读:
    PHP mysqli_error() 函数
    PHP mysqli_error_list() 函数
    PHP mysqli_errno() 函数
    PHP mysqli_dump_debug_info() 函数
    PHP mysqli_data_seek() 函数
    PHP mysqli_debug() 函数
    PHP mysqli_connect() 函数
    PHP mysqli_connect_errno() 函数
    PHP mysqli_connect_error() 函数
    PHP mysqli_commit() 函数
  • 原文地址:https://www.cnblogs.com/gr-nick/p/4924186.html
Copyright © 2011-2022 走看看