jni封装ffmpeg接口遇到的错误修改方法

前段时间编译了ffmpeg的android版本,今天准备封装一下jni接口供上层java调用,在编译库的时候遇到了一些错误,这里分享出来,后面遇到的童鞋可以少走弯路。

1.编译的时候出现如下错误:

.........

/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:80:28: error: 'uint8_t' was not declared in this scope
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:80:37: error: 'data' was not declared in this scope
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:80:46: error: expected primary-expression before 'enum'
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:80:74: error: expected primary-expression before 'int'
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:81:28: error: 'uint8_t' was not declared in this scope
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:81:37: error: 'ptr' was not declared in this scope
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:81:42: error: expected primary-expression before 'const'
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:81:64: error: expression list treated as compound expression in initializer [-fpermissive]
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/imgutils.h:93:20: error: 'uint8_t' was not declared in this scope
.......

解决办法:这是因为找不到uint8_t这些定义,网上说什么修改ffmpeg里面的某个common.h头文件加上这些定义什么的呀,其实完全不用这么做,本身有个系统文件是有这些定义的,加上头文件#include <inttypes.h>即可,注意需要加在引用ffmpeg头文件之前


2.编译的时候遇到

/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/common.h: In function 'int32_t av_clipl_int32_c(int64_t)':
/Users/chenjianjun/Documents/work/ffmpeg-android/build/include/libavutil/common.h:183:47: error: 'UINT64_C' was not declared in this scope

解决办法:这个时候需要手动在你的代码里面加上几句代码,注意需要加在引用ffmpeg头文件之前。直接上代码:

//
//  H264Decoder.h
//  MICloudPub
//
//  Created by chenjianjun on 14-6-3.
//  Copyright (c) 2014年 hy. All rights reserved.
//

#ifndef __MICloudPub___H264Decoder__
#define __MICloudPub___H264Decoder__

#ifndef UINT64_C
#define UINT64_C(value) __CONCAT(value, ULL)
#endif

#include <inttypes.h>


3.连接的时候遇到

/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(http.o): in function http_read_header:libavformat/http.c:384: error: undefined reference to 'inflateEnd'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(http.o): in function http_read_header:libavformat/http.c:385: error: undefined reference to 'inflateInit2_'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(http.o): in function http_read_header:libavformat/http.c:390: error: undefined reference to 'zlibCompileFlags'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(http.o): in function http_read_stream:libavformat/http.c:865: error: undefined reference to 'inflate'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(http.o): in function http_close:libavformat/http.c:1030: error: undefined reference to 'inflateEnd'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(id3v2.o): in function id3v2_read_internal.part.0:libavformat/id3v2.c:838: error: undefined reference to 'uncompress'
/Users/chenjianjun/Documents/andriod_dev/adt-bundle-mac-x86_64/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib/libavformat.a(mov.o): in function mov_read_cmov:libavformat/mov.c:2790: error: undefined reference to 'uncompress'

解决办法:需要在android.mk里面加上连接动态库的时候加上-lz这个,表示依赖libz.so这个系统库


另外附上我的android.mk文件,给大家参考:

Android.mk:

LOCAL_PATH := $(call my-dir)

MY_LIBS_PATH := /Users/chenjianjun/Documents/work/ffmpeg-android/build/lib
MY_INCLUDE_PATH := /Users/chenjianjun/Documents/work/ffmpeg-android/build/include


include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libavcodec.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavfilter
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libavfilter.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libavformat.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavresample
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libavresample.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libavutil.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libpostproc
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libpostproc.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libswresample
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libswresample.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES :=  $(MY_LIBS_PATH)/libswscale.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := MICloudPub
LOCAL_MODULE := libMICloudPub

LOCAL_SRC_FILES := H264Decoder.cpp
LOCAL_CFLAGS :=

LOCAL_C_INCLUDES := $(MY_INCLUDE_PATH)
LOCAL_CPP_INCLUDES := $(MY_INCLUDE_PATH)

LOCAL_LDLIBS := \
    -llog \
    -lgcc \
    -lz
    
LOCAL_WHOLE_STATIC_LIBRARIES := \
    libavcodec \
    libavfilter \
    libavformat \
    libavresample \
    libavutil \
    libpostproc \
    libswresample \
    libswscale

include $(BUILD_SHARED_LIBRARY)


Application.mk:

APP_STL := gnustl_static  
APP_CPPFLAGS := -frtti -fexceptions  
APP_ABI := armeabi-v7a  
APP_PLATFORM := android-8



PS:如果有同学不会使用ffmpeg编解码的,可以来电交流呀(QQ:276775937),广交天下朋友^_^.




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值