简体   繁体   English

HTC m8中的低fps`onPreviewFrame`

[英]Low fps `onPreviewFrame` in HTC m8

I'm using camera.setPreviewCallbackWithBuffer(...) to get my frames - doing it in separate frame. 我正在使用camera.setPreviewCallbackWithBuffer(...)获取帧-在单独的帧中进行。 (I'm aware of the new camera2 api - but i want to stick for now with this one) (我知道新的camera2但我现在想坚持使用此API)

I have issues regarding fps of the previews frame in my cellphone. 关于手机中预览帧的fps,我有问题。

I've checked the fps at the onPreviewFrame(...) method and i get around 25 fps in many devices, including using GenyMotion emulator. 我已经通过onPreviewFrame(...)方法检查了fps,在许多设备中(包括使用GenyMotion模拟器onPreviewFrame(...) ,我都得到了大约25 fps。 But in my HTC M8 i get maximum 11 fps. 但是在我的HTC M8中,我的最高速度为11 fps。

In my onPreviewFrame(...) I removed all my frame processing code and left the fps computing only (3 simple lines) so no code in there is doing this slowing down. 在我的onPreviewFrame(...)我删除了所有帧处理代码,只保留了fps计算(3条简单的行),因此其中没有代码会减慢速度。 (and it is working good in other devices - so it must be camera settings - I think) (它在其他设备上运行良好-因此必须是相机设置-我认为)

I've tried 我试过了

  • setPreviewSize(320,240)
  • setRecordHint(true)
  • setPreviewFpsRange(30000,30000)

(everything been double checked with the supported values of the camera) (所有检查均已通过相机的支持值进行了仔细检查)

Nothing help with my HTC M8 - android 6. HTC M8没有任何帮助-android 6。

What do i need to set to make it faster? 我需要设置什么才能使其更快?

The problem with HTC for some reason that we need to provide them more than one buffer when using camera.setPreviewCallbackWithBuffer(..) HTC的问题由于某些原因,在使用camera.setPreviewCallbackWithBuffer(..)时我们需要为它们提供多个缓冲区camera.setPreviewCallbackWithBuffer(..)

for example 例如

camera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() {
       @Override
       public void onPreviewFrame(byte[] data, Camera camera) {

           // Do what ever here

          camera.addCallbackBuffer(data);
      }
});

int bitsPetPixel = ImageFormat.getBitsPerPixel(cameraPreviewFormat);
double bytesPerPixel = bitsPetPixel / 8.0;
int frameSize = (int) (cameraPreviewSize.getWidth() * cameraPreviewSize.getHeight() * bytesPerPixel);

byte[][] framesData = new byte[10][];
for (int i = 0; i < framesData.length; i++) {
     framesData[i] = new byte[frameSize];
}

// Providing more than one buffer did the trick
// For the demo it is 10
for (int i = 0; i < framesData.length; i++) {
   camera.addCallbackBuffer(framesData[i]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM