2

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?

fadden
  • 51,356
  • 5
  • 116
  • 166
vkislicins
  • 3,331
  • 3
  • 32
  • 62
  • 2
    The capabilities of media recording will vary by device, as much if not more so than by OS. – CommonsWare Nov 11 '15 at 15:50
  • so you're suggesting the author is playing it safe by saying that all the devices will handle <= 1080p but larger res is not safe? Although the `choices` array in this method is from the `CameraCharacteristics` / `StreamConfigurationMap` getOutputSize - which I thought was collected from the camera hardware profile? Confusing.. – vkislicins Nov 11 '15 at 16:01
  • 4
    I am saying that the camera stuff on Android is generally confusing. :-) – CommonsWare Nov 11 '15 at 16:22
  • @CommonsWare and it's very buggy :) gathered some info for many devices using `CamcorderProfile` and others API (it's useless basically) here - https://stackoverflow.com/questions/76846234/mediarecorder-java-io-ioexception-prepare-failed-for-4k-resolutions-on-some – user924 Aug 19 '23 at 22:43

2 Answers2

4

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.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • it's useless :) gathered some info for many devices using `CamcorderProfile` and others API (it's useless basically) here - https://stackoverflow.com/questions/76846234/mediarecorder-java-io-ioexception-prepare-failed-for-4k-resolutions-on-some , even when it's not null it say for example for Camera "2" id of Samsung S22 Ultra that it doesn't support 4K (.hasProfile(...) returns false) so I can record 4000x3000 with this camera using MediaRecorder :) – user924 Aug 19 '23 at 22:41
2

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

Right, but this camera profile does not necessarily comply with MediaRecorder capabilities, e.g. this.

You can trust the Camcorder profiles better,

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

but not without glitches, and no guarantee that on specific device the MediaRecorder cannot handle more than that.

At any rate, the CamcorderProfile has "official" profiles for up to 1080p, so it is a reasonable choice for sample code, which does not claim to deliver best possible results for the widest range of devices.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Right, but this camera profile does not necessarily comply with MediaRecorder - Are you sure this is still relevant for camera2? That's all true and I went through my share of pain related to this with pre-lollipop camera implementation. I was hoping they fixed it / simplified for camera2 and `StreamConfigurationMap` is camera2 class – vkislicins Nov 11 '15 at 16:42
  • Camera is still separate from the MediaRecorder, even if it is camera2. I believe that Camcorder is more tightly coupled with MediaRecorder, but even this is not guaranteed. Actually, my personal experience shows that often camera2 implementations are still less robust than the old API. – Alex Cohn Nov 11 '15 at 17:01
  • `CamcorderProfile.QUALITY_HIGH` is not work on Sony L1 – vuhung3990 Oct 24 '17 at 02:52
  • @vuhung3990 too bad. Does this device return **true** for [CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_HIGH)](https://developer.android.com/reference/android/media/CamcorderProfile.html#hasProfile(int,%20int)) ? – Alex Cohn Oct 24 '17 at 07:47
  • gathered some info for many devices using `CamcorderProfile` and others API (it's useless basically) here - https://stackoverflow.com/questions/76846234/mediarecorder-java-io-ioexception-prepare-failed-for-4k-resolutions-on-some , even when it's not null it say for example for Camera "2" id of Samsung S22 Ultra that it doesn't support 4K (.hasProfile(...) returns false) so I can record 4000x3000 with this camera using MediaRecorder :) – user924 Aug 19 '23 at 22:41