FFMPEG windows build procedure

From Hawk Wiki
Revision as of 21:11, 12 August 2011 by Hall (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#!/bin/sh   
  
# How to compile ffmpeg/x264 binaries for both 32bit and 64bit on Windows   
#   
#  At first, you should install Git into your Windows.   
#   1. Download Git from http://msysgit.googlecode.com/files/Git-1.7.4-preview20110204.exe   
#   2. Doubleclick Git-1.7.4-preview20110204.exe   
#   3. "Welcome to the Git Setup Wizard" : Next>   
#   4. "Information" (GPLv2 descliption) : Next>   
#   5. "Select Destination Location" : C:\Git (or where you want) and Next>   
#   6. "Select Components" : all checks off and Next>   
#   7. "Select Start Menu Folder" : check "Don't create a Start Menu folder" and Next>   
#   8. "Adjusting your PATH environment" :   
#         check "Run Git and included Unix tool from the Windows Command Prompt" and Next>   
#      * This method has the possibility to cause some trouble to your system.   
#        When it happens, uninstall Git via ControlPanel.   
#        If you know how to edit /etc/profile, you will choose "Use Git Bash only".   
#   9. "Configuring the line ending conversions" :   
#         check "Checkout as-is,commit as-is" and Next>   
#    
#  Next, you have to get latest MSYS, mingw-w64 binaries, pkg-config, subversion, nasm,   
# yasm, and the others.   
#  I recommend you to use XhmikosR's toolchain.   
#  You will be able to get all dependencies at once.   
#   1. Go to http://xhmikosr.1f0.de/index.php?folder=dG9vbHM=   
#   2. Download MSYS_MinGW_GCC_***_x86-x64_Full.7z   
#     * You should download MSYS_MinGW_GCC_***_x86-x64_'Full'.7z because some dependencies   
#      are not included in MSYS_MinGW_***_x86-x64.7z(e.g. perl.exe).   
#   3. extract it with 7zip, and put it on the place that you want (e.g. C:\MSYS).   
#   4. Doubleclick C:\MSYS\msys.bat   
#     * If you want to use other MinGW, edit /etc/fstab.   
#   
#  Now, you finished all the preparations to run this script.   
#  Save this script into $HOME as 'my_build.sh', and type './my_build.sh' on bash.   
  
  
# ----------------------set valuables------------------------   
MY_BUILD=${HOME}/build   
MY_X86=${MY_BUILD}/x86   
MY_X64=${MY_BUILD}/x64   
  
# -----------------download source codes------------------   
mkdir -p ${MY_BUILD}/src   
  
cd ${MY_BUILD}/src   
#git clone git://git.libav.org/libav.git libav   
git clone git://git.videolan.org/x264.git x264   
#svn co http://ffmpegsource.googlecode.com/svn/trunk/ ffms2   
git clone git://github.com/mstorsjo/vo-aacenc.git   
git clone git://github.com/mstorsjo/vo-amrwbenc.git   
wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz   
wget http://downloads.xiph.org/releases/ogg/libogg-1.2.2.tar.gz   
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.bz2   
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2   
wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz   
wget http://openjpeg.googlecode.com/files/openjpeg_v1_4_sources_r697.tgz   
wget http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/0.1.2/opencore-amr-0.1.2.tar.gz   
wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.bz2   
cp -r ./ $MY_X64   
  
wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz   
wget http://www.openssl.org/source/openssl-1.0.0d.tar.gz   
wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3.tgz   
wget http://webm.googlecode.com/files/libvpx-v0.9.6.tar.bz2   
wget http://downloads.xvid.org/downloads/xvidcore-1.3.1.tar.gz   
#wget http://code.entropywave.com/download/orc/orc-0.4.11.tar.gz   
#wget http://diracvideo.org/download/schroedinger/schroedinger-1.0.10.tar.gz   
cp -r ./ $MY_X86   
  
cd $MY_X86   
for i in ./*gz; do tar zxvf $i; done   
for i in ./*.tar.bz2; do tar jxvf $i; done   
rm ./*gz ./*.tar.bz2   
  
cd $MY_X64   
for i in ./*gz; do tar zxvf $i; done   
for i in ./*.tar.bz2; do tar jxvf $i; done   
rm ./*gz ./*.tar.bz2   
  
  
# ------------compiling external libraries for ffmpeg---------   
# *I don't know how to compile OpenCV and Frei0r.   
  
# ===only 32bit ===   
# note:   
# The following libraries are able to compile only on 32bit.   
# If you want to compile them on 64bit, write a pathch yourself and send it to the devs.   
  
#Compiling SDL (ffplay requires this as renderer)   
# note:   
#  It becomes impossible for me to link SDL libraries statically with ffplay   
# because of some recent changes. thus you have to copy SDL.dll to the folder   
# in your PATH.(26/03/2011)   
cd ${MY_X86}/SDL-*   
./configure --prefix=/mingw/i686-pc-mingw32   
make clean && make && make install   
cp /mingw/i686-pc-mingw32/bin/SDL.dll /usr/local/bin/   
  
#Compiling OpenSSL (librtmp requires this)   
cd ${MY_X86}/openssl-*   
# note:   
# for openssl, the first 'C' of Configure is a capital letter.    
./Configure mingw --prefix=/mingw/i686-pc-mingw32   
make && make install   
  
#Compiling librtmp(rtmpdump)   
cd ${MY_X86}/rtmpdump-*   
make prefix=/mingw/i686-pc-mingw32 SYS=mingw SHARED=no   
make install prefix=/mingw/i686-pc-mingw32 SYS=mingw SHARED=no   
# note:   
# librtmp links libws2_32 and libwinmm on MinGW, but it is not written in librtmp.pc.   
# And, ffmpeg's configure requires pkg-config to check librtmp.   
# Thus you should edit librtmp.pc as follows.   
sed -i -e 's/Libs: -L${libdir} -lrtmp -lz/Libs: -L${libdir} -lrtmp -lz -lws2_32 -lwinmm/g' /mingw/i686-pc-mingw32/lib/pkgconfig/librtmp.pc   
  
#Delete orc and schroedinger compile(20110421)   
  
#Compiling libvpx   
#20110313:update libvpx version from 0.9.5 to 0.9.6   
cd ${MY_X86}/libvpx-*   
./configure --target=x86-win32-gcc --cpu=i686 --disable-examples --enable-runtime-cpu-detect   
make clean && make   
cp libvpx.a /mingw/i686-pc-mingw32/lib/   
mkdir -p /mingw/i686-pc-mingw32/include/vpx   
cp ./vpx/*.h /mingw/i686-pc-mingw32/include/vpx/   
#Compiling xvid   
#20110325:update xvidcore version from 1.3.0 to 1.3.1   
cd ${MY_X86}/xvidcore/build/generic   
./configure   
make   
cp =build/xvidcore.a /mingw/i686-pc-mingw32/lib/libxvidcore.a   
cp ../../src/xvid.h /mingw/i686-pc-mingw32/include/   
  
# === both 32bit and 64bit ===   
  
#Compiling lame   
cd ${MY_X86}/lame-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared --enable-nasm   
make clean && make && make install-strip   
  
cd ${MY_X64}/lame-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 
 --disable-shared --enable-nasm   
make clean && make && make install-strip   
  
#Compiling faac   
# note:   
# faac is incompatible with GPL/LGPL.   
cd ${MY_X86}/faac-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared --without-mp4v2   
make clean && make && make install-strip   
  
cd ${MY_X64}/faac-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32  --disable-shared --without-mp4v2   
make clean && make && make install-strip  
 

#Compiling opencore-amr   
# note:   
# opencore-amr's license(Apache 2.0) is compatible with GPLv3 or later.   
cd ${MY_X86}/opencore-amr-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/opencore-amr-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling vo-aacenc   
# note:   
# vo-aacenc's license(Apache 2.0) is compatible with GPLv3 or later.   
# vo-aacenc-0.1.0.tar.gz includes some clitical issues.   
# thus you should get latest source code from git repo.   
cd ${MY_X86}/vo-aacenc   
autoreconf   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/vo-aacenc   
autoreconf   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling vo-amrwbenc   
# note:   
# vo-amrwbenc's license(Apache 2.0) is compatible with GPLv3 or later.   
cd ${MY_X86}/vo-amrwbenc   
autoreconf   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/vo-amrwbenc   
autoreconf   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling libogg (libtheora/libvorbis/speex requires this)   
cd ${MY_X86}/libogg-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/libogg-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling libtheora   
cd ${MY_X86}/libtheora-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/libtheora-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling libvorbis   
cd ${MY_X86}/libvorbis-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
  
cd ${MY_X64}/libvorbis-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
  
#Compiling speex   
cd ${MY_X86}/speex-*   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared --enable-sse   
make clean && make && make install-strip   
  
cd ${MY_X64}/speex-*   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared --enable-sse   
make clean && make && make install-strip   
  
#Compiling openjpeg   
# note:   
# Compiling openjpeg is weird.   
cd ${MY_X86}/openjpeg_*   
./configure && make clean   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-shared   
make clean && make && make install-strip   
# note:   
#  The .pc files of openjpeg-1.4.0 are installed into /usr/lib/pkgconfig   
# instead of install-prefix/lib/pkgconfig.   
#  You should move these files into install-prefix/lib/pkgconfig.   
mv /usr/lib/pkgconfig/libopenjpeg*.pc /mingw/i686-pc-mingw32/lib/pkgconfig/   
  
cd ${MY_X64}/openjpeg_*   
./configure && make clean   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-shared   
make clean && make && make install-strip   
mv /usr/lib/pkgconfig/libopenjpeg*.pc /mingw/x86_64-w64-mingw32/lib/pkgconfig/   

#Compiling libx264   
# Edit configure line assume r1995 or later(20110514)   
cd ${MY_X86}/x264   
./configure --prefix=/mingw/i686-pc-mingw32 --disable-cli --enable-static --disable-gpac --disable-swscale --enable-win32thread --enable-strip   
make clean && make # or make fprofiled VIDS='/path/to/file.y4m'   
make install   
  
cd ${MY_X64}/x264   
./configure --prefix=/mingw/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --cross-prefix=x86_64-w64-mingw32- --disable-cli --enable-static --disable-gpac --disable-swscale --enable-win32thread   
make clean && make # or make fprofiled VIDS='/path/to/file.y4m'   
make install   

#compile ffmpeg final working code
cd ${MY_BUILD}/src
git clone git://git.videolan.org/ffmpeg.git ffmpeg_latest
cd ffmpeg_latest
PKG_CONFIG_PATH=/mingw/i686-pc-mingw32/lib/pkgconfig/ 
./configure --prefix=/mingw/i686-pc-mingw32 --disable-doc --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-w32threads  --enable-runtime-cpudetect --enable-memalign-hack --enable-avisynth  --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac  --enable-libmp3lame --enable-libopenjpeg --enable-libspeex  --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --enable-libvo-amrwbenc  --enable-libvpx --enable-libx264 --enable-libxvid --disable-decoder=libvpx  --disable-hwaccels --cpu=i686 --disable-debug --extra-cflags=-fno-strict-aliasing --enable-avfilter
make 
make install
#compile x64
make clean
PKG_CONFIG_PATH=/mingw/x86_64-w64-mingw32/lib/pkgconfig  
./configure --prefix=/mingw/x86_64-w64-mingw32 --arch=x86_64 --disable-doc --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-w32threads  --enable-runtime-cpudetect --enable-memalign-hack --enable-avisynth  --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac  --enable-libmp3lame --enable-libopenjpeg --enable-libspeex  --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --enable-libvo-amrwbenc  --enable-libvpx --enable-libx264 --enable-libxvid --disable-decoder=libvpx  --disable-hwaccels --disable-debug --extra-cflags=-fno-strict-aliasing --enable-avfilter