每次在Android中使用FFmpegFrameGrabber.grabImage()获取相同的帧

时间:2017-02-12 15:38:22

标签: android ffmpeg javacv

尝试使用javaCV,FFFmpegFramGrabber从视频文件中提取每个帧并保存为jpg,每次最终得到相同的帧。

      FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(cVideoFilePath+ "/" + "VID_20170211_132657.mp4");
    try {
        AndroidFrameConverter convertToBitmap = new AndroidFrameConverter();
        grabber.start();

        for (int i= 0; i< grabber.getFrameRate();i++){

             frame1 = grabber.grabImage();
            Bitmap bitmap = convertToBitmap.convert(frame1);
            String date = simpleDateFormat.format(new Date());
            File picfile = new File(file_name);
            if (!picfile.exists()) {
                try {
                    picfile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {

                FileOutputStream out = new FileOutputStream(picfile);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                out.flush();
                out.close();

            } catch (IOException ex) {

            } finally {

            }
}

1 个答案:

答案 0 :(得分:0)

循环看起来不对。以下是此循环的预期:

int frame_count = grabber.getLengthInFrames();
for (int i=0; i<frame_count; i+=grabber.getFrameRate())