cocos2dx跨平台直播实例-ffmpeg-android篇

一、环境

    windows10(mac的虚拟机)

    cocos2dx-3.13.1

    android(adt-bundle-window-86_64-20140702)

    ffmpeg-3.0

    ndk(android-ndk-r10c)

    好了,其他的比如jdk什么的就不说了。

二、项目配置

    大家想要在android上运行cocos2dx的项目要先配置好cococs2dx的android环境。这个有传送门。

    哦,还有,我的环境是在eclipse上配置的(不好意思),没用过AndroidStudio,不好意思,不过大家可以看eclipse,懂得eclipse和AndroidStudio的就可以根据eclipse配置自己的AndroidStudio了。

    下面的配置说明是根据大家配置好了cocos2dx运行的环境之后说的,cocos2dx的配置我就不再啰嗦了。

    现在我们的cocos2dx是用的我的上一篇cocos2dx跨平台直播实例-ffmpeg-ios篇写过的项目。

    好了,把项目Import进eclipse里,现在大家配置好了cocos2dx的环境,运行一下,肯定是报错的,因为我们之前写的LiveVideo需要ffmpeg库,而我们上一篇中配置的ffmpeg库的环境只是ios或者mac项目的,android里面并没有这样的环境!!

    所以,接下来我们要配置ffmpeg在cococs2dx-android的项目上的环境。

    1.ffmpeg在android用的库的编译

       传送门。这篇文章里的编译环境是在mac下的,linux下也可以,所以windows的同学还得建个linux或者mac的虚拟机才行。。。。

    2.ffmpeg库在andorid上的配置

       ffmpeg编译好之后,把include和lib文件夹复制到android项目的jni下面。

如图:

cocos2dx跨平台直播实例-ffmpeg-android篇_第1张图片

之后,

修改Android.mk文件

 

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE:= libavcodec

LOCAL_SRC_FILES:= lib/libavcodec-57.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)
 

include $(CLEAR_VARS)

LOCAL_MODULE:= libavformat

LOCAL_SRC_FILES:= lib/libavformat-57.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE:= libswscale

LOCAL_SRC_FILES:= lib/libswscale-4.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE:= libavutil

LOCAL_SRC_FILES:= lib/libavutil-55.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE:= libavfilter

LOCAL_SRC_FILES:= lib/libavfilter-6.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE:= libswresample

LOCAL_SRC_FILES:= lib/libswresample-2.so

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos/audio/include)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := hellocpp/main.cpp \
				   ../../Classes/LiveVideo.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_SHARED_LIBRARIES:=libavcodec libavfilter libavformat libavutil libswscale libswresample

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END


用上面的内容替换掉Android.mk里的内容。

 

然后,Application.mk文件:

加上这句

编译Project-Clean。

cocos2dx跨平台直播实例-ffmpeg-android篇_第2张图片

 

完成,等待编译结束。。。。。。。

最后,如果大家配置的时候出现问题可以留言或者下载项目https://github.com/zhu12345618/ffmeg_android_test

还有一个,就是iod和android都可以运行的项目https://github.com/zhu12345618/ffmeg_android_test

你可能感兴趣的:(android,c++,ffmpeg,cocos2dx)