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

时间:2025-03-14 07:11:25

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

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

.........

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

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


2.编译的时候遇到

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

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

//
// 
//  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 <>


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/(): in function http_read_header:libavformat/: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/(): in function http_read_header:libavformat/: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/(): in function http_read_header:libavformat/: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/(): in function http_read_stream:libavformat/: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/(): in function http_close:libavformat/: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/(): in function id3v2_read_internal.part.0:libavformat/: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/(): in function mov_read_cmov:libavformat/:2790: error: undefined reference to 'uncompress'

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


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


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)/
include $(PREBUILT_STATIC_LIBRARY)

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

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

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

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

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

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

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


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

LOCAL_SRC_FILES :=
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)


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



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