Using FFmpeg under Windows Visual C++ Environment
Contents
Using FFmpeg under Windows, especially using Visual C++, is not very well supported or documented. Today I tried this and mark this down for reference.
1. Download pre-compiled builds or compile from source
The first thing is to download the latest “Shared” and “Dev” builds from Zeranoe FFmpeg builds.
At the time of this writing, the “Dev” builds contain the headers and libs, but not the dlls, so use the “bin” folder of the “Shared” zip.
Note it’s possible to compile FFmpeg (which contains libavcodec) on Windows with MinGW & MSYS, but not with Visual Studio. If you are interesting about compiling FFmpeg on Windows, please check this post.
2. Using libavcodec in Visual Studio
Now configure your project to use the libs, headers and dlls. For the includes, you need to add:
[ffmpeg_directory]\include
Add the corresponding libs under linker options as usual.
[Your_ffmpeg_directory]\lib
3. add missing inttypes.h & stdint.h header file
Even just using libavcodec’s headers requires inttypes.h & stdint.h, and Visual Studio 9/10 doesn’t have it. Download this version and put in your FFmpeg include folder.
[ffmpeg_directory]\include
The most important thing is to add __STDC_CONSTANT_MACROS to Preprocessor, or add following code directly in source file:
#define __STDC_CONSTANT_MACROS
4. Test Code
Since libavcodec is a C library, we have to enclose the #includes in an extern C block. If following code works OK, then you can write more complicated application.
extern “C” { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h> }
int main( int argc, char* argv[] ) { av_register_all(); return 0; }
If you want to try more examples, there are a few examples under folder:
[ffmpeg_directory]\doc\examples
It is not complex but just steps!
Author Watterry
LastMod 2013-03-07