尝试使用 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 {
}
}
最佳答案
循环看起来不对。这是这个循环的预期方式:
int frame_count = grabber.getLengthInFrames();
for (int i=0; i<frame_count; i+=grabber.getFrameRate())
关于android - 在 Android 中每次使用 FFmpegFrameGrabber.grabImage() 获取相同的帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42189543/