Friday, September 23, 2011

Building a Visual Studio 2010 Project with FFmpeg/libavcodec

It's not supposed to be possible, right? Actually, it is, despite what the interwebs sometimes say. I just wanted to point out an excellent post which gives some great detail on building a Visual Studio project with libavcodec. I'm just going to point out a few things, because I did a few things differently.

Building the Project

To build the project, I almost exactly followed what's posted there on that other blog. The only real differences are:

For the custom build step, I simply did:

copy  "[Your_ffmpeg_directory]\bin\*.dll" $(OutDir)

There's two major differences here. First, notice it's OutDir and not OutputDir. The difference is significant, as OutputDir wasn't defined. The second, is the *, so that I didn't have to retype all those lines (laziness is a good thing... kinda).

That was pretty much it for building the project. Not to bad, eh?

Using FFmpeg/libavcodec

To learn the ropes, I used this tutorial. It's horribly out of date, but it helped a lot. One of the things that helped me is following the tutorial, and as I used functions and things, look at the FFmpeg headers to see the documentation for every function. The documentation is sometimes decent, but what's nice is that it'll tell you if something's been deprecated, and if so, what to use instead.

The trickiest function was avcodec_open2. The reason is because it asks for a AVDictionary** as the third parameter, but I couldn't find any real documentation on what that parameter should be. Honestly, I didn't care either. just wanted libavcodec to detect what to do and decode the dang video. After some experimenting, turns out that passing NULL is okay and libavcodec will auto-detect stuff.

And that's pretty much all there is to it! Lots of reading an outdated tutorial, googling, and reading the FFmpeg documentation (to try and use the current functions, rather than the deprecated ones).

A quick note on building FFmpeg/libavcodec with Visual Studio

If you've found this page wondering how to compile FFmpeg and libavcodec with Visual Studio, just realize that's not supported (Update: see the update below). FFmpeg and libavcodec should be compiled with gcc, and then those compiled libraries can be used in your Visual Studio project. This post is about using the binaries once they've been compiled with gcc. If you are wondering how to compile the libraries with gcc, there's lots of sites out there with instructions on how to do it. The main difficulty will be getting Unixy stuff to work on Windows for the compilation to work, but that's what Cygwin and all those other Unix environments are for.

As for why it's not possible to compile FFmpeg with Microsoft's VC: see this page. It's not a full listing, and the reason that page exists is for people to add to it so that FFmpeg can hopefully be made to be natively compilable with VC and Intel's C compiler.

Update! There's some talk about libav's c99-to-c89 which would allow one to convert the C99 code of FFmpeg to C89 (and then hopefully build with VC). It's still pretty new, but the source repository for it can be found here. I've never tried it, so if you try it out and successfully get it to work and VC to build FFmpeg/libav, leave a comment letting me know!

Double Update! As time has gone on, it looks like c99-to-c89 has matured and you can now build FFmpeg with Visual Studio (even statically). I'm going to give this a try some time (may take me awhile to get around to it) and if it works, I'll rewrite this entire post and focus on that.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.