1. 程式人生 > >linux平臺ffmpeg+h.264的本機移植和交叉編譯

linux平臺ffmpeg+h.264的本機移植和交叉編譯

本文講解在ubuntu和arm平臺下的ffmpeg和x264相關庫的移植,最終實現使用ffmpeg進行H.264編碼。

1、原始碼下載:

2、編譯

    2.1、yasm-1.2.0移植

      PC可使用如下命令對yasm庫進行配置、編譯和安裝,庫的安裝目錄需要根據自己的需要進行配置修改:

  1. ./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/x64/

  2. make

  3. make install

       ARM平臺使用如下命令進行配置、編譯和安裝:

  1. ./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/arm --host=arm-linux

  2. make

  3. make install

      2.2、設定臨時環境變數

    使用如下命令將yasm的安裝目錄設定為臨時環境變數,具體目錄按照自己的實際需要進行配置修改。

     PC平臺

export PATH=$PATH:/home/fyx/workspace/ffmpeg/x64/bin

    ARM平臺

export PATH=$PATH:/home/fyx/workspace/ffmpeg/arm/bin

   2.3、x264移植

    PC端使用如下命令進行配置、編譯和安裝。

  1. ./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/x86

  2. make

  3. make install

   ARM平臺使用如下命令進行配置。

./configure --enable-shared --disable-asm --host=arm-linux --prefix=/home/fyx/workspace/ffmpeg/arm

    配置完成後編輯config.mak檔案,修改如下配置為如下選項:

  1. ARCH=arm

  2. CC=arm-linux-gcc

  3. LD=arm-linux-gcc -o

  4. AR=arm-linux-ar rc

  5. AS=

  6. RANLIB=arm-linux-ranlib

   編譯和安裝

  1. make

  2. make install

  2.4、xvid移植

   PC端使用如下命令進行配置、編譯和安裝。

  1. ./configure --prefix=/home/fyx/workspace/ffmpeg/x64/

  2. make

  3. make install

  ARM平臺使用如下命令進行配置、編譯和安裝。

  1. ./configure --host=arm-linux --target=arm-linux --prefix=/home/fyx/workspace/ffmpeg/arm

  2. make

  3. make install

   2.5、ffmpeg移植

   PC端使用如下命令進行配置、編譯和安裝。

  1. ./configure --enable-shared --enable-gpl --enable-libx264 --prefix=/home/fyx/workspace/ffmpeg/x64/ --extra-cflags=-I/home/fyx/workspace/ffmpeg/x64/include --extra-ldflags=-L/home/fyx/workspace/ffmpeg/x64/lib

  2. make

  3. make install

   ARM平臺使用如下命令進行配置、編譯和安裝。

  1. ./configure --target-os=linux --cc=arm-linux-gcc --arch=arm --enable-shared --enable-cross-compile --cross-prefix=arm-linux- --enable-gpl --enable-libx264 --prefix=/home/fyx/workspace/ffmpeg/arm --extra-cflags=-I/home/fyx/workspace/ffmpeg/arm/include --extra-ldflags=-L/home/fyx/workspace/ffmpeg/arm/lib

  2. make

  3. make install

3、測試

使用eclipse建立C++工程,將本機編譯生成的include和lib目錄拷貝到工程目錄中,將ffmpeg原始檔的doc目錄下的example中的avcodec.c拷貝到工程中,設定工程的標頭檔案目錄。將生成的lib新增到工程中。編譯通過後測試即可。

本機測試工程目錄結構:

工程屬性中新增如下庫的連線,並將工程標頭檔案新增到標頭檔案目錄中。

編譯之後執行執行可執行程式,如果提示找不到庫將需要的庫拷貝到/lib目錄下即可。本例中使用FFmpeg h264測試使用FFmpeg編碼h264資料,編碼後用VLC播放器開啟生成的test.h264視訊,效果如下: