Wednesday, February 5, 2014

About Android ffmpeg problem? ? Ask you seniors! ! ! ! ! ! ! ! ! ! !


            
Methods used cygwin + ndk-r9 + xp + ffmpeg0.9.3
Reference http://zzhhui.blog.sohu.com/244819188.html compiled static library methods, I finally compiled a
in XPlibavcodec.a, libavformat.a, libavutil.a, libpostproc.a, libswscale.a and libffmpeg.so

Then referring to
https://github.com/churnlabs/android-ffmpeg-sample method to establish engineering

Works as follows


Android.mk file looks

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 following documents

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 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);
}

In NDK compile time error
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'

Tip avcodec_find_decoder found, but this function in the header file is there, I was not compiled into a static library when a mistake?
Many of the functions FFMPEG prompted to find


Downloaded churnlabs this project can be compiled, read engineering function in my header file is there, can be found ah
Reply:
My configuration is the same path with churnlabs also include the file into your head
Reply:
Why is it I can find but can not find it

Reply:
The strange thing is I put my project JNI delete all folders, then copy churnlabs the JNI folder to the project to modify the look native.c file, NDK compile time or error, the function can not find all the FFMPEG , there is not a project where you want to set, churnlabs can be compiled using the NDK
Reply:
Static files should be the right
Reply:
I was wrong, the churnlabs copied all the JNI directory, refresh the project in compilation is
possibleI may be the problem of static documents it is a step not have any problems compiling
Reply:
Do not know what their predecessors
Reply:
Indeed the problem of static documents, re-edited a bit mk files, compiled static files on it, ndk-build it through,
But av_open_input_file (& pFormatCtx, "rtmp :/ / xxx.xxx.87.58/e/mystream", NULL, 0, NULL);'s return value is always negative, my config.sh file is so

#! / Bin / bash
PREBUILT = $ {NDK_ROOT} / toolchains/arm-linux-androideabi-4.8/prebuilt/windows
PLATFORM = android-18
ARCH = - arch = arm
. / Configure \
$ {ARCH} \
- Target-os = linux - enable-cross-compile - cross-prefix = $ {PREBUILT} / bin/arm-linux-androideabi- \
- Extra-cflags = "-fPIC-DANDROID-std = c99" \
- Enable-version3 \
- Enable-gpl \
- Enable-nonfree \
- Disable-stripping \
- Disable-ffmpeg \
- Disable-ffplay \
- Disable-ffserver \
- Disable-ffprobe \
- Disable-encoders \
- Enable-demuxer = rtsp \
- Disable-devices \
- Enable-protocols \
- Enable-protocol = tcp \
- Enable-avfilter \
- Enable-network \
- Enable-decoder = h264 \
- Disable-avdevice \
- Disable-asm \
- Enable-neon \
- Enable-armv5te \
- Sysinclude = $ {NDK_ROOT} / platforms / $ {PLATFORM} / arch-arm/usr/include \
- Extra-ldflags = "-Wl,-rpath-link = $ {NDK_ROOT} / platforms / $ {PLATFORM} / arch-arm/usr/lib-L $ {NDK_ROOT} / platforms / $ {PLATFORM} / arch- arm / usr / lib-nostdlib $ {NDK_ROOT} / platforms / $ {PLATFORM} / arch-arm/usr/lib/crtbegin_static.o $ {NDK_ROOT} / platforms / $ {PLATFORM} / arch-arm/usr/lib / crtend_android.o-lc-lm-ldl "


I have opened with network protocol ah,. / config.sh when I looked at the prompt
install prefix / usr / local
source path.
C compiler D: \ android-ndk \ android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/arm-linux-androideabi-gcc
ARCH c (generic)
big-endian no
runtime cpu detection no
debug symbols yes
strip symbols no
optimize for size no
optimizations yes
static yes
shared no
postprocessing support yes
new filter support yes
network support no


network support is no not yes
Is there any place to set up, looking ladies to answer, feel CSDN Andrews plate good little man ah
Reply:
The reply was deleted administrator at 2013-09-24 17:01:02

Reply:
av_register_all ();
Tune yet
Reply:
Join in engineering


In addition to directly modify the config.h file with config.mak rtmp protocol network there, all open or set to 1
After compiled into the project
av_open_input_file (& pFormatCtx, "rtmp :/ / xxx.xxx.87.58/e/mystream", NULL, 0, NULL); or wrong, the return value is always -5 but my network video is good, no problems path with other software can see
Reply:
reference to the 9th floor youngc527 reply:
av_register_all ();
Tune yet


av_register_all () ;/ / initialize libavformat and register all the muxers, demuxers and protocols
avformat_network_init ();
LOGE ("Registered formats");
err = avformat_open_input (& pFormatCtx, "rtmp :/ / xxx.xxx.87.58/e/mystream", NULL, NULL);
LOGE ("Called open file");
if (err! = 0) {
LOGE ("Couldn't open file% d", err);
return;
}
LOGE ("Opened file");
Reply:
reference to the 9th floor youngc527 reply:
av_register_all ();
Tune yet

There
callCan open a video file, but can not open the video stream
Reply:
The reply was deleted administrator at 2013-09-25 10:17:04

Reply:
The reply was deleted administrator at 2013-09-26 09:29:48

Reply:
Compile time to join rtmp
Reply:
The reply was deleted administrator at 2013-10-30 08:16:20

Reply:
Problem solved? Recently, I also do this stuff, but I ported the VLC-Android, is now able to play rtmp stream is delayed longer, there are about 5s. We two can exchange. QQ: 56431858

No comments:

Post a Comment