【发布时间】:2016-07-25 13:13:27
【问题描述】:
我正在尝试从视频中获取多个帧,但有时会出现致命异常。我在这里做的是,如果方向是纵向的,我会取帧一段时间并旋转。失败的原因可能是内存问题。请提出我错在哪里。
private ArrayList<Bitmap> getFrames() {
ArrayList<Bitmap> bmFrames = new ArrayList<>();
Bitmap bmp = null;
Bitmap orientedBitmap = null;
try {
int baseTime = Integer.parseInt(model.getDuration());
baseTime = baseTime / 11 * 1000;
baseTimeArray = new int[11];
for (int i = 0; i < 11; i++) {
baseTimeArray[i] = baseTime * (i);
Log.d("TAG", "fetching frame from " + baseTimeArray[i]);
try {
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(new File(sourceFilePath).getAbsolutePath());
bmp = getBitmapViaFFMPEG(baseTimeArray[i], mmr);
if (rotationMetaData != null) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
//Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmp,50,50,true);
if (bmp != null)
orientedBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
else
Log.d(TAG,"returned bitmap was null");
}
//Log.d("TAG", "rotation: " + rotation);
mmr.release();
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
} catch (RuntimeException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
if (rotationMetaData != null)
bmFrames.add(orientedBitmap);
else
bmFrames.add(bmp);
}
} catch (Exception e) {
e.printStackTrace();
}
return bmFrames;
}
错误日志
【问题讨论】:
-
嗨。你解决了你的问题吗?如果可以,请分享解决方案?
-
我会在星期一分享解决方案。
-
好的,谢谢! @拉利特
-
@HardikJoshi 对不起兄弟,我迟到了,但我回答了。
-
没问题,兄弟。非常感谢(Y)
标签: android performance bitmap frames