How to build OpenCV with ffmpeg (and VideoWriter) for Android in Windows/Cygwin

Post date: Jan 02, 2015 10:17:45 PM

Assuming ffmpeg for Android was built, this blog post shows how to proceed building OpenCV for Android with ffmpeg as a 3rd-party library. This is so that VideoWriter is available in OpenCV4Android.

1. Modify opencv source codes with this patch, which is based on the patch android-ffmpeg.patch found in this page.

2. Download the native(Window) cmake build system; cygwin version of cmake will not work straightforwardly (See here). Configuring cmake with

    Where is the source code: <opencv>

    Where to build the binaries: <opencv>/build

    Configure -> Unix Makefiles -> Toolchain file: <opencv>/platforms/android/android.toolchain.cmake

    Generate

3. Go to opencv/build folder and type make. The build process will now start. If it fails due to unable to link with library, replace the library symlink with its actual binary, e.g. 

rm libavutil.so

cp libavutil-52.so, libavutil.so

This is because Cygwin symlinks are broken in most cases.

4. OpenCV Manager is not built. Must download the right apk manually

The following links might be useful for troubleshooting

http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk

http://stackoverflow.com/questions/7075180/how-to-compile-opencv-2-3-with-ffmpeg-support-with-visual-studio-2010

Update 1/4/2015: It's much easier to use JavaCV instead of building OpenCV and ffmpeg from scratch.