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
- 1920x1080
- 1920x920
- 1440x1080
- 1536x864
- ...
- 208x144
- 176x144
How I can get correct list of video resolutions without exotical values like 1504x720 ? In ideal I want short list like
- 1920x1080
- 1280x720
- 720x576
If phone's camera support thesis resolutions
CodePudding user response:
You can try this;
QSize size = qApp->screens()[0]->size();
CodePudding user response:
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, 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":960,"height":720},
// {"width":1280,"height":720},
// {"width":1920,"height":1080}]
return filteredResolutions;
}
}
You can see that the following functions:
.filter( r => [ 480, 720, 1080 ].includes(r.height) )
.sort( (r1, r2) => r1.width*r1.height - r2.width*r2.height );
are used to (1) filter the list with resolution heights you wish to accept, (2) sort the list in increasing order of megapixels
as an enhancement, we could also limit the acceptable aspect ratios.