采用的方法cygwin + ndk-r9 + xp +ffmpeg0.9.3
参考http://zzhhui.blog.sohu.com/244819188.html编译静态库的方法,我在XP下终于编译出了
libavcodec.a、libavformat.a、libavutil.a、libpostproc.a、libswscale.a和libffmpeg.so
然后再参照
https://github.com/churnlabs/android-ffmpeg-sample方法建立工程
工程如下
Android.mk文件如下
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := native.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib -L$(LOCAL_PATH) -lavformat -lavcodec -lpostproc -lavutil -lswscale -llog -ljnigraphics -lz -ldl -lgcc
include $(BUILD_SHARED_LIBRARY)
native.c文件如下
void Java_cn_ct_rtmpdemo_MainActivity_openFile(JNIEnv * env, jobject this)
{
int ret;
int err;
int i;
AVCodec *pCodec;
uint8_t *buffer;
int numBytes;
avcodec_init();
av_register_all();
avformat_network_init();
LOGE("Registered formats");
err = av_open_input_file(&pFormatCtx, "rtmp://202.64.87.58/e/855crovd1", NULL, 0, NULL);
LOGE("Called open file");
if(err!=0) {
LOGE("Couldn't open file");
return;
}
LOGE("Opened file");
if(av_find_stream_info(pFormatCtx)<0) {
LOGE("Unable to get stream info");
return;
}
videoStream = -1;
for (i=0; i<pFormatCtx->nb_streams; i++) {//AVMEDIA_TYPE_VIDEO
// if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
videoStream = i;
break;
}
}
if(videoStream==-1) {
LOGE("Unable to find video stream");
return;
}
LOGI("Video stream is [%d]", videoStream);
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL) {
LOGE("Unsupported codec");
return;
}
if(avcodec_open(pCodecCtx, pCodec)<0) {
LOGE("Unable to open codec");
return;
}
pFrame=avcodec_alloc_frame();
pFrameRGB=avcodec_alloc_frame();
LOGI("Video size is [%d x %d]", pCodecCtx->width, pCodecCtx->height);
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
}
在NDK编译的时候报错
D:/android-ndk/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/ffmpeg/native.o: in function Java_cn_ct_rtmpdemo_MainActivity_openFile:jni/native.c:119: error: undefined reference to 'avcodec_find_decoder'
提示avcodec_find_decoder找不到,但是在头文件中这个函数是有的,是不是我编译成静态库的时候出错了?
很多FFMPEG中的函数都提示找不到
下载下来的churnlabs这个工程是可以通过编译的,看了工程中的函数,在我的头文件中是都有的,都能找到啊