FFmpeg
From DesigningPatterns
Contents |
Description
FFmpeg is an open-source, cross-platform audio/video encoding/decoding Swiss Army Knife. Its raison d'etre is to convert media files between different formats. It can be used both from the command-line (on UNIX, Windows, etc.) and linked into programs as a library.
Unusually, the FFmpeg project releases very sporadically and does not provide binaries. Binaries for Linux usually can be obtained through distribution package management systems (i.e. yum). FFmpeg binaries can be obtained for Windows here; note that this site takes pains to specify which are built from more stable snapshots of FFmpeg's source tree.
Building from Source
If support for an additional codec (i.e., AAC) is required, then FFmpeg will need to be built from source with the proper encoder/decoder. For instance, FFmpeg must be built with FAAC in order to encode AAC files. The below instructions all assume a standard UNIX environment with GNU Make (most (all?) Linux distributions are like this by default). MingW provides an acceptable environment for building FFmpeg on Windows.
Building FAAC
Read the official instructions (especially if building with MingW, as a special flag needs to be passed to the bootstrap script). Download FAAC's source from here. Unpack it, bootstrap, ./configure, and make. The libfaac/.libs subdirectory of the FAAC distribution now should contain libfaac.a. If you want FFmpeg to link statically against FAAC (so that you won't have to worry about having the proper shared object around), then either delete libfaac.so or move libfaac.a to another directory. Currently, at least one of FAAC's header files needs a bit of modification in order to build under MingW (comment out the typedef for ssize_t, the inline definition of snprintf, the printf macro, and the fprintf macro from common/mp4v2/mpeg4ip_win32.h; also, alter the TO_I64 and TO_U64 macros in that header file to be ANSI standard).
Building FFmpeg
First,
./configure --logfile=build.log --extra-cflags="-I../faac/faac-1.28/include/" --extra-ldflags="-L../faac/faac-1.28/libfaac/.libs/" --enable-libfaac
Note the following elements:
- --logfile=build.log
- Have all configure commands written to a log file, so that when something goes wrong the problem will be clear.
- --extra-cflags="-I../faac/faac-1.28/include/"
- Include FAAC's headers when compiling FFmpeg
- --extra-ldflags="-L../faac/faac-1.28/libfaac/.libs/"
- Tell FFmpeg where to find libfaac.a
- --enable-libfaac
- Build FFmpeg with FAAC.
Next,
make
If make finishes successfully, then there should be an ffmpeg executable at the root of the FFmpeg distribution. You can use ldd on it (assuming that you're building on UNIX) in order to ensure that its .so requirements are acceptable.
Issues
I had problems with FFmpeg's configure script under MingW. The configure script uses awk, and MingW's awk seems to be incorrect. It launches awk with the same arguments, resulting in an infinite loop. The fix is to change MingW's awk script to launch awk.exe.
Extra Bits
We comment out the call to show_banner() in ffmpeg.c, in order to prevent the build identifiers from appearing every time that ffmpeg is run.
