0
我試圖從視頻中獲取多個幀,但它有時會產生致命異常。我在這裏做的是如果方向是縱向的,我正在抓取框架一段時間並旋轉。失敗的原因可能是記憶問題。請提出我錯在哪裏。通過FFmpegMediaMetadataRetriever檢索視頻的多幀時出錯
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;
}
錯誤日誌
嗨。你解決了你的問題嗎?如果你能分享解決方案嗎? –
我將在週一分享您的解決方案。 –
好的,謝謝! @Lalit –