Build shared library of ffmpeg with x264 to use in visual studio win32 project
After few painful failure attempts at last i was able to build shared library which can be used in visual studio win32 project. Here is the process which i have gone through. Hope this will be helpful. I don't want any body to face the same failure moments..
Next Part generally is not needed
To create import libraries that work with the
Environment settings
- Download msys2 32 bit form this link http://msys2.github.io and install it.(in my case installed "msys2-i686-20160205.exe" in directory is "c:\msys32").
- Run it and run below commands
-
update-core (Update the system packages with)
close MSYS2, run it again and run below commands - pacman -Sy
- pacman -Su (sometimes this command creates error then you have uninstall msys2 and install again. In that case you can ignore this command)
- pacman -S pkg-config make diffutils
-
update-core (Update the system packages with)
- go to C:\msys32\usr\bin and rename "link.exe" to "link_backup.exe". Because we will not use this link. we will use visual studio link.
- Download yasm win32 ".exe" version from http://yasm.tortall.net/Download.html
(in my case file name was "yasm-1.3.0-win32.exe")after downloading exe file rename it as "yasm.exe" and place it or replace if already exists in "C:\msys32\usr\bin" directory.
Checking:
Open visual studio Developer Command Prompt for VS2013 or VS2013 x86 Native Tools Command Prompt(2nd one is preferable).
Generally the tool path is like below
" C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts "
Then- run c:\msys32\mingw32_shell.bat
- Run below commands and check the output
- command: which cl
output: /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/cl - command: which link
output: /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/link - command: which lib
output: /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/lib - command: which yasm
output: /usr/bin/yasm
- command: which cl
Steps to build x264
- Use visual studio 2013 update 2 or later.(This supports CC=cl compiler).
- Download source code of latest x264 from this website.
http://www.videolan.org/developers/x264.html - Extract the files in a directory (in my case " c:\codecsBuild\x264 ").
- Open visual studio Developer Command Prompt for VS2013 or VS2013 x86 Native Tools Command Prompt(2nd one is preferable).
Generally the tool path is like below
" C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts " - Run
c:\msys32\mingw32_shell.bat
this will open new command line interface. - Now go to the directory where you have extracted x264 using command line. In my case command is
cd /c/codecsBuild/x264 - Now run below command to create x264 shared library.
CC=cl ./configure --disable-cli --disable-asm --enable-shared --enable-pic --prefix=../Codecs --extra-cflags="-DNO_PREFIX"- Options are optional. To see the options you can run "./configure --help".
- To create static library use "--enable-static" instead instead of "--enable-shared".
- "--enable-pic" means build position-independent code.
"--prefix" means the path where built codec will be created. (in my case the path is "../Codecs" equivalent to "c:\codecsBuild\Codecs")
- Now run
make
Build will start. - Now run
make install.
- "bin" folder contains "libx264-<version>.dll" (in my case it was "libx264-148.dll")
- "include" folder contains "x264.h" and "x264_config.h"
- "lib" folder contains "pkconfig" folder and "libx264.dll.lib" . Rename it with "libx264.lib"
Steps to build ffmpeg with/without x264
- If you want to build ffmpeg with x264 then you have to build x264 first (discussed earlier). Otherwise follow below steps..
- Download source code of latest ffmpeg from this website. http://ffmpeg.org/download.html
- Extract the files in a directory (in my case " c:\codecsBuild\ffmpeg ").
- Open visual studio Developer Command Prompt for VS2013 or VS2013 x86 Native Tools Command Prompt(2nd one is preferable).
Generally the tool path is like below
" C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts " - Run
c:\msys32\mingw32_shell.bat
this will open new command line interface. - Now go to the directory where you have extracted ffmpeg using command line. In my case command is
cd /c/codecsBuild/ffmpeg - Now run below command to create ffmpeg shared library with x264.
./configure --toolchain=msvc --target-os=win32 --arch=x86 --enable-gpl --prefix=../Codecs --disable-asm --enable-shared --disable-static --disable-stripping --disable-everything --disable-doc --disable-ffplay --disable-ffserver --enable-ffmpeg --disable-programs --disable-ffprobe --enable-libx264 --enable-encoder=libx264 --enable-decoder=h264 --enable-encoder=h263 --enable-decoder=h263 --enable-hwaccels --enable-avfilter --disable-devices --disable-avdevice --disable-swresample --disable-postproc --extra-cflags="-I../Codecs/include -fPIC -DNO_PREFIX" --extra-ldflags="-LIBPATH:../Codecs/lib"- Options are optional. To see the options you can run "./configure --help".
- To create static library use "--enable-static --disable-shared" instead instead of "--enable-shared --disable-static".
- "-fpic" means build position-independent code.
"--prefix" means the path where built codec will be created. (in my case the path is "../Codecs" equivalent to "c:\codecsBuild\Codecs") - -I../Codecs/include is used in --extra-cflags to show the compiler the path of the header files of x264 which is located in "../Codecs/include" directory.
- -LIBPATH:../Codecs/lib is used in --extra-ldflags to show the compiler the path of the libx264.lib file which is located in "../Codecs/lib" directory.
N.B.: if you search online, you will find --extra-ldflags="-L<path>". Which will work for gcc compiler. But for visual studio compiler you have to use --extra-ldflags="-LIBPATH:<path>" and use --toolchain=msvc (micro soft visual-studio compiler)
- If you want to build only ffmpeg without x264 then
- remove --enable-libx264 --enable-encoder=libx264 --enable-decoder=h264 from command.
- replace --extra-cflags="-I../Codecs/include -fPIC -DNO_PREFIX" with
--extra-cflags="-fPIC -DNO_PREFIX" - remove --extra-ldflags="-LIBPATH:../Codecs/lib"
- Now run
make
Build will start. - Now run
make install.
- "bin" folder contains all the dll and lib files.
- "include" folder contains all header files.
- "lib" folder contains "pkconfig" folder and other def files.
-----------The END. This is it.. So simple.. Keep smiling..--------
Next Part generally is not needed
To create import libraries that work with the
/OPT:REF
option
(which is enabled by default in Release mode), follow these steps:
- Open the Visual Studio Command Prompt.
- Enter the c:\codecsBuild\Codecs\bin directory where the created LIB and DLL files are stored.
- Generate new import libraries with using this command.
lib /machine:i386 /def:..\lib\<lib name>-<version>.def /out:<lib name>.lib
i have get error
ReplyDelete$ make
cat: config.h: No such file or directory
./configure
No working C compiler found.
Makefile:3: config.mak: No such file or directory
make: *** [Makefile:236: config.mak] Error 1