尝试使用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 {
}
}
答案 0 :(得分:0)
循环看起来不对。以下是此循环的预期:
int frame_count = grabber.getLengthInFrames();
for (int i=0; i<frame_count; i+=grabber.getFrameRate())