How to get supported video camera resolutions in android?

17,104

Solution 1

Did you try to use the getSupportedVideoSizes() method from Camera.Parameters class?

public List<Camera.Size> getSupportedVideoSizes()

This method returns a list of Size objects. It will return null if the camera does not have separate preview and video output. The answer here indicates that when this returns null you may use the getSupportedPreviewSizes() list.

Solution 2

Ok I think I figured it out. It seems to work correctly on the phones I have been testing on.

List<Size> tmpList = camera.getParameters().getSupportedPreviewSizes();

    final List<Size> sizeList = new Vector<Size>();

    //compair the apsect ratio of the candidate sizes against the real ratio
    Double aspectRatio = (Double.valueOf(getWindowManager().getDefaultDisplay().getHeight()) / getWindowManager().getDefaultDisplay().getWidth());
    for(int i=0; i<tmpList.size(); i++){
        Double tmpRatio = Double.valueOf(tmpList.get(i).height) / tmpList.get(i).width;
        if(Math.abs(aspectRatio - tmpRatio) < .15){
            sizeList.add(tmpList.get(i));
        }
    }
Share:
17,104
jln646v
Author by

jln646v

Java developer at LocalEdge, division Hearst Media

Updated on June 14, 2022

Comments

  • jln646v
    jln646v almost 2 years

    I am writing an app where I am allowing the user to capture video using the phones camera. I am using my own code to record the video as opposed to Androids built in camera app.

    Everything is working OK except I need to be able to access the list of supported camera resolutions so I can choose at runtime which one to use. I am looking for something like getSupportedPictureSizes() but for video. Android 3.0 has this functionality but I am looking for something for 2.2.

    As of right now I am using CamcorderProfile.QUALITY_HIGH / QUALITY_LOW, but this only gives me two options and on the phones I have been testing on, the file sizes are at each extreme.(QUALITY_LOW is 216 kb/s and QUALITY_HIGH is > 3 MB/s)

    Any help would be greatly appreciated, Thank You!

  • jln646v
    jln646v almost 13 years
    Thanks! but unfortunately that wasnt implemented until API 11 (Android 3) and I am on API 8 (2.2). I found that the other night and it took me a half an hour of cursing to figure out it wasnt in my api.
  • jln646v
    jln646v almost 13 years
    Ok I think I figured it out. It seems to work correctly on the phones I have been testing with.
  • Captain Blammo
    Captain Blammo almost 12 years
    I tried this on the Nexus S with Android 4.0.3, and it always returns null!
  • Captain Blammo
    Captain Blammo almost 12 years
    This only works on some phones. My HTC Desire Z will crash when setting many of the modes listed by this method.
  • Yura Shinkarev
    Yura Shinkarev over 11 years
    Because: Returns: a list of Size object if camera has separate preview and video output; otherwise, null is returned.
  • jln646v
    jln646v almost 11 years
    I believe this is the code that I am still using. On some devices (Motorolla devices seem to do this) getSupportedPreviewSizes() seems to return some sizes that will not work, causing the video to be corrupted with green lines and such. What problems are you having?