26/08/2009

FFMPEG COMPILATION IN WINDOWS USING MINGW32/MSYS

FFMPEG COMPILATION IN WINDOWS USING MINGW32/MSYS

1-)Minimal SYStem (MSYS) installation
Download the MSYS executable from here and install into c:\msys. Do not continue with the postinstall operation.
2-)Update MSYS
Update the MSYS to a more recent version (1.0.11) by downloading the package from here and copy mount.exe, msys-1.0.dll and ps.exe into c:\msys\bin directory.
3-)MSYS DTK(Developer Tool Kit)
Download the DTK from here and install into c:\msys.
4-)Update BASH
Download bash version 3.1 from here and copy bash.exe and sh.exe from the bin subdirectory to c:\msys\bin directory and replace sh.exe with the old one.
5-)Install MINGW
Download MINGW 5.1.4 from here and follow the instructions as follows:
-Download only
-Candidate
-Check the followings
MinGW base tools (autoselected)
g++ compiler
and run the exe again but this time follow the instructions as follows
-Download and install
-Candidate
-Check the followings
MinGW base tools (autoselected)
g++ compiler
make the installation folder as c:\msys\mingw it will download the following packages
mingw-runtime-3.10.tar.gz
w32api-3.7.tar.gz
binutils-2.16.91-20060119-1.tar.gz
gcc-core-3.4.5-20060117-1.tar.gz
gcc-g++-3.4.5-20060117-1.tar.gz
6-)Configuring FSTAB
Rename the file in c:\msys\etc\fstab.sample as fstab and replace the the line c:/mingw to c:/msys/mingw using a text editor like Notepad++. Notepad++ is recommended as the text editor for all of the editing operations. It can be downloaded from here Note:Open c:\msys\msys.bat with Notepad++ and replace “-fn Courier-12” to “-fn Courier-16” to make the fonts larger in the msys window.
7-)Update MAKE
Download the MAKE MSYS v 3.81 from here and copy the files in the bin and share folder into the same folders under
c:\msys\mingw\bin and c:\msys\mingw\share.
8-)Coreutils
Download the coreutils package from here and copy the whomai.exe to c:\msys\minw\bin
9-)MINGW Utils
Downlaod the package from here and copy the unix2dos.exe to c:\msys\mingw\bin.
10-)Update GCC 3.4.5 to 4.3.3
Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
11-)Update GCC Core 3.4.5 to 4.3.3
Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
12-)ICONV
Download the package from here and install it into c:\msys\mingw.
13-)MINGW RUNTIME Update From 3.10 to 3.15.2
Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
14-)W32 API Update from 3.7 to 3.13
Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
15-)BINUTILS Update from 2.16.91 to 2.19.1
Download the package from here and copy all of the directories
to c:\msys\mingw\<correponding directory>

AFTER ALL OF THESE OPERATIONS ITS TIME TO GET FFMPEG FROM SVN

In order to get ffmpeg from svn, first we have to download and install a SVN client, TortoiseSVN is recommended. TortoiseSVN can be downloaded from http://tortoisesvn.tigris.org/.
After installing SVN client we can download the ffmpeg SVN by performing a checkout to the address svn://svn.mplayerhq.hu/ffmpeg/trunk

COMPILING FFMPEG WITHOUT ADDITIONAL LIBRARIES

After installing MSYS and MINGW there will be a shortcut on your desktop with a blue M icon. Just double click on it to run MSYS or run C:\msys\msys.bat Assuming that the ffmpeg is downloaded to c:\ffmpeg just type
cd c:\ffmpeg
./configure --enable-memalign-hack --extra-cflags=-fno-common --enable-static --disable-shared
If an error occurs like “pr: Command not found” copy the pr.exe file in the bin directory of coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2 that you previously downloaded to c:\msys\bin.
make
After the make operation, if you see “strip ffmpeg.exe” as the last line of the terminal, it means that the compilation is successful and its turn for the next command:
make install
COMPILING FFMPEG WITH ADDITIONAL STATIC LIBRARIES

