Compiling FFmpeg with libx264 and libfdk_aac under Cygwin without Mingw32

After many days and nights – I have been through many battles. One battle involved my scratching of my head many times. This battle is me trying to build FFmpeg with Cygwin. A new post and about computer stuff? Yay!

If you just happen to stumble upon this mostly irrelevant post to the world, and you know absolutely nothing about programs and have no interest on these kind of things, you can opt out and stop reading right now, or better yet read some of my other post, as if there’s many worthwhile one, or just go outside and do some “real world” stuff instead of being in front of your computer lazily glazing your eyes with artificial radiation. What the feck is an artificial radiation anyway. If someone referred you to this page, like a search engine, then I’m fluttered.

Continuing with the topic. This is about making the latest source snapshot at least compile within Cygwin under Windows. If you didn’t know about Cygwin, it’s an excellent (at least for me) unix shell layer for Windows. This can entice you if you miss bashing (sorry) and you want to experience it under Windows or if you want to use practical UNIX tools under Windows.

The problem with Cygwin (a system always have a problem; it’s the charm of engineering) is because it’s practically an emulation of the Unix shell (even though technically it’s not an emulation; it’s more of an application layer, like Wine on Linux), and you are guaranteed to encounter a slew of problems here and there, especially if it pertains to libraries and dependencies.

You can think you can get away with the base installation of Cygwin and just compile those dependencies yourself, but you’ll just waste your time. Because of the low-levelness of these things, they are specially pre-built by the Cygwin team and are available over the repositories, and can be fetch by the setup program. So we will use the pre-built version of these little ones. However, some are missing on the repositories; most likely due to licensing issues. So to get around this, we can try to build it ourselves and cross your finger, or find a third-party repository. We will go on the harder route, and we’ll build them ourselves coz we’re masochists Fortunately, there’s one available. We will come to that later.

And you might have thought, what the ♥♥♥♥ is FFmpeg? FFmpeg is the most powerful, open-source command-line media factory for all your media handling needs. Hands down. You can use it to efficiently convert, repack, encode, re-encode, etc. almost all various image, video, and audio formats. It is the back-end that powers most powerful, often free, encoders, decoders, and players out in the wild, like MPlayer. Later versions also includes a player and a server, ffplayer and ffserver, respectively, but mainly it is used for repackaging and encoding purposes. We will only focus on the ffmpeg binary on this page.

For this guide, we will use another guide (so much for a guide). Head over to and read the specifications “Compilation under Cygwin”, or you can read them all and have an idea of how these things work across platforms, or just ignore the link and continue below (trust me, the above link is completely optional). It mutters these names:

binutils, gcc4-core, make, git, mingw-runtime, texinfo
bc, diffutils
libogg-devel, libvorbis-devel
yasm, libSDL-devel, libfaac-devel, libaacplus-devel, libgsm-devel, libmp3lame-devel,
libschroedinger1.0-devel, speex-devel, libtheora-devel, libxvidcore-devel

Install them through the Cygwin setup, together with the entire “Base” packages. gcc4-core is gcc-core. git will not be used but install it anyway (for the future). bc and diffutils are still important even if you don’t do FATE so get them anyway. mingw-runtime is required even though we will not use Mingw32 for building. The 4th row is the most important, but all of these are not available in the official repos (you know the reason). In order to get them, follow the guide there and use Cygport repositories. Make sure you get yasm and libtheora, as those others provides the codecs, albeit popular codecs, so you might get them as well. Since we will build libfdk_aac and libx264 ourselves, we can ignore libfaac, libaacplus, and libvorbis (they’re missing in the repositories anyway). You can also ignore libschroedinger, since we will ideally use x264 for h.264 codec.

Additionally, install the packages:

wget, unzip, texi2html, curl, dos2unix, autotools (autobuild, autoconf, automake, autotoolset, all versions, for insurance), pthreads, cygport

dos2unix is required for conversions of formatting characters (e.g. newline character) from dos unto Unix format. Make sure you get cygport, it provides the proper lib-utils to build under windows. Without it, all of your attempts to build will throw you an error. autotools is required for one particular build process. pthread is required to build ffmpeg with pthreads, as it’s supposed to provide multithreading support. You can build without one; in fact, it’s not required if you’ll only use x264 codings, as libx264 provides this functionality for itself.

After you managed to get and install those packages, we will use another guide, again. We will use You can read that entire page, or just ignore the link and open your Cygwin Terminal. For the purpose of uniformity, we will follow the guide (or you can just do some liberties in the process, as long as it sounds logically). On the terminal, run:

mkdir bin && mkdir ffmpeg_sources && mkdir ffmpeg_build

Those will setup the working directories. After that, copy and paste to terminal:

cd ~/ffmpeg_sources
tar xjvf last_x264.tar.bz2
cd x264-snapshot*
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
PATH="$HOME/bin:$PATH" make
make install
make distclean

Make sure to press enter on the last command. This will build libx264 for us. If all required packages were installed, the build process will be successful. You can find libx264.exe inside ~bin on your cygwin home folder.

This builds the 8-bit variant. If you happen to want to encode 10-bit videos, you have to use --bit-depth=10 argument when running configure. So thus the command:

./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --bit-depth=10

If you’ve come across --enable-win32thread, you’ll know the name is sweet but don’t ever use it!! (Not that you care.) You’ll lose multi-threading capability since we are not cross-compiling for windows; we are compiling for Cygwin.

All done with libx264, run:

cd ~/ffmpeg_sources
wget -O
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make install
make distclean

This will build libfdk_aac. The “F” stands for Fraugher, something like that (it was German, ha ha). Again, if all packages mentioned in this post were installed, this will build successfully. It doesn’t come with an executable binary so it doesn’t produce an output inside ~bin. Now, we will have a library that will enable us to encode High Efficiency Advanced Audio Codec (HE-AAC). Quality audio for lower bitrates. That’s German engineering for you. Yay!

Now, finally, the ffmpeg itself. Run:

cd ~/ffmpeg_sources
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --disable-ffplay \
  --disable-ffprobe \
  --disable-ffserver \
  --enable-gpl \
  --enable-libfdk-aac \
  --enable-libmp3lame \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libx264 \
  --enable-pthreads \
PATH="$HOME/bin:$PATH" make
make install
make distclean
hash -r

This is my configuration. Be ready for a loooong time of compilation. If you didn’t install libvorbis, you can remove its line. The same with other codecs that you didn’t install. We disabled ffplay, ffprobe and ffserver for this setup since we didn’t install some of their dependencies. If you want them, you can always head to the official FFmpeg documentations and wiki for more information on them and their dependencies.

Now, unless you find watching progress and numbers appearing entertaining (like me), that’s a boring compilation! You will find ffmpeg.exe inside ~bin. If you care about bits, we used x86 toolchains, so the binary is 32-bit. You’ll notice that it’s pretty big compared to other ffmpeg builds out there in the jungle, but don’t fret. It was built statically which means that included libraries are all packed in that one binary, and under Cygwin. It would be different if you built it using mingw32. But if you wanted to cross-compile it, you could have better compiled it under other sane platforms (like Linux), or better, under Windows (if you know to setup Visual Studios or Mingw32 for ffmpeg, that is).

But why Cygwin? Because sometimes these kinds of work and process are easier here, evident by this one post alone.

When you’re ready to use your newly built program, you can copy the binary unto anywhere and run it through cmd there or whatever method of applications you can use it with, or put it on a directory included with your SYSTEM PATH (e.g. WINDOWS\system32). You can even use it for scripting purposes (that’s part of FFmpeg’s charm, or any other cmd-line programs). Just remember that you need external Cygwin libraries either on the same folder or in the system path to run this little shiny, since you technically compiled it under/for a UNIX environment. Depending on what packages you included during configuration, these includes:


If you don’t want these extra dll’s lying around, you can always cross-compile it or natively compile it in Windows. That will be another story.

To know the command parameters, run ffmpeg -h.

Some example command:

ffmpeg -i "!filepath!" -c:v libx264 -preset:v veryslow -crf 27 -c:a libfdk_aac -profile:a aac_he_v2 -strict experimental -b:a 32k -movflags +faststart -vf "scale=-2:480" -r 24 "!outfile!"

“!filepath!” is your input file, while “!outfile!” would be your output file. For more information how to use ffmpeg, FFmpeg has an excellent documentation for all its flexibility and possible use.

Happy Compiling!


3 thoughts on “Compiling FFmpeg with libx264 and libfdk_aac under Cygwin without Mingw32

  1. Pingback: Resize/convert all images in a folder just by using batch script and FFmpeg | Koohiimaster

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s