Bohl's Blog

my digital life

building FFmpeg on Windows (7 of n)

Here are some new patches that should cure the problems with Debug-builds in VisualStudio. The changes (related to the Debug-build) are limited to the files ..\libavcodec\x86\mpegvideoenc_template.c, ..\libavcodec\x86\lpc.c, ..\libavcodec\x86\vc1dsp_mmx.c and ..\libpostproc\postprocess_template.c. And they are rather crude ones, just some quick'n'dirty hacks. But they should do the job.

 patches.diff (147.85 kb)

building FFmpeg on Windows (6 of n)

Now that the configure/make-build of FFmpeg is working satisfactorily, it is time to turn to VisualStudio. We will create a VisualStudio-project from the results of the configure/make-build.

The approach I took is somewhat like: we run a configure/make-build which will create the config.h & config.asm files, a makefile and the dependencies. Then we use that information in order to create a VisualStudio-project-file (vcxproj) with the help of a little tool.

After configure has run, we run make with an option telling it to just print the commands it would normally execute:

make --dry-run > makelog.txt

The file "makelog.txt" now contains all compiler invocations, which we just need to parse and turn into a VisualStudio-project. Here is a little tool I put together for this job. I'll need to give it some more polish before releasing the source, so for now just the binary:

MakeVSProject.zip (23.59 kb)

Run this program with the following commandline:

MakeVSProject.exe --projname=vsFFmpeg -m makelog.txt

This will create two new files vsFFmpeg.vcxproj and vsFFmpeg.vcxproj.filters. Open the project with VisualStudio and it should look like this: 

Now, we are almost there, just some more tweaks are required. First of all, the VisualStudio-project includes both x86- and x64-platform, but configure has created config.h & config.asm tailored for just one platform. So we need to add some #ifdef's to these files - that's what the commands below will do:

sed 's/%define ARCH_X86_32 [0-1]//' < config.asm | sed 's/%define ARCH_X86_64 [0-1]//' > config.asm_out
sed 's/%define HAVE_ALIGNED_STACK [0-1]/%if ARCH_X86_32 == 1\n %define HAVE_ALIGNED_STACK 0\n%elif ARCH_X86_64 == 1\n %define HAVE_ALIGNED_STACK 1\n%endif/' < config.asm_out > config.asm
rm config.asm_out

sed 's/#define ARCH_X86_32 [0-1]/#if defined( _M_X64)\n #define ARCH_X86_32 0\n#elif defined( _M_IX86)\n #define ARCH_X86_32 1\n#endif\n/' < config.h | sed 's/#define ARCH_X86_64 [0-1]/#if defined( _M_X64)\n #define ARCH_X86_64 1\n#elif defined( _M_IX86)\n #define ARCH_X86_64 0\n#endif\n/' > config.h_out
sed 's/#define HAVE_ALIGNED_STACK [0-1]/#if defined( _M_X64)\n #define HAVE_ALIGNED_STACK 1\n#elif defined( _M_IX86)\n #define HAVE_ALIGNED_STACK 0\n#endif\n/' < config.h_out > config.h
rm config.h_out

Now the x86- and x64-Release builds should work right out of the box. There are still problems with the x64-Debug and x86-Debug build. With the former one you will get

 

and with the latter something like

 

I will have some more patches for this in the next post.

Of course, the VisualStudio-project still leaves some things to be desired. Foremost, it only includes the files which are producing an object file, headers and files that are only included are missing. I'd think it should be easy to parse the dependency-files (".d") in order to get them. Watch out for an update - again in a later post.

building ffmpeg on Windows (4 of n)

This is an update to the previous post - I made the patches work with an x64-build and the tweaked some more files so that FFmpeg now builds fine with these configure-script:

./configure --enable-inline-asm --enable-gpl --enable-nonfree --disable-doc --toolchain=cygicl --host-cc=gcc --arch=x86_32

or

./configure --enable-inline-asm --enable-gpl --enable-nonfree --disable-doc --toolchain=cygicl --host-cc=gcc --arch=x86_64

And of course it passes all FATE-tests.

What you need are these patches

 patches.diff (135.82 kb)

