首先下載 ffmpeg 0.5 的原始碼,官方載點:http://ffmpeg.org/releases/ffmpeg-0.5.tar.bz2

編譯的最基本選項。(以下所述皆為靜態編譯,得到的 ffmpeg.exe 可獨立執行。不編譯 dll)

./configure --enable-memalign-hack --extra-cflags=-fno-common
make
make install

--enable-memalign-hack,若無此項無法編譯;-fno-common 為應對一個 GCC 的 bug


偶所使用的編譯選項

CFLAGS="-pipe -s -fno-common" /path/to/ffmpeg-0.5/configure \
--enable-memalign-hack --disable-logging --disable-debug --disable-ffserver --enable-avisynth \
--enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --cpu=i586 \
\
--enable-pthreads --enable-libx264 --enable-libmp3lame --enable-libfaac --enable-libgsm --enable-libtheora

前兩行的選項共計11個,為 ffmpeg 內建可直接使用的選項。--cpu=i586,不能使用 i686 及以上,否則無法使用內建 mpeg4 轉檔,ffplay 無法播放視訊。編譯過程中會強制開啟 -O3,configure 的 --cpu 參數會覆蓋掉 CFLAGS 中指定的 -march。

最後一行的6個選項需要事先安裝其他相對應的軟體包才能開啟。因為 ffmpeg 有內建 mpeg4 和 vorbis,所以無需額外安裝外部編碼器 libxvid 和 libvorbis。

pthreads(--enable-pthreads
CPU 的多線程 / 多核心支援。libx264 依賴於這個軟體包。如果只是想要多線程 / 多核心支援,但不安裝 libx264。則可使用內建的 Win32 threads(--enable-w32threads

下載 pthreads:pthreads-w32-2-8-0-release.tar.gz

下載補丁:
http://ffmpeg.arrozcru.org/wiki/images/1/12/Pthreads-w32-2-8-0.diff http://ffmpeg.arrozcru.org/wiki/images/d/dd/Ffmpeg_r15966_static_pthreads.diff

pthreads 資料夾中:
make clean GC-static
patch -p1 < ../pthreads-w32-2-8-0.diff
cp libpthreadGC2.a /mingw/lib
cp pthread.h sched.h /mingw/include

ffmpeg 資料夾中:
patch -p0 < ../Ffmpeg_r15966_static_pthreads.diff

第一個補丁解決 sched.h 編譯出錯的問題。第二個補丁解決 ffmpeg 無法使用 pthreads 靜態庫的問題。

x264(--enable-libx264

下載 x264 原始碼 ftp://ftp.videolan.org/pub/videolan/x264/snapshots

下載 YASM:yasm-0.7.2-win32.exe。重新命名為 yasm.exe,複製到 msys\mingw\bin

x264 原始碼資料夾中執行:
./configure --prefix=/mingw --extra-cflags=-DPTW32_STATIC_LIB ; make -j2 ; make install

--extra-cflags 必備,不然 ffmpeg 那邊會編譯不通過卡在 libx264.a:undefined reference to `_imp__pthread

lame(--enable-libmp3lame

下載 LAME:http://downloads.sourceforge.net/lame/lame-398-2.tar.gz
下載補丁:http://superfq.googlepages.com/ffmpeg-20080908-lame-flush-once.patch

前往 lame-398-2。執行:
./configure --prefix=/mingw --disable-shared --disable-frontend ; make -j2 ; make install

ffmpeg 資料夾中:
patch -p0 < ../ffmpeg-20080908-lame-flush-once.patch

補丁用以解決 lamemp3 編碼結束時出現錯誤的問題:lame: output buffer too small, Audio encoding failed

faac(--enable-libfaac

下載 FAAC:http://downloads.sourceforge.net/faac/faac-1.28.tar.bz2

faac 資料夾中:
./bootstrap ; ./configure --prefix=/mingw --disable-shared --without-mp4v2 ; make -j2 ; make install

FAAC 無需編入 mp4 容器支援,封入 mp4 容器的工作由 ffmpeg 負責。

GSM(--enable-libgsm
經其編碼後的音訊聽起來就像是從電話線中傳出。(make 編譯出錯無視之:make: *** [bin/toast] Error 1)

下載 GSM:http://user.cs.tu-berlin.de/~jutta/gsm/gsm-1.0.12.tar.gz

gsm-1.0-pl12 資料夾中:
make -j2
cp lib/libgsm.a /mingw/lib
cp inc/gsm.h /mingw/include

使用方法特殊:ffmpeg -i input.wav -acodec libgsm_ms -ac 1 -ar 8000 -ab 13000 output.wav

Theora(--enable-libtheora
libtheora 是 OGG 的視訊編碼,依賴於 libogg。

下載
libogg:http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
Theora:http://downloads.xiph.org/releases/theora/libtheora-1.0.tar.bz2

libogg、libtheora-1.0 資料夾中(先安裝 libogg):
./configure --prefix=/mingw --disable-shared ; make -j2 ; make install



FFplay
ffplay 是一個簡單的問題多多的陽春播放器,不支援去交錯。偶是拿它來作測試。一般的影音播放用途應使用其他播放器。ffplay 依賴於 SDL,若未安裝 SDL 則不會編譯 ffplay。

下載 SDL:http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz

解壓縮後用記事本開啟 SDL-1.2.13\bin\sdl-config,將 prefix 由 Users/hercules/tmp/SDL-1.2.13 改為 /mingw

複製 SDL-1.2.13 中的 bin, include, lib 至 /mingw。出現取代資料夾提示時選擇全部取代。

若 configure 輸出的訊息中有顯示 SDL support 為 yes,即表示可編譯出 ffplay.exe。使用 ffplay 需要將 SDL.dll 同 ffplay.exe 放在一起。


幫助文檔
必需安裝有 texi2html,才會在編譯時編譯出文檔。

下載 texi2html:http://ftp.twaren.net/Unix/NonGNU/texi2html

texi2html 資料夾中:
./configure --prefix=/mingw ; make install
touch /mingw/bin/pod2man

touch /mingw/bin/pod2man。解決編譯時出現錯誤:「/bin/sh: pod2man: command not found」。如果你有 pod2man 可以省去這步。pod2man 是一個 Perl script,這裡建立一個空的免得找不到命令。

幫助文檔主要就是6個 HTML 檔案,偶已經給它 PO 到網路上:

  1. FFmpeg FAQ
  2. FFmpeg Documentation
  3. FFplay Documentation
  4. FFserver Documentation
  5. General Documentation
  6. Video Hook Documentation



檔案下載
ffmpeg-0.5-windows-i586.7z:包括 ffmpeg、ffplay 和幫助文檔。

備用載點一
備用載點二

arrow
arrow
    全站熱搜

    呆丸北拜 發表在 痞客邦 留言(4) 人氣()