基於linux平臺的FFmpeg安裝部署

FFmpeg安裝部署

  1. 系統環境
    [root@ceshiji ~]# iostat
    Linux 2.6.32-573.3.1.el6.x86_64 (ceshiji)   2018年03月04日     _x86_64_    (8 CPU)
    [root@ceshiji ~]# cat /etc/redhat-release
    CentOS release 6.7 (Final)
    [root@ceshiji ~]# getenforce
    Disabled
  2. 安裝所需包或插件
    (1)faac-1.28.tar.gz
    下載地址:http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
    tar -zxvf  faac-1.28.tar.gz
    cd faac-1.28
    ./configure
    make && make install
    將 faac-1.28/common/mp4v2/mpeg4ip.h 第 123行~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

    如不安裝會出現下面的報錯信息:

    make[3]: 正在進入目錄 `/home/tarena/project/jpg to mp4/faac-1.28/common/mp4v2'  
    if g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include   -Wall -g -O2 -MT 3gp.o -MD -MP -MF ".deps/3gp.Tpo" -c -o 3gp.o 3gp.cpp; \  
    then mv -f ".deps/3gp.Tpo" ".deps/3gp.Po"; else rm -f ".deps/3gp.Tpo"; exit 1; fi  
    In file included from mp4common.h:29:0,  
                 from 3gp.cpp:28:  
    mpeg4ip.h:126:58: 錯誤: 對‘char* strcasestr(const char*, const char*)’的新聲明  
    /usr/include/string.h:369:28: 錯誤: 使舊的聲明‘const char* strcasestr(const char*, const char*)’出現歧義  
    make[3]: *** [3gp.o] 錯誤 1  
    make[3]:正在離開目錄 `/home/tarena/project/jpg to mp4/faac-1.28/common/mp4v2'  
    make[2]: *** [all-recursive] 錯誤 1  
    make[2]:正在離開目錄 `/home/tarena/project/jpg to mp4/faac-1.28/common'  
    make[1]: *** [all-recursive] 錯誤 1  
    make[1]:正在離開目錄 `/home/tarena/project/jpg to mp4/faac-1.28'  
    make: *** [all] 錯誤 2<strong>  
    </strong>  

    (2)lame-3.97.tar.gz

    下載地址:http://downloads.sourceforge.net/lame/lame-3.97.tar.gz
    tar -zxvf lame-3.97.tar.gz
    cd lame-3.98.4
    ./configure
    make && make install
    如不安裝會出現下面的報錯信息:
    ERROR: libmp3lame >= 3.98.3 not found

    (3)opencore-amr-0.1.2.tar.gz

    下載地址:http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/0.1.2/opencore-amr-0.1.2.tar.gz
    tar -zxvf opencore-amr-0.1.2.tar.gz
    cd opencore-amr-0.1.2
    ./configure
    make && make install
    如不安裝會出現下面的報錯信息:
    ERROR: libopencore_amrnb not found

    (4)libogg-1.3.3.tar.xz

    下載地址:wget https://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz
    tar -xf libogg-1.3.3.tar.xz
    ./configure --prefix=/usr    \
            --disable-static \
            --docdir=/usr/share/doc/libogg-1.3.3 
    make && make install
    如不安裝會出現下面報錯信息:
    *** Could not run Ogg test program, checking why...
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occured. This usually means Ogg was incorrectly installed
    *** or that you have moved Ogg since it was installed.
    configure: error: must have Ogg installed!

    (5)libvorbis-1.3.5.tar.gz

    下載地址:https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.xz
    tar -xf libvorbis-1.3.5.tar.xz
    cd libvorbis-1.3.5
    ./configure
    make && make install
    如不安裝會出現下面報錯信息:
    ERROR: libvorbis not found

    (6)x264

    下載地址:wget http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20170213-2245-stable.tar.bz2
    tar -jxf x264-snapshot-20170213-2245-stable.tar.bz2
    cd x264-snapshot-20170213-2245-stable/
    ./configure --disable-asm --enable-static --enable-shared
    make && make install
    如不安裝會出現下面報錯信息:
    ERROR: libx264 not found
    ERROR: libx264 must be installed and version must be >= 0.118.
    重新編譯安裝libx264時,一定需要把電腦裏面之前的版本給刪除掉,在/usr 或者/usr/local下,在編譯x264的時候加--enable-static --enable-shared,如果不加參數,只能編譯出x264的執行文件出來,install到/usr/bin目錄下面。
    按如下方法尋找:
    whereis libx264
    cd /usr/local/lib
    rm -rf libx264.*

    (7)xvidcore-1.2.2.tar.gz

    下載地址:http://downloads.xvid.org/downloads/xvidcore-1.2.2.tar.gz
    tar -xf xvidcore-1.2.2.tar.gz
    cd xvidcore/build/generic
    ./configure
    make && make install
    如不安裝會出現下面報錯信息:
    ERROR: libxvid not found
  3. 安裝ffmpeg
    下載地址:https://ffmpeg.org/releases/ffmpeg-3.2.7.tar.gz
    tar -zxf ffmpeg-3.2.7.tar.gz
    cd ffmpeg-3.2.7 
    ./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-libmp3lame --disable-yasm
    make && make install
    如出現下面報錯信息:
    libavcodec/libx264.c: 在函數‘X264_init_static’中:
    libavcodec/libx264.c:892: 錯誤:‘x264_bit_depth’未聲明(在此函數內第一次使用)
    make: *** [libavcodec/libx264.o] 錯誤 1
    解決方法:
    更換libx264版本,重新編譯安裝,把編譯文件清理下,命令:make clean
    如出現如下報錯:
    yasm/nasm not found or too old. 
    解決方法:
    安裝yasm  或者按照提示直接在配置上添加 --disable-yasm
  4. 驗證ffmpeg是否安裝正確
    cd /usr/local/ffmpeg/bin
    ./ffmpeg -version
    報錯信息如下:
    ./ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory
    解決方法:
    pwd
    /data3/ceshiji/ffmpeg/x264-snapshot-20170213-2245-stable
    cp libx264.so.148 /usr/lib/
    修改文件 /etc/ld.so.conf 內容增加 /usr/local/ffmpeg/lib/ 
    echo "/usr/local/ffmpeg/lib/" >>  /etc/ld.so.conf  
    使之生效:
    #ldconfig
    ./ffmpeg -version
    ffmpeg version 3.2.7 Copyright (c) 2000-2017 the FFmpeg developers
    built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
    configuration: --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-libmp3lame --disable-yasm
    libavutil      55. 34.101 / 55. 34.101
    libavcodec     57. 64.101 / 57. 64.101
    libavformat    57. 56.101 / 57. 56.101
    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
    libpostproc    54.  1.100 / 54.  1.100
  5. ffmpeg建立軟連接
    兩種方法均可:
    (1)ln -s /usr/local/ffmpeg/bin/ffmpeg  /usr/local/bin/ffmpeg
    (2)export PATH=/usr/local/ffmpeg/bin/:$PATH  
    永久性的:  
    echo "export PATH=/usr/local/ffmpeg/bin/:$PATH" >> /etc/profile 
    立即生效執行:  
    source /etc/profile  
  6. 基本命令
    (1)ffmpeg -help
    (2)ffmpeg -version
    (3)ffmpeg -codecs
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章