For all of the configure commands we will use the following instruction
./configure --prefix=/mingw --enable-static --disable-shared
make
make install
1-)ZLIB-1.2.3
Download the package from here and extract the package to c:\msys\zlib-1.2.3 and follow the instructions:
cd c:\msys\zlib-1.2.3
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the zlib-1.2.3 directory after installation.

2-)XVIDCORE-1.2.1
Download the package from here and
extract the package to c:\msys\xvidcore-1.2.1 and follow the instructions:
cd c:\msys\xvidcore-1.2.1
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the xvidcore-1.2.1 directory after installation.

3-)SPEEX-1.2rc1
Download the package from here and extract the package to c:\msys\speex-1.2rc1 and follow the instructions:
cd c:\msys\speex-1.2rc1
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the speex-1.2rc1 directory after installation.

4-)LIBOGG-1.1.3
Download the package from http://www.xiph.org/downloads/ and extract the package to
c:\msys\libogg-1.1.3 and follow the instructions:
cd c:\msys\libogg-1.1.3
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the libogg-1.1.3 directory after installation.

5-)LIBOIL-0.3.16
Dwonload the package from here and extract the package to c:\msys\liboil-0.3.16 and follow the instructions:
cd c:\msys\liboil-0.3.16
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the liboil-0.3.16 directory after installation.

6-)GLIB-2.18.3 and PKG-CONFIG-0.23-2
Download the glib package from here and extract the files into c:\msys\mingw\<corresponding directory>
Download the package from here and extract the files into c:\msys\mingw\<corresponding directory>

7-)LIBSCHROEDINGER-1.0.7
Download the package from here and extract the package into c:\msys\schroedinger-1.0.7and follow the instructions:
cd c:\msys\schroedinger-1.0.7
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the schroedinger-1.0.7 directory after installation.

8-)LIBTHEORA-1.0
Download the package from http://www.theora.org/downloads/ and extract the package into c:\msys\libtheora-1.0 and follow the instructions:
cd c:\msys\libtheora-1.0
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the libtheora-1.0 directory after installation.

9-)LIBMP3LAME
Download the package from here and extract to c:\msys\lame-398 and follow the instructions:
cd c:\msys\lame-398
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the lame-398 directory after installation.

10-)AMRNB-7.0.0.2
Download the package from here and extract th epackage to c:\msys\amrnb-7.0.0.2 and follow the instructions:
cd c:\msys\amrnb-7.0.0.2
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the amrnb-7.0.0.2 directory after installation.

11-)AMRWB-7.0.0.3
Download the package from here and extract the package into c:\msys\amrwb-7.0.0.3 and follow the instructions:
cd c:\msys\amrwb-7.0.0.3
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the amrwb-7.0.0.3 directory after installation.

12-)FAAD-2.6.1
Download the packge from here and extract the package into c:\msys\faad-2.6.1 and follow the instructions:
cd c:\msys\faad-2.6.1
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the faad-2.6.1 directory after installation.

13-)FAAC-1.26
Download the package from here and extract the package into c:\msys\faac-1.26 and follow the instructions:
cd c:\msys\faac-1.26
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the faac-1.26 directory after installation.

14-)BZIP2
Download the package from here and extract the package into c:\msys\bzip2-1.0.5 and download the patch from here and save into c:\msys\bzip2-1.0.5 and follow the instructions:
cd c:\msys\bzip2-1.0.5
patch -p0 < bzip2-1.0.5-extensions.diff
make
make install PREFIX=/mingw
Delete the bzip2-1.0.5 directory after installation.

15-)LIBGSM-1.0.12
Download the package from here and extract the cabinet file components to the corresponding directories in c:\msys\mingw\

16-)LIBVORBIS-1.2.2
Download the package from http://www.xiph.org/downloads/ and extract the package into c:\msys\libvorbis-1.2.2 and follow the instructions:
cd c:\msys\libvorbis-1.2.2
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the libvorbis-1.2.2 directory after installation.

17-)NASM-2.06rc1(May be needed before installing one of the previous libraries-libmp3lame-)

