Cross-platform migration-ffmpeg for android and cocos2dx

Source: Internet
Author: User

[Version]

Ffmpeg 1.2.6, android ndk r8b, cygwin

[Compile in windows]

This is simpler than imagined. compile it with MinGW and use the generated lib library in VS. Refer to the blogs of the following netizens:

Compile ffmpeg in windows

[Configuration compilation]

Install cygwin, put android ndk under the home Directory of cygwin, the path is like this: D: \ cocos2dx \ cygwin \ home \ Administrator \ android-ndk-r8b

Decompress ffmpeg to this location (Content in jni): D: \ cocos2dx \ cygwin \ home \ Administrator \ ffmpeg \ jni \ ffmpeg


Then write the configuration Script config. sh. For details, refer to the following link:

Compile the ffmpeg config. sh script

The content is as follows (note that the configure content is put in one line at last. This is a pitfall! And if the ndk path is different, change it by yourself ):

./configure  --disable-asm --disable-static --enable-shared --enable-gpl --enable-version3 --enable-nonfree --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-avfilter --disable-postproc --enable-small --cross-prefix=/home/Administrator/android-ndk-r8b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi- --enable-cross-compile  --target-os=linux --extra-cflags='-I/home/Administrator/android-ndk-r8b/platforms/android-9/arch-arm/usr/include' --extra-ldflags='-L/home/Administrator/android-ndk-r8b/platforms/android-9/arch-arm/usr/lib -nostdlib' --arch=arm --disable-symver --disable-debug --disable-strippingsed -i 's/HAVE_LRINT 0/HAVE_LRINT 1/g' config.hsed -i 's/HAVE_LRINTF 0/HAVE_LRINTF 1/g' config.hsed -i 's/HAVE_ROUND 0/HAVE_ROUND 1/g' config.hsed -i 's/HAVE_ROUNDF 0/HAVE_ROUNDF 1/g' config.hsed -i 's/HAVE_TRUNC 0/HAVE_TRUNC 1/g' config.hsed -i 's/HAVE_TRUNCF 0/HAVE_TRUNCF 1/g' config.h

Then copy the script to the preceding jni directory and run cygwin to the jni directory to execute the script:

cd /home/Administrator/ffmpeg/jniexport TMPDIR=d:/temp./config.sh

The second sentence is to set a temporary directory, which is also a pitfall, and this directory should exist. Then the third sentence begins to execute the configuration script, and the following is the right one ......


[Compile Android. mk] <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + ztK + kernel/kernel + kernel/CvM/g06a1xM671sO + kernel/kernel + a9ssHLINXiwO + kernel + CjxwPqG + kernel/kernel + cjxwcmUgY2xhc3M9 "brush: java; "> # define CC_IDENT" gcc 4.4.3 (GCC) "# define av_restrict // restrict2. Modify the Makefile in the libavcode libavformat libavutil libswscale directory and remove include XXXXconfig. mak.

3. Modify libavutil/libm. h and delete all static methods.

Then you can set the ndk directory to the path of the environment variable, and then you can start the first wave of attempts from cd to the ffmpeg directory on cygwin, and execute ndk-build.

[Long compilation path-second season]

1. Oh, there may be some problems with ndk. You just need to find the number of lines corresponding to the file in the ndk, which is usually commented out or deleted. I won't try again.

There are still a lot of pitfalls to compile, and I may have gotten rid of them in the above configuration file, so it looks very easy now.

2. time under libavutil. h. h is changed to avtime. h, and then use libavutil/time. change the c files of h to libavutil/avtime. h (go to the directory to set search conditions and modify the search file ).

3. During the link, ff_log2_tab is redefined. Delete log2_tab.o from the makefile under libavformat and libavcodec, delete the temporary file, and compile it.

When you see it, you are done:


If I cannot describe it clearly, I can refer to this blog post. I found this only when I wrote it. I really regret not finding it early:

Http://blog.csdn.net/xms0xms/article/details/8964999

[Used in cocos2dx]

Here only the simplest way, copy ffmpeg to cocos2d-x-2.2.1 \ cocos2dx, because the engine default build_native.sh configured this import directory. Then modify Android. mk and add the following words:

LOCAL_WHOLE_STATIC_LIBRARIES += libavformat LOCAL_WHOLE_STATIC_LIBRARIES += libavcodecLOCAL_WHOLE_STATIC_LIBRARIES += libavutilLOCAL_WHOLE_STATIC_LIBRARIES += libswscaleinclude $(BUILD_SHARED_LIBRARY)$(call import-module,cocos2dx)$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)$(call import-module,CocosDenshion/android)$(call import-module,extensions)$(call import-module,cocos2dx/ffmpeg/jni/ffmpeg/libavformat)$(call import-module,cocos2dx/ffmpeg/jni/ffmpeg/libavcodec)$(call import-module,cocos2dx/ffmpeg/jni/ffmpeg/libavutil)$(call import-module,cocos2dx/ffmpeg/jni/ffmpeg/libswscale)

You can use it as soon as possible. For how to use it, refer to the text below, which can also be transplanted to ios:

Http://blog.csdn.net/langresser_king/article/details/14516879

Note: In android, you must copy the video file to a writable directory (and the directory must exist). Otherwise, an error will occur. Remember ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.