Thursday, December 11, 2008

building ffmpeg with x264/h.264/libx264 encoder on cygwin

The end goal: To use ffmpeg on cygwin to create h.264 encoded video sample clips.

Required packages:

1. Build and install yasm. This should be relatively straightforward.

2. Build and install libx264. libx264 should build and compile normally without issue. But when trying to compile ffmpeg with --enable-libx264 I ran into compile errors which were eventually resolved by performing the following steps:

a. Before running configure, edit the configure script and remove the flag -mno-cygwin from CFLAGS and LDFLAGS. I.e. remove the following 2 lines:

CFLAGS="$CFLAGS -mno-cygwin"
LDFLAGS="$LDFLAGS -mno-cygwin"

b. Run configure, make and make install to complete building.

3. Build and install ffmpeg.

a. configure ffmpeg with libx264 enabled: $ ./configure --enable-libx264 --enable-gpl --enable-pthreads

  • --enable-libx264 : specifies that you want libx264 enabled for your ffmpeg build
  • --enable-gpl : required as libx264 is released under the GPL
  • --enable-pthreads : required if you compiled x264 with pthreads enabled

Depending on your system you may need --enable-memalign-hack as well.

b. compile ffmpeg: $ make

If you run into compile errors resembling the following: "WM_CAP_FIRSTA undeclared" this is a bug in w32api-3.12. You may resolve this by performing the following steps:

i. Find vfw.h. I located mine at /usr/include/win32api/vfw.h.
ii. Comment out or delete the following lines:

#undef WM_CAP_FIRSTA
#undef WM_CAP_FIRSTW

If you run into compile errors resembling the following: "undefined reference to `__assert'" from libx264 this is an issue with cross-compiling for MinGW with Cygwin. You'll need to re-compile libx264 with -mno-cygwin removed from CFLAGS and LDFLAGS.

c. Install ffmpeg: $ make install

4. Put it to use. Finally if you've managed to get everything built, you may start encoding with h.264 with ffmpeg:

$ ffmpeg -ss 60 -i myfile.avi -vcodec libx264 -t 30 -ar 44100 -b 512k -s 320x240 mysample.flv

Useful links:

No comments: