Android:使用“连续”录制视频自动对焦

发布于 2024-12-09 19:02:56 字数 628 浏览 0 评论 0原文

我从事视频录制工作;除了要求持续专注之外,一切正常。这就是我所做的(在surfaceCreated和surfaceChanged中都尝试过但没有成功):

camera = Camera.open();
camera.setPreviewDisplay(holder);

Parameters parameters = camera.getParameters();

然后我做其中一个

parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

parameters.set("focus-mode", "continuous-video");

两个应该做同样的事情;然后我设置参数

camera.setParameters(parameters);

最后一行总是崩溃!那么我错过了什么吗?

顺便说一句,我在 Desire HD、Galaxy S、Galaxy Tab 7 和 10.1 等相当新的设备上进行了测试,这些设备必须支持连续自动对焦;至少他们的内置相机应用程序支持它。

I work on video recording; everything works except for requesting continuous focus. This is what I do (tried both in surfaceCreated and surfaceChanged with no success):

camera = Camera.open();
camera.setPreviewDisplay(holder);

Parameters parameters = camera.getParameters();

then I do either

parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

or

parameters.set("focus-mode", "continuous-video");

both should do the same thing; then I set parameters with

camera.setParameters(parameters);

This last line always crashes! So do I miss something?

By the way, I test on rather new devices like Desire HD, Galaxy S, Galaxy Tab 7 and 10.1, which must have support for continuous auto-focus; at least their built-in camera apps support it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

段念尘 2024-12-16 19:02:56

您应该检查设备是否支持连续自动对焦。这对我有用,请尝试一下。

boolean startContinuousAutoFocus() {

    Camera.Parameters params = mCamera.getParameters();

    List<String> focusModes = params.getSupportedFocusModes();

    String CAF_PICTURE = Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, 
           CAF_VIDEO = Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, 
           supportedMode = focusModes
                   .contains(CAF_PICTURE) ? CAF_PICTURE : focusModes
                   .contains(CAF_VIDEO) ? CAF_VIDEO : "";

    if (!supportedMode.equals("")) {

        params.setFocusMode(supportedMode);
        mCamera.setParameters(params);
        return true;
    }

    return false;
}

You should check if Continuous Auto Focus is supported by the device. This is something that works for me, please give it a try.

boolean startContinuousAutoFocus() {

    Camera.Parameters params = mCamera.getParameters();

    List<String> focusModes = params.getSupportedFocusModes();

    String CAF_PICTURE = Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, 
           CAF_VIDEO = Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, 
           supportedMode = focusModes
                   .contains(CAF_PICTURE) ? CAF_PICTURE : focusModes
                   .contains(CAF_VIDEO) ? CAF_VIDEO : "";

    if (!supportedMode.equals("")) {

        params.setFocusMode(supportedMode);
        mCamera.setParameters(params);
        return true;
    }

    return false;
}
血之狂魔 2024-12-16 19:02:56

好的,我对这个问题有某种解决方案:我可以调用 Camera#autoFocus(...) 手动对焦相机。

这仍然存在严重的问题。首先,在某些三星设备上无法在拍摄视频时调用自动对焦。此外,强迫用户在视频录制期间手动对焦相机也不是一个好主意。

因此,如果您在录制时能够正常聚焦视频 - 您的建议将会非常有帮助。

Ok, I have sort of solution to this problem: I was able to manually focus camera calling Camera#autoFocus(...).

This still has serious issues. First, calling autofocus while shooting video is not working on some Samsung devices. Also it's not a good idea to force your users to manually focus the camera during video recording.

So if you were able to normally focus your videos while recording - your advice would be very helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文