wiki:

CompilationGuide

/

MSVC


Version 7 (modified by hahaha1234, 4 years ago) (diff)

--

It's fairly simple to build ffmpeg on Windows with Visual Studio. The official guide is quite clear, but a little bit out-of-date.

FFmpeg can be built with MSVC 2012 or earlier using a C99-to-C89 conversion utility and wrapper, or with MSVC 2013 natively.

You will need the following prerequisites:

First, you need to unzip and copy the prerequisites into a folder, for example, c:\c99.

Then, you need to add the folder c:\c99 into your PATH environment variable.

Rename the yasm executable you will use to yasm.exe.

Finally, create an INCLUDE environment variable, and point it to c:\99; this is the location where the compiler will find inttypes.h.

Note: If it complains of MSVCR100.dll not found when running yasm, install the Microsoft 2010 VC redistributable.

To set up a proper environment in MSYS, you need to run msys.bat from the Visual Studio or Intel Compiler command prompt.

Next, make sure any other headers and libs you want to use, such as zlib, are located in a location that the compiler can see. Do so by modifying the LIB and INCLUDE environment variables to include the Windows-style paths to these directories. Alternatively, you can try and use the --extra-cflags/--extra-ldflags configure options.

Finally, run: For MSVC:

./configure --toolchain=msvc
make
make install

or the following:

./configure --enable-asm --enable-yasm --arch=i386 --disable-ffserver --disable-avdevice --disable-swscale --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --disable-zlib --prefix=/c/ffmpeg --toolchain=msvc

--enable-shared will generate the dynamic linked lib (dlls)

Note: You might see an error saying cl can't generate executable; this is because you installed the link.exe from MSYS. It conflicts with the link.exe of Visual Studio.

cl is unable to create an executable file.
If cl is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

You can try which link.exe to verify if it is the case. If you see /bin/link.exe, then you can simply rm /bin/link.exe. For more info see #3203 Windows MSVC configure failed.

The right link.exe should come from this location:

/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/BIN/link.exe

You might see two problems when building ffmpeg:

  1. pr command not found:

A solution is posted at MSYS pr not found. Basically, pr.exe is removed from MSYS. You need to download it and copy pr.exe to the msys/bin folder.

  1. The compiler might complain about redefinition issues of stdint.h, because both msinttypes and Visual Studio have stdint.h. I removed stdint.h from c:\c99 to let the compiler uses the one provided by Visual Studio.

In the end of configuration, you might also see pkg-config not found issue. That won't affect compilation, you can ignore it. It is said that installing pkg-config to MSYS is kinda tiresome.

How to build debug version?

An example:

$ ./configure --enable-asm --enable-yasm --disable-ffserver --disable-avdevice --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --disable-zlib --prefix=/c/ffmpeg --toolchain=msvc --arch=amd64 --extra-cflags="-MDd" --extra-ldflags="/NODEFAULTLIB:libcmt" --enable-debug

In case you need to build 64bit:

you need to run this command to trigger the 64bit compiler (setting --arch=amd64 --target-os=win64 won't build 64bit ffmpeg):

vcvarsall amd64

details: https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx