android – 从图像序列javacv创建视频

为了从 android中的图像序列创建视频,我使用了 javacv 0.6库,但我遇到了问题:
它通常适用于HTC Sensation( Android 4.0.1,处理器类型armv7)和htc Desire(Android 2.3.3,处理器类型arm7)手机,但它不适用于htc Wildfire
(Android 2.3.5,处理器类型armv6)手机尤其在这部分代码中失败了
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,TalkingPhotoConstants.VIDEO_FRAME_WIDTH,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT);

在附加的代码中.

public class MovieCreator extends AsyncTask<String,Void,Boolean> {

private opencv_core.IplImage[] iplimage;
private String audioFilePath;


private ProgressDialog progressDialog;
private Context context;
private List<TalkFrame> frames;

public MovieCreator(Context context,opencv_core.IplImage[] images,String audioFilePath,List<TalkFrame> frames) {
    this.context = context;
    this.iplimage = images;
    this.audioFilePath = audioFilePath;
    this.frames = frames;

}

private String createMovie() {

    String videoName = TalkingPhotoConstants.TMP_VIDEO_NAME;
    String path = TalkingPhotoConstants.RESOURCES_TMP_FOLDER;
    String videoFilePath = path + videoName;
    String finalVideoName = TalkingPhotoConstants.FINAL_VIDEO_NAME + 
    System.currentTimeMillis() + ".mp4";
    String finalVideoPath = TalkingPhotoConstants.RESOURCES_FOLDER + finalVideoName;

    try {

        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT);


        //int frameCount = iplimage.length;
        int frameCount = frames.size();
        recorder.setAudioCodec(AV_CODEC_ID_AMR_NB);
        recorder.setVideoCodec(AV_CODEC_ID_MPEG4);

        recorder.setVideoBitrate(120000);
        recorder.setFrameRate(TalkingPhotoConstants.VIDEO_FRAME_RATE);

        recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
        recorder.setFormat("mp4");

        recorder.start();


        for (int i = 0; i < frameCount; i++) {
            TalkFrame currentFrame = frames.get(i);
            long duration = currentFrame.getDuration();
            opencv_core.IplImage iplImage = cvLoadImage(currentFrame.getimageName());

            for (int j = 0; j < TalkingPhotoConstants.VIDEO_FRAME_RATE * duration; j++) {
                recorder.record(iplImage);

            }

        }

        recorder.stop();

        mergeAudioAndVideo(videoFilePath,audioFilePath,finalVideoPath);

    } catch (Exception e) {
        Log.e("problem","problem",e);
        finalVideoName = "";
    }
    return finalVideoName;
}

private boolean mergeAudioAndVideo(String videoPath,String audioPath,String outPut)  
throws Exception {
    boolean isCreated = true;
    File file = new File(videoPath);
    if (!file.exists()) {
        return false;
    }


    FrameGrabber videoGrabber = new FFmpegFrameGrabber(videoPath);
    FrameGrabber audioGrabber = new FFmpegFrameGrabber(audioPath);

    videoGrabber.start();
    audioGrabber.start();
    FrameRecorder recorder = new FFmpegFrameRecorder(outPut,videoGrabber.getimageWidth(),videoGrabber.getimageHeight(),audioGrabber.getAudioChannels());


    recorder.setFrameRate(videoGrabber.getFrameRate());
    recorder.start();
    Frame videoFrame = null,audioFrame = null;
    while ((audioFrame = audioGrabber.grabFrame()) != null) {
        videoFrame = videoGrabber.grabFrame();
        if (videoFrame != null) {
            recorder.record(videoFrame);
        }
        recorder.record(audioFrame);

    }
    recorder.stop();
    videoGrabber.stop();
    audioGrabber.stop();
    return isCreated;
}

@Override
protected Boolean doInBackground(String... params) {
    String fileName = createMovie();
    boolean result = fileName.isEmpty();
    if (!result) {
        VideoDAO videoDAO = new VideoDAO(context);
        videoDAO.open();
        videoDAO.createVideo(fileName);
        videoDAO.close();
    }
    //Utils.cleanTmpDir();
    return result;
}

@Override
protected void onPreExecute() {
    progressDialog = new ProgressDialog(context);
    progressDialog.setTitle("Processing...");
    progressDialog.setMessage("Please wait.");
    progressDialog.setCancelable(false);
    progressDialog.setIndeterminate(true);
    progressDialog.show();
}

@Override
protected void onPostExecute(Boolean result) {
    if (progressDialog != null) {
        progressDialog.dismiss();

    }
}

}

没有例外.

我怎么能解决它?

2.我有一个版本问题与设备的处理器类型有关.

如果我是对的,我该如何解决

提前致谢.

解决方法

JavaCV包含一些由Java调用的本机C代码.看起来好像你有一个为ARMv7编译但不适用于ARMv6的版本.

为了使它工作,您需要重新编译JavaCV本机位,用于您想要定位的处理器(在本例中为ARMv6).一旦你完成了这个,你应该发现它工作正常.

本机代码很痛苦,但对于像这样的应用程序而言,它正在执行一些非常耗费cpu的事情.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...