使用Camera2 API的低FPS [英] Low FPS with Camera2 API

查看:588
本文介绍了使用Camera2 API的低FPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用新的camera2 API时,我的FPS速率较低.具体来说, 尽管从

I am experiencing a low FPS rate with the new camera2 api. Specifically, despite choosing the highest FPS range (30,30) from

characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);

并使用

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, bestFPSRange);

在我测试过的两种设备(三星S5和Xperia Z3 Compact)上,获得高图像分辨率的平均速率都低得多.这是我设置OnImageAvailableListener的方法:

I get much lower average rates for high image resolutions on both devices I have tested (Samsung S5 and Xperia Z3 Compact). Here is how I set up the OnImageAvailableListener:

int format = ImageFormat.YUV_420_888;
Size largest = map.getOutputSizes(format)[0];
Log.d("Images", "sizes: " + Arrays.toString(map.getOutputSizes(format)));
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), format,
        /* maxImages */50);
mImageReader.setOnImageAvailableListener(new OnImageAvailableListener() {

    private int  frames      = 0;
    private long initialTime = SystemClock.elapsedRealtimeNanos();

    @Override
    public void onImageAvailable(ImageReader reader) {
        reader.acquireLatestImage().close();
        frames++;
        if ((frames % 30) == 0) {
            long currentTime = SystemClock.elapsedRealtimeNanos();
            long fps = Math.round(frames * 1e9 / (currentTime - initialTime));
            Log.d("Image", "frame# : " + frames + ", approximately " + fps + " fps");
            frames = 0;
            initialTime = SystemClock.elapsedRealtimeNanos();
        }
    }
}, mBackgroundHandler);

基本上,上面的if语句每30个样本获取一次平均FPS.实际上,在两个设备上的最高分辨率(1920x1080)上,我看到的fps范围均为15-20 fps.但是,在线上的其他人似乎表明,无论分辨率如何,都应该可以达到30fps,实际上,使用旧的不推荐使用的相机API,我可以在两台设备上以最高的分辨率获得30fps.那我想念什么呢?

Basically, the if statement above is taking an average FPS every 30 samples. In practice, at the highest resolutions on both devices (1920x1080), I see fps ranges of 15-20 fps. Others online seem to indicate, however, that 30fps should be possible regardless of the resolution, and in fact, using the old deprecated camera API, I CAN get 30fps on both devices with the highest resolution. So what am I missing?

我已经尝试了TEMPLATE(例如TEMPLATE_PREVIEW)和格式(例如ImageFormat.YUV_420_888)的所有组合.我忘了扭哪一个旋钮?

I already tried all of the combinations of TEMPLATE (e.g. TEMPLATE_PREVIEW) and format (e.g. ImageFormat.YUV_420_888). Which other knob am I forgetting to twist?

推荐答案

S5和Z3 Compact被分类为LEGACY设备.我在其他LEGACY设备(包括

The S5 and Z3 Compact are classified as LEGACY devices. I tested this code on other LEGACY devices, including a

三星Galaxy S5

Samsung Galaxy S5

Xperia Z3 Compact

Xperia Z3 Compact

HTC One M9

HTC One M9

华为伴侣S

所有人都以1080p返回低帧速率(约15fps).我发现其中一部手机LG G4支持完整档案.在那台设​​备上,即使在高帧尺寸下,我也能获得30fps.因此,我强烈怀疑在camera2 api的包装中存在导致此问题的开销.

All of them returned low frame rates (approximately 15fps) at 1080p. One of the phones I found, an LG G4, support the FULL profile. On that device, I was able to get 30fps at even high frame sizes. So I strongly suspect that there is overhead in the camera2 api's wrapper that is causing this problem.

这篇关于使用Camera2 API的低FPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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