Android的摄像机2捕捉突发的速度太慢 [英] Android camera2 capture burst is too slow

查看:1192
本文介绍了Android的摄像机2捕捉突发的速度太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改的Andr​​oid Camera2Basic code捕捉突发的图片。但是,我不能得到的照片之间的延迟时间比任何快200-300ms我的Nexus 5,运行L 5.0.1。

我已经试过了一堆东西,但是这是最基本的。这是我已经修改了Camera2Basic code中的一部分。我的preVIEW TextureView只有50x50dp,但是这不应该的问题,对吧?

有关它的价值,这code只有延迟各地50-100ms在我的Nexus 6,带L 5.1。

 私人无效captureStillPicture(){
    尝试 {
        名单< CaptureRequest> captureList =新的ArrayList< CaptureRequest>();
        米previewRequestBuilder.addTarget(mImageReader.getSurface());

        的for(int i = 0;我小于10;我++){
            captureList.add(M previewRequestBuilder.build());
        }

        mCaptureSession.sto prepeating();
        mCaptureSession.captureBurst(captureList,cameraCaptureCallback,NULL);
        米previewRequestBuilder.removeTarget(mImageReader.getSurface());
    }赶上(CameraAccessException E){
        e.printStackTrace();
    }
}

CameraCaptureSession.CaptureCallback cameraCaptureCallback =新CameraCaptureSession.CaptureCallback(){
    @覆盖
    公共无效onCaptureCompleted(CameraCaptureSession会议,CaptureRequest要求,
            TotalCaptureResult结果){
        Log.d(相机,拯救);
        mPictureCounter ++;
        如果(mPictureCounter> = 10)
            unlockFocus方法();
    }
};
 

解决方案

您正在运行到的问题是,您所请求的图像输出格式的神器。的JPEG编码过程把在相机流水线的大失速时间,所以有很多停机时间的时一次曝光结束,下开始而此编码发生之间。

这是引用,可以实现通过设置在的ImageReader 为YUV输出图像格式,因为这是一个更本土输出摄像机的30fps的速率。这将是存储图像,因为它们被捕捉的方式,那么你必须做的JPEG编码之后,独立的摄像头的在线处理的。

例如,对了Nexus 5的输出摆摊时间 JPEG 编码是243ms,你一直在观察。对于 YUV_420_888 输出,这是0毫秒。由于其庞大的规模同样, RAW_SENSOR 编码引入200ms的失速时间。

还要注意的是,即使你选择一个快的格式消除失速时间的障碍,还有一个最小帧的时间,根据不同的输出图像大小。但对于一台Nexus 5的全分辨率输出,这是为33ms,这正是您所期望的。

相关信息在相机元数据的 StreamConfigurationMap 对象,<一个href="https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html">here.退房 getOutputStallDuration(INT格式,尺寸大小) getOutputMinFrameDuration(INT格式,尺寸大小)的方法进行确认。

I am trying to modify the android-Camera2Basic code to capture a burst of pictures. However, I can't get the delay between pictures any faster than 200-300ms on my Nexus 5, running L 5.0.1.

I've tried a bunch of things, but this is the most basic. This is the only part of the Camera2Basic code that I've modified. My preview TextureView is only 50x50dp, but that shouldn't matter, right?

For what it's worth, this code only has delays around 50-100ms on my Nexus 6, with L 5.1.

private void captureStillPicture() {
    try {
        List<CaptureRequest> captureList = new ArrayList<CaptureRequest>();
        mPreviewRequestBuilder.addTarget(mImageReader.getSurface());

        for (int i=0;i<10;i++) {
            captureList.add(mPreviewRequestBuilder.build());
        }

        mCaptureSession.stopRepeating();
        mCaptureSession.captureBurst(captureList, cameraCaptureCallback, null);
        mPreviewRequestBuilder.removeTarget(mImageReader.getSurface());
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

CameraCaptureSession.CaptureCallback cameraCaptureCallback = new CameraCaptureSession.CaptureCallback() {
    @Override
    public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
            TotalCaptureResult result) {
        Log.d("camera","saved");
        mPictureCounter++;
        if (mPictureCounter >= 10)
            unlockFocus();
    }
};

解决方案

The issue you are running into is an artifact of the image output format you have requested. The JPEG encoding process puts a large stall time on the camera pipeline, so there is a lot of downtime between when one exposure ends and the next begins while this encoding happens.

The 30fps rate that is quoted can be achieved by setting the output image format on the ImageReader as YUV, since that is a more "native" output for the camera. This would be the way to store the images as they are captured, and then you would have to do JPEG encoding afterwards, separate of the camera's inline processing.

For example, on the Nexus 5 the output stall time for JPEG encoding is 243ms, which you have been observing. For YUV_420_888 output, it is 0ms. Likewise, because of their large size, RAW_SENSOR encoding introduces a stall time of 200ms.

Note also that even if you remove the stall time obstacle by choosing a "faster" format, there is still a minimum frame time, depending on the output image size. But for a Nexus 5's full resolution output, this is 33ms, which is what you were expecting.

The relevant information is in the camera metadata's StreamConfigurationMap object, here. Check out the getOutputStallDuration(int format, Size size) and getOutputMinFrameDuration(int format, Size size) methods for confirmation.

这篇关于Android的摄像机2捕捉突发的速度太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