Search code examples
androidandroid-cameraandroid-mediarecorder

Recording 4K with MediaRecorder


Was looking through the camera2 video sample app published by Google and one of the methods goes as following:

/**
 * 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];
}

I've fiddled with my own implementation of camera2 and attempted to record a 4K video with media recorder which worked fine - the recorded file reported dimensions of 3840 × 2160.

So, is the comment in the sample incorrect or MediaRecorder was not capable of handling larger resolutions on Lollipop but is capable on Marshmallow or something else?


Solution

  • CamcorderProfile does support 4K, as 'QUALITY_2160P', so best practice is to check if that profile is supported. If it is, then using that size for the camera2 output to MediaRecorder is expected to work.

    However, since not all devices support 4K, 1080p is a conservative limit used in the sample app - parts of the app also predate the addition of 4K support to CamcorderProfile, so the comment is a bit out of date.