Then fire up a Cygwin-command-prompt with either the x86-ICL or the x64-ICL on the path. In order to use the x64-ICL, just change the batch-file (from the previous post) to

call C:\Progra~2\Intel\Compos~1\bin\ipsxe-comp-vars.bat intel64 vs2012

In order to check which icl you are using, just type 'icl' - if you get this, then it is the x64-version:

The x86-compiler instead gives:

 

Let's start with a fresh check-out of ffmpeg, then you would have to enter something like:

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

cd ffmpeg

patch -p1 < ../patches.diff

./configure --enable-inline-asm --enable-gpl --enable-nonfree --disable-doc --toolchain=cygicl --host-cc=gcc --arch=x86_64

The above line with "configure" will build the x64-version, for the x86-build you need to enter --arch=x86_32.

Don't forget to have the two scripts iclwrap.sh and tweakpaths.sh in place (e.g. at /usr/local/bin). Just in case, here they are again (I'd think they should be unchanged from the previous post):

tweakpaths.sh (1.30 kb)

iclwrap.sh (1.54 kb)

I tested with ffmpeg as of version 6c4516d0413ea9b2a9b48fb83d0ba0ef7bc84f92.

building ffmpeg on Windows (3 of n)

In this post we will build FFmpeg with the Intel-compiler ICL - with the usual configure-/make-scripts. First of all we need a Cygwin-shell with the Intel-compiler on the path. It is easiest to call the batch-file "ipsxe-comp-vars.bat" which is installed with the Intel-compiler. So we put together a simple batch-file something like this:

@echo off
call C:\Progra~2\Intel\Compos~1\bin\ipsxe-comp-vars.bat ia32 vs2012
chdir /D d:\cygwin\bin
start .\mintty.exe -

Of course you have to substitute your respective paths. Now, when you launch the Cygwin-shell it should look like this:

Let me say beforehand: I tested the following steps with the FFmpeg-sources as of 06/02/2013. The corresponding git-commit-ID is 582f36ca3fb1c69dbe3478f174d36278f5dd3f63. So, if something goes wrong it might because of changes in the FFmpeg-repository. In order to be sure that you get this specific version you need to run this command after downloading the most recent FFmpeg-repository:

git checkout 582f36ca3fb1c69dbe3478f174d36278f5dd3f63

Now, first of all, we need to get the FFmpeg-sources:

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

Now download the two patches below:

cygicl.diff (31.31 kb) 

inlineassembly.diff (60.75 kb)

The first patch modifies the configure - script, adds some files and applies minimal modifications so that FFmpeg compiles without inline-assembly. The second patch contains more extensive changes to the FFmpeg-code in order to make the inline-assembly work with icl.

I will elaborate on the changes in a latter post, in this post I will just list the steps how to make it compile. Change into the ffmpeg-folder and apply both patches:

patch -p1 < ../cygicl.diff
patch -p1 < ../inlineassembly.diff

Now we still need two more scripts - the first one is a little wrapper for the icl-compiler, and the second is required for executing the FATE-test-suite successfully.

 iclwrap.sh (1.53 kb)

 tweakpaths.sh (1.30 kb)

Place them to somewhere on the (Cygwin-) path - e.g. /usr/local/bin.

We can now run the configure-script:

./configure --enable-inline-asm --disable-doc --toolchain=cygicl --host-cc=gcc

If you chose to not apply the inlineassembly.diff-patch, then you need to specify --disable-inline-asm. This will take a while and should finish without any errors.

Then we are ready to fire up make - which can be speeded up by allowing it to run multiple compiler-processes concurrently. Something like this might be a good choice:

make -j "$(grep -c processor /proc/cpuinfo)"

Again, this should finish without errors.

Finally, we can run FATE with this command:

make  TARGET_EXEC=tweakpaths.sh fate SAMPLES=PATH_TO_FATE_SUITE_SAMPLES  -j "$(grep -c processor /proc/cpuinfo)"

Don't forget to give the correct path (where you have place the fate-samples) instead of PATH_TO_FATE_SUITE_SAMPLES.

At least for me (with the latest icl, version 13.1.2.190 build 20130514) all fate-tests pass.