我使用Camera 2 API將JPEG圖像保存在磁盤上。我目前在我的Nexus 5X上有3-4 fps,我想將其提高到20-30。可能嗎?攝像頭2,增加FPS
將圖像格式更改爲YUV我設法生成30 fps。是否有可能以這個幀率保存它們,還是應該放棄並以我的3-4 fps生活?
顯然我可以共享代碼,如果需要的話,但如果大家都認爲這是不可能的,我會放棄。使用NDK(例如libjpeg)是一個選項(但顯然我寧願避免它)。
由於
編輯:這裏是如何我轉換YUV android.media.Image到單個字節[]:
private byte[] toByteArray(Image image, File destination) {
ByteBuffer buffer0 = image.getPlanes()[0].getBuffer();
ByteBuffer buffer2 = image.getPlanes()[2].getBuffer();
int buffer0_size = buffer0.remaining();
int buffer2_size = buffer2.remaining();
byte[] bytes = new byte[buffer0_size + buffer2_size];
buffer0.get(bytes, 0, buffer0_size);
buffer2.get(bytes, buffer0_size, buffer2_size);
return bytes;
}
編輯2:另一種方法,我發現了YUV圖像轉換成一個字節[]:在移動電話上
private byte[] toByteArray(Image image, File destination) {
Image.Plane yPlane = image.getPlanes()[0];
Image.Plane uPlane = image.getPlanes()[1];
Image.Plane vPlane = image.getPlanes()[2];
int ySize = yPlane.getBuffer().remaining();
// be aware that this size does not include the padding at the end, if there is any
// (e.g. if pixel stride is 2 the size is ySize/2 - 1)
int uSize = uPlane.getBuffer().remaining();
int vSize = vPlane.getBuffer().remaining();
byte[] data = new byte[ySize + (ySize/2)];
yPlane.getBuffer().get(data, 0, ySize);
ByteBuffer ub = uPlane.getBuffer();
ByteBuffer vb = vPlane.getBuffer();
int uvPixelStride = uPlane.getPixelStride(); //stride guaranteed to be the same for u and v planes
if (uvPixelStride == 1) {
uPlane.getBuffer().get(data, ySize, uSize);
vPlane.getBuffer().get(data, ySize + uSize, vSize);
}
else {
// if pixel stride is 2 there is padding between each pixel
// converting it to NV21 by filling the gaps of the v plane with the u values
vb.get(data, ySize, vSize);
for (int i = 0; i < uSize; i += 2) {
data[ySize + i + 1] = ub.get(i);
}
}
return data;
}
您是否使用方法追蹤或其他技術來精確確定您的時間花費在哪裏?你使用什麼決議?你在一個單獨的線程上做你的磁盤I/O嗎? – CommonsWare
是的,這個時間用在YUV - > JPEG轉換和磁盤I/O上。我正在使用最大分辨率(4000 * 3000左右)。是的,磁盤I/O是線程化的。但是,如果我多線程保存圖像,並且如果花費比圖像創建更多的時間,那麼Ill可能會碰到OOME(或者沒有磁盤空間),對吧? –
「時間花在YUV→JPEG轉換」 - 什麼是YUV-> JPEG轉換?爲什麼Camera2不是直接給你JPEG,而是利用專用於該轉換的任何設備硬件? – CommonsWare