首先下載 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 到網路上:
- FFmpeg FAQ
- FFmpeg Documentation
- FFplay Documentation
- FFserver Documentation
- General Documentation
- Video Hook Documentation
檔案下載
ffmpeg-0.5-windows-i586.7z:包括 ffmpeg、ffplay 和幫助文檔。
備用載點一
備用載點二

*****
*****
不好意思打擾一下 我剛好也試著在 windows 上 build ffmpeg (min sys + mingw) 遇到一些問題 不知道你有沒有遇到 我在 win 7 上 make 時 一直遇到 permission denied 的問題 即使我用 chmod 777 也沒用 我改到 XP 上 就沒了這問題 可是又有其他問題 Orz 在 make 時 libavformat/allformats.c: In function 'av_register_all': libavformat/allformats.c:57: error: 'CONFIG_AC3_DEMUXER' undeclared (first use in this function) libavformat/allformats.c:57: error: (Each undeclared identifier is reported only once libavformat/allformats.c:57: error: for each function it appears in.) libavformat/allformats.c:65: error: 'CONFIG_ASF_STREAM_MUXER' undeclared (first use in this function) libavformat/allformats.c:118: error: 'CONFIG_MPEG1SYSTEM_MUXER' undeclared (first use in this function) libavformat/allformats.c:134: error: 'CONFIG_NSV_DEMUXER' undeclared (first use in this function) libavformat/allformats.c:153: error: 'CONFIG_PCM_U32BE_DEMUXER' undeclared (first use in this function) libavformat/allformats.c:192: error: 'CONFIG_WAV_MUXER' undeclared (first use in this function) libavformat/allformats.c:192: error: 'CONFIG_WAV_DEMUXER' undeclared (first use in this function) libavformat/allformats.c:198: error: 'CONFIG_YUV4MPEGPIPE_MUXER' undeclared (first use in this function) make: *** [libavformat/allformats.o] Error 1 不知道可以向你請教嗎 謝謝你的回覆
win 7 要停用 UAC 才不會一直遇到 permission denied 的問題 make 時的錯誤不知道如何解決
太好了 我把uac 停用後 就沒有 permission denied 的問題了 如果還有不懂的地方 還望你多多指教 謝謝
我已經很久沒有編譯 ffmpeg 了。
不好意思又來請教了 我已經編譯出有 x264 功能的 ffmpeg.exe 可是我想要的是 編譯出可以讓 vc 使用的dll avcodec.dll ... 等 請問指令我該怎麼下呢?? 謝謝你的回覆
不知道。我只編譯過 msys + mingw 的 ffmpeg,沒編譯過 VC 的。