What video resolutions are supported by QML Camera?

Issue

I need ability to change camera resolutions in my project by QML.
For photos I use imageCapture.supportedResolutions property and make list. But QML videoRecorder have not similar property.

I tried use ViewfinderResolutions() function, but I geting huge resolutions list on my android phone with value like

  • 1920×1080
  • 1920×920
  • 1440×1080
  • 1536×864
  • 208×144
  • 176×144

How I can get correct list of video resolutions without exotical values like 1504×720 ?
In ideal I want short list like

  • 1920×1080
  • 1280×720
  • 720×576

If phone’s camera support thesis resolutions

Solution

Here’s some code to help you filter the Camera resolutions to a sorted filtered shortlist:

Camera {
    id: camera
    function getFilteredResolutions() {
        let resolutions = supportedViewfinderResolutions();
        console.log(JSON.stringify(resolutions));
        // qml: [{"width":160,"height":120},
        //       {"width":176,"height":144},
        //       {"width":320,"height":240},
        //       {"width":352,"height":288},
        //       {"width":432,"height":240},
        //       {"width":640,"height":360},
        //       {"width":640,"height":480},
        //       {"width":800,"height":448},
        //       {"width":864,"height":480},
        //       {"width":800,"height":600},
        //       {"width":1024,"height":576},
        //       {"width":960,"height":720},
        //       {"width":1280,"height":720},
        //       {"width":1600,"height":896},
        //       {"width":1920,"height":1080}]
        let filteredResolutions = 
            resolutions
            .filter( r => [ 480, 576, 720, 1080 ].includes(r.height) )
            .sort( (r1, r2) => r1.width*r1.height - r2.width*r2.height );
         console.log(JSON.stringify(filteredResolutions));
         // qml: [{"width":640,"height":480},
         //       {"width":864,"height":480},
         //       {"width":1024,"height":576},
         //       {"width":960,"height":720},
         //       {"width":1280,"height":720},
         //       {"width":1920,"height":1080}]
         return filteredResolutions;
    }
}

You can see that the following functions:

.filter( r => [ 480, 576, 720, 1080 ].includes(r.height) )
.sort( (r1, r2) => r1.width*r1.height - r2.width*r2.height );

are used to:

  • filter the list with resolution heights you wish to accept,
  • sort the list in increasing order of megapixels.

As an enhancement, we could also limit the acceptable aspect ratios.

Answered By – Stephen Quan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published