Bohl's Blog

my digital life

building FFmpeg on Windows (9 of n)

The story continues - some of the recent changes

  • I changed how asm-files are handled. Instead of relying on VSYASM we now use a simple custom-build step.
  • The VS-project now can include x264 and zLib.
  • Some fixes and tweaks.

You now need to have yasm.exe somewhere on the path. If you download it (e.g. from here) make sure that you rename to executable to "yasm.exe". As far as my understanding goes, it does not matter whether you use the x86- or x64-version. Both of them can compile x86- and x64-code it seems. A good place could be "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin" (which is "on the path" for x86-builds) and "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64" (for x64-builds). I am using a hard link (mklink /H "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64\yasm.exe" "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\yasm.exe") which saves a few bytes.

 

I am listing the complete set of steps how to build FFmpeg and create the VisualStudio-project:

First we run this script (iclbuild.sh) - which will get the git-repository, build it (with the Intel-compiler) and finally run FATE:

#/bin/sh

if (icl.exe 2>&1 | grep -q "IA-32"); then
    arch="x86_32"
elif (icl.exe 2>&1 | grep -q " Intel(R) 64"); then
    arch="x86_64"
else
    echo "Could not determine whether to use x86_32 or x86_64."
	exit 1
fi

echo "Building for architecture '$arch'"

git clone https://github.com/ptahmose/FFmpeg.git

cd FFmpeg

git checkout cygicl

# need to add the current path so that "iclwrap.sh" is found
PATH=$PATH:$(pwd)
export PATH
./configure --enable-inline-asm --enable-gpl --enable-nonfree --disable-doc --toolchain=cygicl --host-cc=gcc --arch=$arch

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

make --dry-run  --always-make > makelog.txt

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

make  TARGET_EXEC=tweakpaths.sh fate SAMPLES=/cygdrive/z/home/jbohl/fate-suite/  -j "$(grep -c processor /proc/cpuinfo)"

This script (preparex264.sh) will download x264 and apply some tweaks to it (the file x264patches.diff is to be found in the zip-file, see below):

#/bin/sh

cd FFmpeg
if [ ! -d external ]; then
 mkdir external
fi
cd external
git clone git://git.videolan.org/x264.git

cd x264
patch -p1 < ../../../x264patches.diff

cat > x264_config.h <<EOF
#define X264_BIT_DEPTH     8
#define X264_GPL           1
#define X264_INTERLACED    1
#define X264_CHROMA_FORMAT 0
EOF

./version.sh >> x264_config.h

cat > config.h <<EOF
#define HAVE_MMX 1
#if defined(_M_X64)
 #define HAVE_32B_STACK_ALIGNMENT 1
 #define ARCH_X86_64 1
 #define ARCH_X86_32 0
 #define ARCH_X86 0
#elif defined(_M_IX86)
 #define HAVE_32B_STACK_ALIGNMENT 0
 #define ARCH_X86_64 0
 #define ARCH_X86_32 1
 #define ARCH_X86 1
#endif
#define SYS_WINDOWS 1
#define HAVE_POSIXTHREAD 0
#define HAVE_THREAD 1
#define HAVE_LOG2F 1
#define HAVE_AVS 1
#define USE_AVXSYNTH 0
#define HAVE_VECTOREXT 0
#define fseek _fseeki64
#define ftell _ftelli64
#define HAVE_GPL 1
#define HAVE_INTERLACED 1
#define HAVE_OPENCL 0
#define HAVE_MALLOC_H 0
#define HAVE_ALTIVEC 0
#define HAVE_ALTIVEC_H 0
#define HAVE_ARMV6 0
#define HAVE_ARMV6T2 0
#define HAVE_NEON 0
#define HAVE_BEOSTHREAD 0
#define HAVE_WIN32THREAD 1
#define HAVE_VISUALIZE 0
#define HAVE_SWSCALE 0
#define HAVE_LAVF 0
#define HAVE_FFMS 0
#define HAVE_GPAC 0
#define HAVE_GF_MALLOC 0
#define HAVE_CPU_COUNT 0
EOF


# patch ffmpeg's "config.h" in order to include libx264
cd ../..
sed -i -e 's/#define CONFIG_LIBX264_ENCODER 0/#define CONFIG_LIBX264_ENCODER 1/' config.h
sed -i -e 's/#define CONFIG_LIBX264RGB_ENCODER 0/#define CONFIG_LIBX264RGB_ENCODER 1/' config.h
sed -i -e 's/#define CONFIG_LIBX264 0/#define CONFIG_LIBX264 1/' config.h

And finally, this script (preparezlib.sh) will do the same for zLib.

#/bin/sh

cd FFmpeg
if [ ! -d external ]; then
 mkdir external
fi

cd external

wget http://zlib.net/zlib-1.2.8.tar.gz
tar xzfv zlib-1.2.8.tar.gz
mv zlib-1.2.8 zlib
rm zlib-1.2.8.tar.gz

cd zlib

sed -i -e 's/#ifdef Z_PREFIX/#if 1/' zconf.h
sed -i -e 's/#ifdef HAVE_UNISTD_H/#if 0/' zconf.h
sed -i -e 's/#  define snprintf _snprintf/#ifndef snprintf\n#  define snprintf _snprintf\n#endif/' gzguts.h

cd ../..

sed -i -e 's/#define CONFIG_ZLIB 0/#define CONFIG_ZLIB 1/' config.h
sed -i -e 's/#define CONFIG_ZLIB_DECODER 0/#define CONFIG_ZLIB_DECODER 1/' config.h
sed -i -e 's/#define CONFIG_ZLIB_ENCODER 0/#define CONFIG_ZLIB_ENCODER 1/' config.h



wget -O MakeVSProject4FFmpeg.exe 'http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=makevsproject4ffmpeg&DownloadId=704486&FileTime=130182781120570000&Build=20602'
chmod +x MakeVSProject4FFmpeg.exe
./MakeVSProject4FFmpeg.exe --projname vsFFmpeg --makefileoutput makelog.txt --parse_includes --libx264 --libzlib

That's it - all files are to be found in this zip-archive (also including the diff for x264):

 vsFFmpeg_scripts.zip (2.76 kb)

So, given that everything is set up correctly (see previous posts for how to install Cygwin etc.), all you have to do is to extract this zip-file into an empty folder (don't forget to edit the path for the FATE-samples in iclbuild.sh or remove that line), then run

./iclbuild.sh ; ./preparex264.sh ; ./preparezlib.sh

and after some time you should find the VS-Studio-project 'vsFFmpeg.vcxproj' (in the FFmpeg-folder) which you can open with VisualStudio2012 and which should build (for all targets) without errors.

If you run into trouble or have any questions, comments or rants - please feel free to post your question here.

Kommentar schreiben

Loading