我使用最新版本的JavaCV来压缩视频,并根据我的要求获取mp4文件,方法是使用以下代码。
File inputFile = new File(UTILS.getAppDirPath(),actual_input_file.getName());
File outputFile = new File(UTILS.getAppDirPath(),"comp_"+actual_file_name+".mp4");
FrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile,
grabber.getImageWidth(), grabber.getImageHeight(),
grabber.getAudioChannels());
recorder.setFrameRate(grabber.getFrameRate());
recorder.setSampleRate(grabber.getSampleRate());
recorder.setFormat("mp4");
if(grabber.getVideoBitrate()>bitrate)
{
recorder.setVideoBitrate(bitrate);
}
else
{
recorder.setVideoBitrate(grabber.getVideoBitrate());
}
recorder.start();
int count = 0;
Frame frame;
while ((frame = grabber.grabFrame()) != null) {
recorder.record(frame);
count++;
}
recorder.stop();
grabber.stop();
这些是我放在libs
应用程序目录中的库,
/libs
/libs/armeabi
/libs/armeabi/libavcodec.so
libs/armeabi/libavdevice.so
libs/armeabi/libavfilter.so
libs/armeabi/libavformat.so
libs/armeabi/libavutil.so
libs/armeabi/libjniavcodec.so
libs/armeabi/libjniavdevice.so
libs/armeabi/libjniavfilter.so
libs/armeabi/libjniavformat.so
libs/armeabi/libjniavutil.so
libs/armeabi/libjnicvkernels.so
libs/armeabi/libjniopencv_calib3d.so
libs/armeabi/libjniopencv_contrib.so
libs/armeabi/libjniopencv_core.so
libs/armeabi/libjniopencv_features2d.so
libs/armeabi/libjniopencv_flann.so
libs/armeabi/libjniopencv_highgui.so
libs/armeabi/libjniopencv_imgproc.so
libs/armeabi/libjniopencv_legacy.so
libs/armeabi/libjniopencv_ml.so
libs/armeabi/libjniopencv_nonfree.so
libs/armeabi/libjniopencv_objdetect.so
libs/armeabi/libjniopencv_photo.so
libs/armeabi/libjniopencv_stitching.so
libs/armeabi/libjniopencv_superres.so
libs/armeabi/libjniopencv_video.so
libs/armeabi/libjniopencv_videostab.so
libs/armeabi/libjnipostproc.so
libs/armeabi/libjniswresample.so
libs/armeabi/libjniswscale.so
libs/armeabi/libnative_camera_r2.2.0.so
libs/armeabi/libnative_camera_r2.3.3.so
libs/armeabi/libnative_camera_r3.0.1.so
libs/armeabi/libnative_camera_r4.0.0.so
libs/armeabi/libnative_camera_r4.0.3.so
libs/armeabi/libnative_camera_r4.1.1.so
libs/armeabi/libnative_camera_r4.2.0.so
libs/armeabi/libnative_camera_r4.3.0.so
libs/armeabi/libnative_camera_r4.4.0.so
libs/armeabi/libopencv_calib3d.so
libs/armeabi/libopencv_contrib.so
libs/armeabi/libopencv_core.so
libs/armeabi/libopencv_features2d.so
libs/armeabi/libopencv_flann.so
libs/armeabi/libopencv_gpu.so
libs/armeabi/libopencv_highgui.so
libs/armeabi/libopencv_imgproc.so
libs/armeabi/libopencv_legacy.so
libs/armeabi/libopencv_ml.so
libs/armeabi/libopencv_nonfree.so
libs/armeabi/libopencv_objdetect.so
libs/armeabi/libopencv_photo.so
libs/armeabi/libopencv_stitching.so
libs/armeabi/libopencv_superres.so
libs/armeabi/libopencv_video.so
libs/armeabi/libopencv_videostab.so
libs/armeabi/libpostproc.so
libs/armeabi/libswresample.so
libs/armeabi/libswscale.so
libs/armeabi/libtbb.so
libs/android-support-v4.jar
libs/commons-net-3.3.jar
libs/ffmpeg.jar
libs/gson-2.2.4.jar
libs/javacpp.jar
libs/javacv.jar
libs/opencv.jar
问题:
当我在三星Galaxy S4,谷歌Nexus 7,三星Galaxy Core上测试时,一切正常。 当我在Motorola Razr上测试时失败了, 我面临的错误:
第一条错误消息:
02-11 09:54:57.579: E/dalvikvm(22745): dlopen("/data/app-lib/com.myapp.example.apk-1/libjniavdevice.so") failed: dlopen failed: cannot locate symbol "av_input_audio_device_next" referenced by "libjniavdevice.so"...
02-11 09:54:57.579: W/dalvikvm(22745): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/bytedeco/javacpp/avdevice;
第二条错误消息:
02-11 09:54:57.962: I/dalvikvm(22745): Could not find method java.awt.image.BufferedImage.getSampleModel, referenced from method org.bytedeco.javacpp.helper.opencv_core$AbstractIplImage.createFrom`
第三条错误消息:
02-11 09:54:58.300: W/System.err(22745): org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open audio codec.`
注意: 截至目前,我已经包含了armeabi的库文件,我也有x86的库文件。 某些特定设备(Motorola Razr)的处理器能否成为这种崩溃的原因?即:Motorola Razr拥有Krait处理器。