【问题标题】:Extreme camera lag on Nexus 4Nexus 4 上的极端相机延迟
【发布时间】:2013-01-03 01:30:31
【问题描述】:

使用以下非常简单的相机预览活动 (from a google example found here),Nexus 4 相机明显慢于设备的标准相机应用程序:

public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
      private Camera mCamera;
      private TextureView mTextureView;

      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          mTextureView = new TextureView(this);
          mTextureView.setSurfaceTextureListener(this);

          setContentView(mTextureView);
      }

      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
          mCamera = Camera.open();

          try {
              mCamera.setPreviewTexture(surface);
              mCamera.startPreview();
          } catch (IOException ioe) {
              // Something bad happened
          }
      }

      public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
          // Ignored, Camera does all the work for us
      }

      public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
          mCamera.stopPreview();
          mCamera.release();
          return true;
      }

      public void onSurfaceTextureUpdated(SurfaceTexture surface) {
          // Invoked every time there's a new Camera preview frame
      }
  }

我的应用程序在 Nexus 4 上的相机速度一直存在问题,但我在其他设备上没有看到此问题。我担心这是 Jelly Bean 4.2 的差异,但运行 JB4.2 的 Galaxy Nexus 手机可以正常工作,没有延迟。我意识到这个示例代码使用了 TextureView,但是其他手机在这个示例中没有遇到延迟。

任何帮助将不胜感激。

【问题讨论】:

    标签: android android-camera nexus-4


    【解决方案1】:

    我发现预览帧速率可以通过setting the recording hint to true 提高到正常速率,但这会严重降低相机性能,尤其是在色彩饱和度和对比度方面的中低光情况下(我对质量感到震惊考虑到这是 Google 与 iPhone 5 和她的优质摄像头竞争的最新和最伟大的尝试...can't wait for the X Phone)。

    不是解决问题的方法,但对于希望避免令人震惊的帧速率的开发人员来说,它是一种创可贴。

    【讨论】:

    • 同样的问题,你的提示帮助了我,但这不是一个解决方案。 Google 必须在这里做点什么。
    • 确认这确实有效..即使您不使用 MediaRecorder,也需要这样做。
    【解决方案2】:

    如果您将图片大小设置为 3264x2448,这将解决它。即使您从不拍照,图片大小也很重要,因为默认情况下启用了 ZSL。默认图片大小为 640x480,这会导致预览帧速率变慢。禁用 ZSL 可以更快地预览,这就是为什么将录制命中设置为 true 会有所帮助,启用 HDR 可以做同样的事情。

    【讨论】:

    • 将图片大小设置为 3264x2448 并不能解决问题。此外,Nexus 4 的前置摄像头甚至不支持 3264 x 2448 的图片尺寸。
    猜你喜欢
    • 2014-12-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2022-09-28
    相关资源
    最近更新 更多