使用 MediaRecorder 录制 4K

Recording 4K with MediaRecorder

正在查看 Google 发布的 camera2 视频 sample app,其中一种方法如下:

/**
 * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes
 * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
 *
 * @param choices The list of available sizes
 * @return The video size
 */
private static Size chooseVideoSize(Size[] choices) {
    for (Size size : choices) {
        if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
            return size;
        }
    }
    Log.e(TAG, "Couldn't find any suitable video size");
    return choices[choices.length - 1];
}

我已经摆弄了我自己的 camera2 实现,并尝试使用工作正常的媒体记录器录制 4K 视频 - 记录的文件报告尺寸为 3840∆×∆2160。

那么,示例中的注释是否不正确,或者 MediaRecorder 无法在 Lollipop 上处理更大的分辨率,但可以在 Marshmallow 或其他设备上处理?

the choices array in this method is from the CameraCharacteristics / StreamConfigurationMap getOutputSize - which I thought was collected from the camera hardware profile?

是的,但是此相机配置文件不一定符合 MediaRecorder 功能,例如this.

您可以更好地信任摄像机配置文件,

mediarecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

但并非没有 glitches,并且不能保证在特定设备上 MediaRecorder 不能处理更多。

无论如何,CamcorderProfile 有 "official" 个最高 1080p 的配置文件,因此它是示例代码的合理选择,它并不声称在最广泛的范围内提供最佳结果设备数量。

CamcorderProfile 确实支持 4K,如 'QUALITY_2160P',因此最佳做法是检查该配置文件是否受支持。如果是,那么使用 camera2 输出到 MediaRecorder 的大小应该可以工作。

但是,由于并非所有设备都支持 4K,因此 1080p 是示例应用程序中使用的保守限制 - 该应用程序的某些部分还早于向 CamcorderProfile 添加 4K 支持,因此评论有点过时了。