Monday, February 16, 2009

Compile FFMPEG with Cygwin under Windows

This atricle guides you how to compile FFMPEG with Cygwin under Windows. The orginal post is at http://mqjing.blogspot.com/2008/12/c-cygwin-ffmpeg-make-ffmpeg-under.html by 井民全.

FFmpeg 是著名的多媒體壓縮解壓縮 library, 例如: 你想處理壓縮 Xvid 或 Divx 壓縮解壓縮, 這個專案裡面的 source 你都可以參考. 可是呢...

這東西不好編譯!

尤其是你以為正在編譯的版本和網路上文章作者所說的一樣時, 你就會開始犯錯. 要正確的編譯 FFmpeg 你一定要注意版本序號以及你的編譯環境.

FFmpeg 版本一直在進展, 昨天更新的最新 source code 並不一定保證在任何的編譯環境都能順利成功. 因為 update 的作者不一定會把所有的編譯環境都測過才 update, 如此一來可以意味著 open source 領域有一個 source code dependency 問題.

如果你想要編譯 FFmpeg 最好使用作者當時寫作並測試通過的所有軟體版本, 已保證第一次就會成功.

open source 社群漏掉的拼圖, 就是編譯環境與 source code 的版本控制還不是那麼的完善, 新版本的 library source code 可能造成其他的第三方應用軟體編譯失敗. 現在想想很明白這道理, 可是這卻是大家花費大量寶貴時間解決編譯問題的根源所在.

或許在編譯之前就要詳細檢查所有會用到 source code 的版本, 現在 ./configure 不完整, 要徹底解決 source code 版本 dependency 的問題, 還有待大家努力!

Step 1: Checkout the FFmpeg source code (20080508 版本)

  • svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk@12383 ffmpeg-12383

(我使用 revision 12383 版以前的原因, 在於最新版的 vfwcap.c 無法在 cygwin 下編譯成功)


Step 2: Patch--ffmpeg--cygwin (see link)

  • replace all llrint functions to the lrint in the libavcodec/mpegaudiodec.c

Step 3: Setup the configure option script

1. modify the option from --enable-pp to the --enable-postproc

  • from revision 12376, rename pp variable to postproc for consistency

2. --target-os=mingw32 (from revision 8049)

3. [Optional] modify the option from --enable-amr_nb to the --enable-libamr-nb (not free. see:http://www.3gpp.org)

4. [Optional] add the option --enable-nonfree , if you add the option --enable-amr_nb

ex:

--------------------- configure-ffmpeg.sh ---------------------

./configure --enable-memalign-hack \
--enable-postproc \
--extra-cflags=-I/usr/win32/include \
--extra-ldflags=-L/usr/win32/lib \
--prefix=/usr/win32 \
--cc="gcc -mno-cygwin" \
--enable-gpl \
--disable-vhook \
--enable-shared \
--target-os=mingw32 \
--extra-cflags=-mno-cygwin \
--extra-libs=-mno-cygwin

--------------------- configure-ffmpeg.sh ---------------------

5. Update your /usr/win32/include

These content is out of the version of the FFmpeg which you want to build. Update these files by yourself. Copy all header files in the following directories to /usr/win32/include.

ffmpeg-12383\libavcodec, libavdevice, libavfilter, libavformat, libavutil, libpostproc, libswscale

7. Create Makefile for building the FFmpeg

run the following command to setup the FFmpeg configures

   configure-ffmpeg.sh


 


6. make


加入 amr 語音libarary 的步驟


1. 新增 configure-ffmpeg.sh



--enable-libamr-nb \

--enable-nonfree \



2. 修改 source code



at ffmpeg-12383/libavcodec/libamr.c



#include 改成 #include



#include 改成 #include



否則你可能會遭遇到 下面的錯誤訊息



libamr.c:80:30: amrnb/interf_dec.h: No such file or directory

libamr.c:81:30: amrnb/interf_enc.h: No such file or directory


libamr.c:93: error: field `mode' has incomplete type



3. 增加 amr_float 內相關的 depend



否則你會遭遇到下面的錯誤



---------------------------------------------------------------------



libamr.o: In function `amr_nb_decode_init':

/home/Jing/ffmpeg-12383/libavcodec/libamr.c:369: undefined reference to `_Decode


r_Interface_init'


libamr.o: In function `amr_nb_encode_init':


/home/Jing/ffmpeg-12383/libavcodec/libamr.c:408: undefined reference to `_Encode


r_Interface_init'



---------------------------------------------------------------------



a. cd /home/Jing/ffmpeg-12383/libavcodec/amr_float



b. 修改 amr_float 裡面的 makefile.gcc, 讓他獨立於 cygwin



原來是



CFLAGS = -Wall -I. $(CFLAGS_$(MODE)) -D$(VAD)



加上 CFLAGS = -Wall -mno-cygwin -I. $(CFLAGS_$(MODE)) -D$(VAD)



否則你在編譯 ffmpeg 的 libcodec 時, 會遇到 找不到 ___getreent 的錯誤.



amr_float/interf_dec.o:interf_dec.c:(.text+0x34e): undefined reference to `___ge

treent'


amr_float/interf_enc.o:interf_enc.c:(.text+0x56e): undefined reference to `___ge


treent'



c. 產生必要的 .o 檔



make -fmakefile.gcc



d. 修改 ffmpeg/libcocdec 的 Makefile, 加入必要的 amr_float object files



OBJS-$(CONFIG_LIBAMR_NB) += libamr.o



改成


OBJS-$(CONFIG_LIBAMR_NB) += libamr.o ./amr_float/interf_dec.o ./amr_float/interf_enc.o ./amr_float/sp_dec.o ./amr_float/sp_enc.o

No comments:

Check clients which connect to Mac OS X Wi-Fi Internet Sharing

arp -i bridge100 -a bridge100 may be different on your Mac OSX