交叉編譯 ffmpeg x264


arm linux 平臺
1、 交叉編譯x264
我用的是:x264-snapshot-20121212-2245-stable.tar.bz

開始是使用這個命令
./configure --enable-pthread --enable-static --disable-shared --host=arm-linux --disable-asm

然後make
make CC=arm-linux-gcc AR=arm-linux-ar LD=arm-linux-gcc RANLIB=arm-linux-ranlib STRIP=arm-linux-strip
 報出錯誤:

x264.c:50:34: error: libavformat/avformat.h: No such file or directory
x264.c:51:30: error: libavutil/pixfmt.h: No such file or directory
x264.c:52:31: error: libavutil/pixdesc.h: No such file or directory
x264.c:57:32: error: libswscale/swscale.h: No such file or directory
x264.c: In function 'print_version_info':
x264.c:236: error: 'LIBSWSCALE_VERSION_MAJOR' undeclared (first use in this function)
x264.c:236: error: (Each undeclared identifier is reported only once
x264.c:236: error: for each function it appears in.)
x264.c:236: error: 'LIBSWSCALE_VERSION_MINOR' undeclared (first use in this function)
x264.c:236: error: 'LIBSWSCALE_VERSION_MICRO' undeclared (first use in this function)
x264.c:239: error: 'LIBAVFORMAT_VERSION_MAJOR' undeclared (first use in this function)
x264.c:239: error: 'LIBAVFORMAT_VERSION_MINOR' undeclared (first use in this function)
x264.c:239: error: 'LIBAVFORMAT_VERSION_MICRO' undeclared (first use in this function)
x264.c:260: warning: implicit declaration of function 'swscale_license'
x264.c:260: warning: initialization makes pointer from integer without a cast
x264.c: In function 'print_csp_names':
x264.c:351: error: variable 'i' has initializer but incomplete type
x264.c:351: error: 'PIX_FMT_NONE' undeclared (first use in this function)
x264.c:351: error: storage size of 'i' isn't known
x264.c:351: error: 'enum PixelFormat' declared in 'for' loop initial declaration
x264.c:351: error: 'PIX_FMT_NB' undeclared (first use in this function)
x264.c:353: warning: implicit declaration of function 'av_get_pix_fmt_name'
x264.c:353: warning: initialization makes pointer from integer without a cast
x264.c:351: warning: unused variable 'i'
make: *** [x264.o] 錯誤 1


這幾個文件都是在ffmpeg文件夾中,

解決辦法:

先按後面的方法配置一下ffmpeg,原因是libavutil/avconfig.h是生成的,配置過還沒有就編譯一下,沒有那個文件編譯的時候會報出找不到這個文件,

然後修改config.mak文件的第十行,加上 -I/home/liuyan/h.264/for_X86/ffmpeg-1.0 就可以找到了

再次運行make命令後,編譯通過,但鏈接時出錯。編譯libx264.a庫時,顯示的命令爲:

arm-linux-arlibx264.a ....

make文件將鏈接命令和庫名字間沒有空格,導致系統無法識別此命令。我嘗試修改Makefile文件也不行,乾脆手動執行下面的命令:

arm-linux-ar rc libx264.a common/mc.o common/predict.o common/pixel.o common/macroblock.o common/frame.o common/dct.o common/cpu.o common/cabac.o common/common.o common/osdep.o common/rectangle.o common/set.o common/quant.o common/deblock.o common/vlc.o common/mvpred.o common/bitstream.o encoder/analyse.o encoder/me.o encoder/ratecontrol.o encoder/set.o encoder/macroblock.o encoder/cabac.o encoder/cavlc.o encoder/encoder.o encoder/lookahead.o common/threadpool.o

arm-linux-ranlib libx264.a (用於產生x264-config.h文件)

由於我電腦上的交叉編譯器是從以下目錄去查找頭文件和庫的,所以把x264.h和libx264.a拷貝到相應目錄:(我是通過在/opt/EmbedSky/4.3.3下查找pthread.h和libpthread.a來獲取這個目錄的)
cp x264.h x264-config.h /opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/libc/usr/include/
cp libx264.a /opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/libc/armv4t/usr/lib/
 
2、 編譯ffmpeg
我用的是:ffmpeg-1.0.tar.gz
./configure --enable-cross-compile --arch=arm --target-os=linux --enable-static --disable-shared --cc=arm-linux-gcc --enable-libx264 --enable-gpl --disable-network --enable-pthreads --enable-small --disable-parsers --disable-debug

修改config.mak 中:

CC=arm-linux-gcc 

AR=arm-linux-ar 

LD=arm-linux-gcc 

RANLIB=arm-linux-ranlib 

STRIP=arm-linux-strip


make CC=arm-linux-gcc AR=arm-linux-ar LD=arm-linux-gcc RANLIB=arm-linux-ranlib STRIP=arm-linux-strip



下面是轉載別人在PC機上安裝ffmpeg和x264的文檔

地址:http://www.xxlinux.com/linux/article/accidence/internet/20081226/14739.html

ffmpeg是一款多媒體視頻和音頻文件解碼和編碼的工具,用來提供衆多的多媒體(主要指視頻和音頻)文件的播放和轉換支持。x264是一個編解碼H264視頻格式的庫文件,相比較xvid或者其它流行的編解碼器轉換效率和轉換後的畫面質量都更加優異。Avidemux, VLC Player, MEncoder, 和Handbrake中都可利用x264庫文件。

    儘管ffmpeg和x264存在於Ubuntu的軟件倉庫中,但是實際上通過Uuntu軟件倉庫apt-get方式安裝的ffmpeg是不完整的的版本,仍需要我們通過自行編譯才能提供對更多視頻、音頻格式(例如3gp)轉換支持。

    獲取相應的依賴軟件

    1. 首先請確認在軟件源中已經添加了相應的Universe和Multiverse軟件源,目的是我們要通過軟件倉庫來解決x264和ffmpeg的依賴文件。

    2. 接下來如果您之前安裝了x264,libx264-dev和ffmpeg請先把它卸載,打開X終端或控制檯運行下面的命令:

  

 sudo apt-get purge ffmpeg x264 libx264-dev

    下面的步驟我們會安裝依賴軟件及其它編譯所需要的軟件

    對於Ubuntu的版本:Intrepid Ibex 8.10

    命令:

   

 sudo apt-get update
sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaad-dev libfaac-dev libmp3lame-dev libtheora-dev

    對於Ubuntu的版本:Hardy Heron 8.04:

    命令:

 sudo apt-get update
sudo apt-get install build-essential subversion git-core checkinstall texi2html libfaad-dev libfaac-dev liblame-dev libtheora-dev

    Intrepid Ibex 8.10 和 Hardy Heron 8.04都用到的依賴包:

    libsdl1.2-dev: 運行 ffplay需要

    libfaad-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore4-dev libschroedinger-dev libspeex-dev libgsm1-dev: ffmpeg開發應用到的一些文件,其中一些已經在ffmpeg的源碼中包含,如果系統中包含且版本太低,可能會導致安裝失敗(不常見)。

    3. 使用Ubuntu版本爲Hardy Heron 8.04請注意下。請最好先安裝yasm(一個彙編編譯軟器,和gcc類似)。它可以優化x264的代碼。當然即便沒有yasm,也可以在編譯過程中加入–disable-asm參數來編譯,不過這樣得到的x264運行效率會稍差一些。

    好像在Ubuntu Hardy Heron 8.04軟件倉庫中的Yasm的版本是0.5.0,而最新版本的x264的彙編編譯部分需要yasm的版本至少爲0.6.1,否則在執行編譯命令時會提示:Minimum version is yasm-0.6.1。這時我們可以通過執行:

    命令:

   

 cd ~/
wget http://www.tortall.net/projects/yasm/releases/yasm-0.7.2.tar.gz
tar xzvf yasm-0.7.2.tar.gz
cd yasm-0.7.2
./configure
make
sudo checkinstall

    來自行下載並編譯相應的軟件安裝x264

    4. 獲取最新版本的x264並編譯安裝,我們在這裏通過git命令獲取:

 

 cd ~/
git clone git://git.videolan.org/x264.git

    開始編譯並安裝

   

 cd x264
