在previewFrame帧速率不一致的Andr​​oid摄像头 [英] Android Camera onPreviewFrame frame rate not consistent

查看:2605
本文介绍了在previewFrame帧速率不一致的Andr​​oid摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接codeA使用媒体codec到相机的previewCall回(在previewFrame)每秒视频30帧。我恩codeD始终发挥非常快的视频(这是不希望的)。 所以,我试图检查帧是进入我的相机的preVIEW通过设置INT frameCount变量来记住它的计数的数量。我所预料到的是每秒30帧,因为我安装我的相机preVIEW有30 fps的preVIEW(如下图所示)。我回来的结果是不一样的。 我叫上previewFrame回调10秒,我回来frameCount的数量只有约100架。这是糟糕的,因为我期待300帧。是我的相机参数设置是否正确?这是Android的摄像头preVIEW限制再打?如果这是对Android相机的preVIEW回拨的限制,那么还有什么其他的相机回调,可以以每秒30帧返回相机的图像数据(NV21,YUV,YV12)?

感谢阅读并采取你的时间,以帮助环聊。我会AP preciate任何意见和建议。

下面是一个例子使用的连接codeD视频摄像机的previewFrame:

http://www.youtube.com/watch?v= I1Eg2bvrHLM和放大器;配备= youtu.be

  Camera.Parameters参数= mCamera.getParameters();
                parameters.set previewFormat(ImageFormat.NV21);
                parameters.setPictureSize(previewWidth,previewHeight);
                parameters.set previewSize(previewWidth,previewHeight);
// parameters.set previewFpsRange(30000,30000);

                parameters.set previewFrameRate(30);
                mCamera.setParameters(参数);

                mCamera.set previewCallback(previewCallback);
                mCamera.set previewDisplay(保持器);
 

解决方案

没有,Android摄像头并不能保证稳定的帧速率,尤其是在30 FPS。例如,它可能选择在低照明条件下更长的曝光

但也有一些方法,我们,应用程序开发人员,可以使事情变得更糟。

首先,使用设置previewCallback(),而不是设置previewCallbackWithBuffer的()。这可能会导致垃圾收集不必要的pressure。

第二,如果在previewFrame()到达主(UI)线程上,你造成任何UI操作直接延缓相机帧到来。为了让在previewFrame()在一个单独的线程,你应该的open()在辅助摄像头弯针线。

三,检查处理时间小于20ms。

I am trying to encode a 30 frames per second video using MediaCodec through the Camera's PreviewCall back(onPreviewFrame). The video that I encoded always plays very fast(this is not desired). So, I tried to check the number of frames that is coming into my camera's preview by setting up a int frameCount variable to remember its count. What I am expecting is 30 frames per second because I setup my camera's preview to have 30 fps preview(as shown below). The result that I get back is not the same. I called the onPreviewFrame callback for 10 second, the number of frameCount I get back is only about 100 frames. This is bad because I am expecting 300 frames. Is my camera parameters setup correctly? Is this a limitation of Android's Camera preview call back? And if this is a limitation on the Android Camera's preview call back, then is there any other camera callback that can return the camera's image data(nv21,yuv, yv12) in 30 frames per second?

thanks for reading and taking your time to helpout. i would appreciate any comments and opinions.

Here is an example an encoded video using Camera's onPreviewFrame:

http://www.youtube.com/watch?v=I1Eg2bvrHLM&feature=youtu.be

                Camera.Parameters parameters = mCamera.getParameters();
                parameters.setPreviewFormat(ImageFormat.NV21);
                parameters.setPictureSize(previewWidth,previewHeight);
                parameters.setPreviewSize(previewWidth, previewHeight);
//              parameters.setPreviewFpsRange(30000,30000);

                parameters.setPreviewFrameRate(30);
                mCamera.setParameters(parameters);

                mCamera.setPreviewCallback(previewCallback);
                mCamera.setPreviewDisplay(holder);

解决方案

No, Android camera does not guarantee stable frame rate, especially at 30 FPS. For example, it may choose longer exposure at low lighting conditions.

But there are some ways we, app developers, can make things worse.

First, by using setPreviewCallback() instead of setPreviewCallbackWithBuffer(). This may cause unnecessary pressure on the garbage collector.

Second, if onPreviewFrame() arrives on the main (UI) thread, you cause any UI action directly delay the camera frames arrival. To keep onPreviewFrame() on a separate thread, you should open() the camera on a secondary Looper thread.

Third, check that processing time is less than 20ms.

这篇关于在previewFrame帧速率不一致的Andr​​oid摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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