Posted on 07-03-2013
Filed Under (Technology) by bigbang

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!

© 2013, The Big Bang on Reading Busy. All rights reserved.
On republishing this post you must provide link to the original post.

Comments

Ascanius on 12 August, 2013 at 1:03 am #

Hey, done all the steps but get an error while compiling. Get the error “1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol “_av_register_all” in Funktion “_main”.
1>c:\users\a\documents\visual studio 2010\Projects\teststreaming\Debug\teststreaming.exe : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.”
What could be the error I done?
Greetz Asc

[Reply]

bigbang Reply:

I can’t read your language. Have you link the libraries?

[Reply]


kiet.heros on 27 August, 2013 at 8:43 pm #

I have set
Additional Include Directories ( dev/include)and Additional Dependencies (dev/lib)in project properties.
I did everything as you did, but when I compiled your code, still got error:
error LNK2019: unresolved external symbol _avcodec_register_all referenced in function _wmain

[Reply]

bigbang Reply:

Have you add the libraries to your solution?

[Reply]


Post a Comment
Name:
Email:
Website:
Comments: