The project: make a basic video player using WPF and the very awesome libavcodec.
The point of this blog: document my findings as I go. Using libavcodec on Windows, especially using MSVC++, is not very well supported nor documented, so this should be useful to some.
The first step will be to learn how to use libavcodec within MSVC++. Then we can eventually figure out how to use it from C#.
In this installment we'll simply get the required files and make sure we can compile and run a "hello world" libavcodec program. I'm using Visual Studio 2010 but this should also work for 2005 and 2008, in theory.
1. Binaries and headers
The first thing you need is the latest 32-bit "Shared" and "Dev" builds fromHawkEye's FFmpeg Windows Builds (Update: now moved to Zeranoe FFmpeg builds. I have not tested them.). 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.
Now configure your project to use the libs, headers and dlls. For the includes, you need to add:
2. Inttypes.h
Even just using libavcodec's headers requires inttypes.h, and MSVC doesn't have it. Grab this version and put in your "Microsoft Visual Studio 10.0\VC\include" folder. Easy peasy (lemon squeezy).
3. The code
Since libavcodec is a C library, we have to enclose the #includes in an extern C block, like so:
If the above procedure doesn't work for you, please be very specific in your problem description and I can update the post with more accurate information.
Some good resources:
An ffmpeg and SDL Tutorial
FFMpeg official site
The point of this blog: document my findings as I go. Using libavcodec on Windows, especially using MSVC++, is not very well supported nor documented, so this should be useful to some.
The first step will be to learn how to use libavcodec within MSVC++. Then we can eventually figure out how to use it from C#.
In this installment we'll simply get the required files and make sure we can compile and run a "hello world" libavcodec program. I'm using Visual Studio 2010 but this should also work for 2005 and 2008, in theory.
1. Binaries and headers
The first thing you need is the latest 32-bit "Shared" and "Dev" builds from
Now configure your project to use the libs, headers and dlls. For the includes, you need to add:
[Your_ffmpeg_directory]\include [Your_ffmpeg_directory]\include\libswscale [Your_ffmpeg_directory]\include\libavutil [Your_ffmpeg_directory]\include\libavformat [Your_ffmpeg_directory]\include\libavdevice [Your_ffmpeg_directory]\include\libavcodecAdd the corresponding libs under linker options as usual. For the dlls, I use a custom build step to copy them to my project directory:
Command Line: copy "[Your_ffmpeg_directory]\bin\avcodec-52.dll" $(OutputDir) copy "[Your_ffmpeg_directory]\bin\avfilter-1.dll" $(OutputDir) copy "[Your_ffmpeg_directory]\bin\avformat-52.dll" $(OutputDir) copy "[Your_ffmpeg_directory]\bin\avutil-50.dll" $(OutputDir) copy "[Your_ffmpeg_directory]\bin\avdevice-52.dll" $(OutputDir) copy "[Your_ffmpeg_directory]\bin\swscale-0.dll" $(OutputDir) Outputs: avcodec-52.dll;avdevice-52.dll;avfilter-1.dll;avformat-52.dll;avutil-50.dll;swscale-0.dllNote that's it's possible to compile FFMpeg (which contains libavcodec) on Windows, but not with MSVC (Code::Blocks with MinGW should do the trick, but I haven't tried). It depends on about 18 different libraries so have fun with that, I'll use the pre-compiled binaries thank you.
2. Inttypes.h
Even just using libavcodec's headers requires inttypes.h, and MSVC doesn't have it. Grab this version and put in your "Microsoft Visual Studio 10.0\VC\include" folder. Easy peasy (lemon squeezy).
3. The code
Since libavcodec is a C library, we have to enclose the #includes in an extern C block, like so:
extern "C" {
#include <avcodec.h>
#include <avformat.h>
#include <swscale.h>
}
Next we'll call one function to verify that the dlls are working:int main( int argc, char* argv[] ) {
av_register_all();
}
Compile and run. If the program exits normally, you should be set. Weee!If the above procedure doesn't work for you, please be very specific in your problem description and I can update the post with more accurate information.
Some good resources:
An ffmpeg and SDL Tutorial
FFMpeg official site






#define __STDC_CONSTANT_MACROS
otherwise it won't compile.
Moreover I added also stdint.h to the VC/include folder