我正在开发一个基于 Javacv 的 Android 项目。我已按照项目 Readme.txt 文件中给出的说明进行操作。将所有 .so 文件放在 libs/armeabi 文件夹中。并使用以下几行将图像转换为电影。但是得到了以下日志。
*日志猫 *
07-16 16:38:32.790: D/dalvikvm(27175): No JNI_OnLoad found in /data/data/com.javacv.ffmpeg/lib/libavutil.so 0x44e8db60, skipping init
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/javacv/cpp/avutil;.<clinit>
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/avcodec;.<clinit>
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/avformat;.<clinit>
07-16 16:38:33.160: D/dalvikvm(27175): Trying to load lib /data/data/com.javacv.ffmpeg/lib/libopencv_core.so 0x44e8db60
07-16 16:38:33.160: I/dalvikvm(27175): Unable to dlopen(/data/data/com.javacv.ffmpeg/lib/libopencv_core.so): Cannot load library: get_lib_extents[759]: 1196 - /data/data/com.javacv.ffmpeg/lib/libopencv_core.so is not a valid ELF object
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/javacv/cpp/opencv_core;.<clinit>
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/opencv_imgproc;.<clinit>
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/opencv_highgui;.<clinit>
07-16 16:38:33.170: D/AndroidRuntime(27175): Shutting down VM
07-16 16:38:33.170: W/dalvikvm(27175): threadid=1: thread exiting with uncaught exception (group=0x400207c8)
07-16 16:38:33.190: E/AndroidRuntime(27175): FATAL EXCEPTION: main
07-16 16:38:33.190: E/AndroidRuntime(27175): java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.javacv.ffmpeg.ZT_FFMPEG_JAVACVActivity.onCreate(ZT_FFMPEG_JAVACVActivity.java:19)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.os.Looper.loop(Looper.java:123)
07-16 16:38:33.190: E/AndroidRuntime(27175): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-16 16:38:33.190: E/AndroidRuntime(27175): at dalvik.system.NativeStart.main(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.Class.classForName(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.Class.forName(Class.java:235)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacpp.Loader.load(Loader.java:334)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:91)
07-16 16:38:33.190: E/AndroidRuntime(27175): ... 14 more
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.Class.classForName(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.Class.forName(Class.java:235)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacpp.Loader.load(Loader.java:334)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:96)
07-16 16:38:33.190: E/AndroidRuntime(27175): ... 18 more
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.UnsatisfiedLinkError: Library jniopencv_core not found
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.Runtime.loadLibrary(Runtime.java:461)
07-16 16:38:33.190: E/AndroidRuntime(27175): at java.lang.System.loadLibrary(System.java:557)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:444)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacpp.Loader.load(Loader.java:368)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacpp.Loader.load(Loader.java:315)
07-16 16:38:33.190: E/AndroidRuntime(27175): at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:131)
07-16 16:38:33.190: E/AndroidRuntime(27175): ... 22 more
我的源代码
package com.javacv.ffmpeg;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import java.io.File;
import java.util.ArrayList;
import static com.googlecode.javacv.cpp.opencv_highgui.CvVideoWriter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.util.Log;
import com.googlecode.javacpp.annotation.ByPtrPtr;
import com.googlecode.javacpp.annotation.ByVal;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class ZT_FFMPEG_JAVACVActivity extends Activity {
com.googlecode.javacv.FFmpegFrameRecorder recorder ;
private String TAG="kljadf";
private IplImage colorImage;
private IplImage image_small;
private File[] file;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//========== have used previously to convert the single image to movie =========
/*opencv_core.IplImage image = cvLoadImage("/mnt/sdcard/image.jpg");
com.googlecode.javacv.FFmpegFrameRecorder recorder = new com.googlecode.javacv.FFmpegFrameRecorder("/mnt/sdcard/test.3gp",256,256);
try {
recorder.setCodecID(5);
recorder.setFormat("3gp");
recorder.setPixelFormat(0);
recorder.start();
for (int i=0;i<10;i++)
{
recorder.record(image);
}
recorder.stop();
}
catch (Exception e){
e.printStackTrace();
}*/
//========== 以前用过把单张图片转成电影=========
ArrayList<File>iamges=new ArrayList<File>();
iamges.add(new File("mnt/sdcard/image"));
iamges.add(new File("mnt/sdcard/image.png"));
File[] file=iamges.toArray(new File[iamges.size()]);
file=iamges.toArray(new File[iamges.size()]);
writeMovie(file,"Rajesh.mp4");
}
@SuppressLint("ParserError") public void writeMovie(File[] files, String name) {
double fps = 30;
int sas =com.googlecode.javacv.cpp.opencv_highgui.CV_FOURCC('U', '2', '6', '3');
CvVideoWriter writer = com.googlecode.javacv.cpp.opencv_highgui.cvCreateVideoWriter(name,sas, fps, new com.googlecode.javacv.cpp.opencv_core.CvSize(640,480), -1); //CV_LOAD_IMAGE_UNCHANGED values is -1
if (writer == null) {
Log.e(TAG, "Can not create Writer!");
}
for (File list:files) {
colorImage = cvLoadImage(list.toString(), 1); //CV_LOAD_IMAGE_COLOR =value for this=1 sp replaced by 1
if (colorImage == null) {
Log.e(TAG, "Color Image is NULL!");
}
image_small = opencv_core.cvCreateImage(opencv_core.cvSize(640, 480), colorImage.depth(), 4); //colorImage.nChannels()=4 as per jar file
//or whatever color depth/channel number you need...
if (image_small == null) {
Log.e(TAG, "Image Small is NULL!");
}
com.googlecode.javacv.cpp.opencv_imgproc.cvResize(colorImage, image_small, 1); //CV_INTER_LINEAR==1
if (writer != null) {
cvWriteFrame(writer, image_small);
} else {
Log.e(TAG, "Can not write frame, No writer!");
}
opencv_core.cvReleaseImage(colorImage);
opencv_core.cvReleaseImage(image_small);
}
cvReleaseVideoWriter(writer);
finish();
}
public static native void cvReleaseVideoWriter(@ByPtrPtr CvVideoWriter paramCvVideoWriter);
public static native int cvWriteFrame(CvVideoWriter paramCvVideoWriter, opencv_core.IplImage paramIplImage);
public static native CvVideoWriter cvCreateVideoWriter(String paramString, int paramInt1, double paramDouble, @ByVal opencv_core.CvSize paramCvSize, int paramInt2);
**
将所有 .so 文件放在 libs/armeabi 和 libs/armeabi_v7 文件夹中。请帮我解决这个问题。
谢谢 。