Download the package from here and extract the package to c:\msys\nasm-2.06rc1 and follow the instructions:
cd c:\msys\nasm-2.06rc1
./configure --prefix=/mingw --enable-static –disable-shared
make
make install
Delete the nasm-2.06rc1 directory after installation.


PROBLEMS THAT CAN OCCUR WHILE COMPILATION/INSTALLATION

Note: The order of installation of the above libraries may be different but its most likely as above. If any other library or component is needed while installation of a library, just apply the required step there. The order may be different because it took me 3 days to compile and apply the configuration above :)

1-)Assembler Needed-If an error occurs like nasm or yasm is needed or not found, just apply the step #17 explained above.
2-)Error pr:Command not found- This can occur while configuration.Copy the pr.exe file in the bin directory of coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2 that you previously downloaded to c:\msys\bin.
3-)Schroedinger Not Found: This can poccur while configuration. Apply the steps 4-5-6-7 under

COMPILING FFMPEG WITH ADDITIONAL STATIC LIBRARIES in exact order.
ATTACHING FFMPEG TO FOBS_JMFSTUDIO MEDIA PLAYER

1-)Download FOBS
Download FOBS-0.4.2 from here both the source code and the binaries.

2-)Install Python
Download Python2.6.2 from http://www.python.org/ and install into c:\Python.

3-)Download SCONS
Download SCONS-local-1.2.0.d20090223 from http://www.scons.org/

4-)Unpacking
Unpack the FOBS under c:\msys\fobs.
Unpack SCONS-local-1.2.0.d20090223 into the c:\msys\fobs\scons-local\.
Unpack the FOBS\fobs-0.4.2\resources\current-ffmpeg.tar.bz2 into c:\msys\fobs\ffmpeg .

5-)FFMPEG Recompilation
-Run MSYS and follow the instructions:
$ cd /fobs/ffmpeg
$ ./configure --enable-memalign-hack --extra-cflags=-fno-common --enable-static --disable-shared
--disable-debug --enable-gpl --enable-nonfree --enable-avfilter --enable-avfilter-lavf --enable-avisynth
--enable-postproc --enable-libamr-nb --enable-libamr-wb --enable-libgsm --enable-libfaac --enablelibfaad
--enable-libmp3lame --enable-libschroedinger --enable-libtheora --enable-libvorbis --enablelibxvid
–prefix=/fobs/external
$ make
$ make install
$ cp libavformat/avi.h /fobs/external/include/libavformat/
$ cp libavformat/riff.h /fobs/external/include/libavformat/
$ mkdir /fobs/external/include/libswscale
$ cp libswscale/swscale.h /fobs/external/include/libswscale/swscale.h

6-)Environment Variables
Check whether the environment variables of Python and Java are existent in your system path. If not : Go to
MyComputer->Properties->Advanced->Environment Variables->System Variables->PATH and append the paths where your python and java JDK bin directory is. Mine is C:\Python; and C:\Program Files\Java\jdk1.6.0_13\bin;
RESTART THE COMPUTER AFTER APPLYING THE CHANGES

7-)Build Script
$ cd /fobs
$ ./buildFobs.sh FFMPEG_HOME=/fobs/external FOBS4JMF=yes

After the project has been built, the "fobs/dist" directory will contain the following:
dist/include, dist/lib : Static library with C++ API classes and header files needed to use Fobs in your C++ project dist/jmf/ : Dynamic library with JMF plugin and Jar with Java part of the implementation. dist/test/ : Some example applications to get help learning the Fobs API.
If you want to use the ffmpeg you've build with Fobs_jmstudio just copy
/fobs/jmf/fobs4jmf.dll,/fobs/jmf/fobs4jmf.jar,/fobs/jmf/jmf.jar and /fobs/jmf/jmf.properties into the folder where Fobs_jmstudio exists in the downloaded Fobs binaries folder and the media player is ready to use.

