我从昨天开始使用android进行javacv并在使用 FFmpegFrameRecorder 或 FrameRecorder 从图像(IplImage)生成视频时出错,同时使用 cvCvtColor在图像过滤中取得成功和 cvCvtColor 。
如图所示,点击第二个按钮(应用效果)即可完成灰度和翻转过滤。
但是点击(制作视频)时会崩溃。
以下是我从图片制作视频的代码。
String path = Environment.getExternalStorageDirectory().getPath() + "/test.mp4";
Log.i("path", path);
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(path, 256, 256);
try {
recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
// recorder.setCodecID(avcodec.AV_CODEC_ID_H263);
recorder.setFormat("mp4");
recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
recorder.start();
for (int i = 0; i < 10; i++) {
recorder.record(image);
}
recorder.stop();
} catch (Exception e) {
e.printStackTrace();
}
图片属于IplImage
记录器对象创建时出错。
我正在使用2台设备
1)华硕zenfone 5
堆栈跟踪
Caused by: java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avcodec
at org.bytedeco.javacpp.Loader.load(Loader.java:387)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacpp.avcodec
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/com.example.javacvex1-1/libjniavcodec.so" has unexpected e_machine: 40
at java.lang.Runtime.loadLibrary(Runtime.java:364)
at java.lang.System.loadLibrary(System.java:526)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
at org.bytedeco.javacpp.Loader.load(Loader.java:410)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avcodec.<clinit>(avcodec.java:12)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/com.example.javacvex1-1/libavcodec.so" has unexpected e_machine: 40
2)Htc me tablet
(适用堆栈跟踪)
Caused by: java.lang.ExceptionInInitializerError
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 76 could not load needed library 'libavcodec.so' for 'libjniavcodec.so' (find_library[1199]: 76 'libavcodec.so' failed to load previously)
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
at org.bytedeco.javacpp.Loader.load(Loader.java:410)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avcodec.<clinit>(avcodec.java:12)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat.<clinit>(avformat.java:13)
at org.bytedeco.javacv.FFmpegFrameRecorder.<clinit>(FFmpegFrameRecorder.java:106)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.makeVideo(MainActivity.java:191)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:180)
at com.example.javacvex1.MainActivity$asyncImageProcVideo.doInBackground(MainActivity.java:152)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 76 could not load needed library 'libswresample.so' for 'libavcodec.so' (load_library[1091]: Library 'libswresample.so' not found)
最后,我将 build.gradle 与 jniLibs 放在左侧。
其他问题的答案没有运气。自去年24小时起被困住了。 :(
任何帮助都会很棒。
答案 0 :(得分:2)
正如本文https://groups.google.com/forum/#!topic/javacv/Q_jxavoWdZE
中所述我终于通过添加
解决了这个问题Loader.load(swresample.class);
在创建FFmpegFrameRecorder对象之前。 谢谢。