./configure --enable-shared
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1"
sudo ldconfig

    更多編譯參數請執行./configure –help查看。。。

    安裝ffmpeg

    5. 通過svn命令獲取最新版本的ffmpeg:

 svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg

    開始編譯並安裝:

 

 svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3"

    更多編譯參數請執行./configure –help查看。。。,例如美麗星點用到的參數是(命令中加–prefix=/usr參數目的是規定安裝位置,如非必要,請不要加這個參數,以免造成不必要的麻煩):
    ./configure –prefix=/usr –enable-shared –enable-gpl –enable-postproc –enable-swscale –enable-pthreads –enable-nonfree –enable-libdc1394 –enable-libfaac –enable-libfaad –enable-libfaadbin –enable-libgsm –enable-libmp3lame –enable-libnut –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-avfilter –enable-avfilter-lavf –enable-libamr-nb –enable-libamr-wb
    注意:–enable-libamr-nb –enable-libamr-wb –enable-libfaac這三個參數如果想讓ffmpeg可以轉換3gp,請在編譯過程中加上,其它參數請根據需要添加。

    6. 鎖定x264和ffmpeg這兩個軟件包阻止其升級。這部分也很重要,由於我們自行編譯的軟件包可能會在操作操作系統更新時被替換掉。

    如果您習慣使用的是圖形界面的apt-get命令或者是新利得軟件包管理器,請在管理器的界面執行:
    System(系統) -> Administration (系統管理)-> Synaptic Package Manager(新得利軟件包管理器) -> 在包瀏覽器中選擇安裝好的264-> Package(軟件包) -> Lock Version(鎖定版本)

    使用aptitude命令的話,請通過下面的命令來鎖定版本:
    sudo aptitude hold x264 ffmpeg
    Using ffmpeg and x264使用ffmpeg和x264

    使用ffmpeg最簡便的轉換視頻和音頻的方法是用它的預設文件(ffmpeg presets),這些文件在ffmpeg的源代碼中就有。我們需要把它複製到當前用戶目錄的.ffmpeg文件夾中:
    命令:
    新建文件夾

 mkdir ~/.ffmpeg

    複製預設文件到上面的目錄中

   

 cp ~/ffmpeg/ffpresets/* ~/.ffmpeg

    現在就可以使用預設文件了(libx264-default.ffpreset,libx264-hq.ffpreset,libx264-normal.ffpreset,libx264-fastfirstpass.ffpreset,libx264-max.ffpreset),下面的兩個例子會指導你如何使用這些預設:

    命令:

 ffmpeg -i infile -vcodec libx264 -vpre hq -b 1M -bt 1M -threads 0 outfile.mp4

    改變-vpre 後面的參數即可更改不同的預設,很容易理解這幾個參數的意思

    備註(點擊查看對應文件):

 

 » default - 默認參數(x264 CLI default values)
» fastfirstpass - 快速轉換(disables options unnecessary for first pass)
» normal - 正常(Dark Shikari’s Q55 preset)
» hq - 高質量轉換(Dark Shikari’s Q75 preset)
» max - 最大文件(all options maxed out)

    您確實可以不使用預設文件,不過那樣的話你轉換視頻或音頻文件時要照顧到很多細節,代碼會很長,使用預設文件省去了我們很多麻煩!升級ffmpeg和x264

    理所當然我們即使我們鎖定了版本,我們還是會想到升級我們的ffmpeg和x264到最新的版本,我們可以使用下面的命令(假定您沒有刪除相應的svn和git同步文件):

  

 sudo apt-get purge ffmpeg x264
cd ~/x264
make distclean
git pull
./configure
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1"
cd ~/ffmpeg
make distclean
svn update
./configure --enable-gpl --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3"

    卸載ffmpeg和x264

    Ubuntu發行版Intrepid Ibex 8.10的操作:
    命令:
    sudo apt-get purge x264 ffmpeg build-essential yasm subversion git-core checkinstall texi2html libfaad-dev libfaac-dev libmp3lame-dev libtheora-dev
    Ubuntu發行版Hardy Heron 8.04:
    命令:

   

 sudo apt-get purge x264 ffmpeg build-essential yasm subversion git-core checkinstall texi2html libfaad-dev libfaac-dev liblame-dev libtheora-dev

    引用和相關網站:
    本文英文原文: HOWTO: Compile the latest ffmpeg and x264 from source
    ffmpeg主頁
    FFmpeg libx264 presets預設文件下載:ffpresets.zip (20)
    ffmpeg源代碼configure幫助文件中文譯文(編譯說明)
    FFmpeg x264 encoding guide(FFmpeg x264編碼指南英文版)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章