ERRORS THAT CAN OCCUR WHILE BUILDING FOBS
Value Error: too many values to unpack:
File “C:\msys\fobs\SConstruct”, line 29: …
Solution : Go to c:\msys\fobs\external\lib\pkgconfig and delete the entry “-Lc:\msys\fobs\external\lib” from the line Libs: -L${libdir} int the files libavcodec.pc,libacdevice.pc,libavfilter.pc and libavformat.pc
Errors in Decoder.cpp , Encoder.cpp and Transcoder.cpp
Note : Do these steps if errors including 'strcpy','memcpy','memset','abs','INT_MAX', etc occur.
Decoder.cpp -> Just add the following lines into the file where the #include lines are:
#include <string.h>
#include <cmath>
Change the following lines
if(isVideoPresent()) res = ::abs(t2-t1) <= 1000.0/getFrameRate();
else res = ::abs(t2-t1) <= 1000.0/getAudioSampleRate();
with
if(isVideoPresent()) res = ::abs((float)(t2-t1)) <= 1000.0/getFrameRate();
else res = ::abs((float)(t2-t1)) <= 1000.0/getAudioSampleRate();

Encoder.cpp ->Just add the following lines into the file where the #include lines are:
#include <string.h>
#include <limits.h>

Transcoder.cpp->Just add the following lines into the file where the #include lines are:
#include <string.h>
#include <stdlib.h>

Redefinition Errors->videohdr_tag,CAPTUREPARMS,WM_CAP_SET_CALLBACK_VIDEOSTREAM,WM_CAP_DRIVER_CONNECT,
WM_CAP_DRIVER_DISCONNECT ,WM_CAP_GET_VIDEOFORMAT, WM_CAP_SET_VIDEOFORMAT, WM_CAP_SET_PREVIEW, WM_CAP_SET_OVERLAY,WM_CAP_SEQUENCE_NOFILE,WM_CAP_SET_SEQUENCE_SETUP,WM_CAP_GET_SEQUENCE_SETUP,...
Solution->Open the file c:\msys\fobs\ffmpeg\libavdevice\vfwcap.c and make the followinf lines as comment lines.

//#define WM_CAP_SET_CALLBACK_VIDEOSTREAM (WM_CAP_START + 6)
//#define WM_CAP_DRIVER_CONNECT (WM_CAP_START + 10)
//#define WM_CAP_DRIVER_DISCONNECT (WM_CAP_START + 11)
//#define WM_CAP_GET_VIDEOFORMAT (WM_CAP_START + 44)
//#define WM_CAP_SET_VIDEOFORMAT (WM_CAP_START + 45)
//#define WM_CAP_SET_PREVIEW (WM_CAP_START + 50)
//#define WM_CAP_SET_OVERLAY (WM_CAP_START + 51)
//#define WM_CAP_SEQUENCE_NOFILE (WM_CAP_START + 63)
//#define WM_CAP_SET_SEQUENCE_SETUP (WM_CAP_START + 64)
//#define WM_CAP_GET_SEQUENCE_SETUP (WM_CAP_START + 65)
// typedef struct videohdr_tag {
// LPBYTE lpData;
// DWORD dwBufferLength;
// DWORD dwBytesUsed;
// DWORD dwTimeCaptured;
// DWORD dwUser;
// DWORD dwFlags;
// DWORD_PTR dwReserved[4];
// } VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;

// typedef struct {
// DWORD dwRequestMicroSecPerFrame;
// BOOL fMakeUserHitOKToCapture;
// UINT wPercentDropForError;
// BOOL fYield;
// DWORD dwIndexSize;
// UINT wChunkGranularity;
// BOOL fUsingDOSMemory;
// UINT wNumVideoRequested;
// BOOL fCaptureAudio;
// UINT wNumAudioRequested;
// UINT vKeyAbort;
// BOOL fAbortLeftMouse;
// BOOL fAbortRightMouse;
// BOOL fLimitEnabled;
// UINT wTimeLimit;
// BOOL fMCIControl;
// BOOL fStepMCIDevice;
// DWORD dwMCIStartTime;
// DWORD dwMCIStopTime;
// BOOL fStepCaptureAt2x;
// UINT wStepCaptureAverageFrames;
// DWORD dwAudioBufferSize;
// BOOL fDisableWriteCache;
// UINT AVStreamMaster;
// } CAPTUREPARMS;