Update (February 11, 2009): The work originally presented in this post evolved into the WinBuilds project, maintained by Andoni Morales and myself. For more information check out the wiki, where you can download the latest gstreamer installers for windows, as well as access the help forum and register to the mailing list.
One main limitation when trying to use the GSVideo library for processing on windows was the relatively difficult task of installing GStreamer on a windows machine. Besides, the latest “official” installation packages for windows haven’t been updated for some time, while GStreamer code has been making continuous progress during the last months.
So, this situation was the motivation to create an alternative, simplified and up-to-date GStreamer installation package for windows. In fact, there is already a project with this very same goal, called OABuild, developed by Ole André Ravnas. OABuild contains a suite of MS Visual C++ projects that allows to compile GStreamer, among other useful open source libraries and tools, using the Microsoft compiler.
One problem with the current version of OABuild is that it includes a stripped-down version of FFmpeg, in order to compile it with MSVC. FFmpeg is the underlying library in GStreamer that provides support for decoding tons of commonplace video formats. However, the FFmpeg included in OABuild only provides a few codecs and hence wasn’t very useful to incorporate in a general GStreamer installer.
The aim of the following sections is to show the main tasks I had to accomplish in order to create this installer, starting with the compilation of a fully functional FFmpeg distribution under windows. This is not a step-by-step tutorial, only the steps or “tricks” I considered central for success are mentioned, while other details are assumed to be known.
Anyways, for those who are not interesting in these little nasty details, here you have a link where you can download the binary installer, as well as an installer of the development files, in case you need to compile applications that use GStreamer:
Please note that this is an initial release intended mostly for testing and debugging. Please let me know of any issues you might find with it.
Compiling FFmpeg under windows
So, for the task of compiling the latest source of FFmpeg, the Microsoft compiler is not an option, since FFmpeg uses features of the C99 specification of the C language which are not recognized by MSVC. What I did was to use MinGW and MSYS in order to compile FFmpeg with gcc, the GNU C compiler.
There were lots of useful information on how to compile and use FFmpeg on windows machines on this FFmpeg Windows help page, specially in the wiki and forum sections. However, the wiki has been down for a couple of months. I was able to recover some data from the copies stored in the Google cache. The forum seems to be online again, though.
I set up a MinGW + MSYS development environment, but the latest stable release of MSYS (1.0.10) won’t work to compile FFmepg because of an incompatibility between FFmpeg and the version of make included with 1.0.10. Version 1.0.11 solves this issue, and can be downloaded from here as individual packages. I prepared an installer that contains all those files in a single package, you can grab it from here.
Once MinGW and MSYS are installed, you have to fix the msys.bat file that is inside the root MSYS folder. The steps to perform this fix according to the FFmpeg Windows help site (gotten from Google cache) are the following:
“Open C:\msys\msys.bat in a plain-text editor, such as notepad.exe.
If you plan on compiling your apps with MSVC++ (note: your apps, not FFmpeg), you will need .lib files to link against FFmpeg’s libraries.
Those .lib files can be generated by the lib command from the Microsoft’s Toolchain.
For that, you must have Microsoft Visual Studio, or Microsoft Visual C++.
Add the following line to the beggining of msys.bat, replacing the path leading to vcvars32.bat to wherever that file is located in your computer:
call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"
If you have Windows x64, you must add the following lines right after the :_WindowsNT label (line 36), or else the shell window will quickly open and close:
rem Hopefully a temporary workaround for getting MSYS shell to run on x64 rem (WoW64 cmd prompt sets PROCESSOR_ARCHITECTURE to x86) if not "x%PROCESSOR_ARCHITECTURE%" == "xAMD64" goto _NotX64 set COMSPEC=%WINDIR%\SysWOW64\cmd.exe %COMSPEC% /c %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 goto EOF :_NotX64 "
The next important “trick” is to update the gcc included in the latest stable MinGW (which should be 3.4.5) to 4.2 or higher, otherwise FFmpeg will give nasty errors about wrong compilation and not properly aligned stack variables… I have tried gcc 4.30-preview available on the sourceforge page of MinGW, but the resulting FFmpeg is also broken. Fortunately, a version of gcc 4.2.4 available at this website worked fine. I was able to successfully compile FFmpeg (from the svn source snapshot taken on 2008-09-04) with the following configure parameters:
--enable-shared --disable-static --enable-memalign-hack --enable-w32threads
You can download a zip file containing the resulting dlls, lib files and headers from here.
Integration of MinGW-generated FFmpeg and OABuild
Once I obtained the FFmpeg’s dlls, lib and headers files, I had to remove the FFmpeg that comes included with OABuild by default and to create new MSVC projects for the MinGW-generated FFmpeg. The idea is to integrate these changes into the OABuild mainline pretty soon.
Fixes to OABuild
I replaced the source code of gst-ffmpeg in OAbuild with the one from the latest stable release (0.10.5). This code needed some changes in order to compile from MSVC:
- Include <libavcodec/avcodec.h> and <libavformat/avformat.h> instead of <ffmpeg/avcodec.h> and <ffmpeg/avformat.h>
- In gstffmpegenc.c do: replace in_plugin = first_avcodec; by in_plugin = av_codec_next(NULL); and in_plugin = in_plugin->next; by in_plugin = av_codec_next(in_plugin);
- In gstffmpegdec.c, do: replace in_plugin = first_avcodec; by in_plugin = av_codec_next(NULL); and in_plugin = in_plugin->next; by in_plugin = av_codec_next(in_plugin);
- In gstffmpegdemux.c, do: replace in_plugin = first_iformat; by in_plugin = av_iformat_next(NULL); and in_plugin = in_plugin->next; by in_plugin = av_iformat_next(in_plugin);
- In gstffmpegmux.c, do: replace in_plugin = first_oformat; by in_plugin = av_oformat_next(NULL); and in_plugin = in_plugin->next;by in_plugin = av_oformat_next(in_plugin);
Also, the qtdemux element wasn’t included in OABuild. Without it is not possible to open quicktime mov files. Again, using the qtdemux code from the latest gst-plugins-good package, I created a project file inside OABuild. The following changes in code were needed in order to compile the pluign:
- In qtdemux_dump.h, change #include <qtdemux.h> with #include “qtdemux.h”
- Then remove gstrtpxqtdepay.c y gstrtpxqtdepay.h from project.
- Comment out the occurrence of gst_tag_freeform_string_to_utf8 in qtdemux.c and the following code: if (!gst_element_register (plugin, “rtpxqtdepay”, GST_RANK_MARGINAL, GST_TYPE_RTP_XQT_DEPAY)) return FALSE; in quicktime.c
Creating binaries with the ReleaseWdkCrt option
The binaries resulting from compiling with the Release option in OABuild won’t work unless the machine where they are installed also has the MSVC 2008 redistributable package installed on it. It is a small nag, but ideally the GStreamer installer shouldn’t need any aditional libraries in order to be it entirely self-contained. This is solved by using the ReleaseWdkCrt compiling option, which requires to use some CRT object files that come with the Windows Driver Kit (WDK). This is kind of a messy topic, and here it is explained in detail the logic of this workaround. The WDK can be downloaded after creating a free account on Microsoft Connect. Then, only the following files from the WDK (located in C:\WinDDK\6001.18002\inc\crt) have to be copied inside <OABuild root>\build\builddeps\wdkcrt.