Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.6.2
-
None
-
-
b8047fbd7 (dev)
-
Multimedia wk 15-16
Description
Per the QCameraFormat docs, "the camera will always try to use the highest frame rate supported by a certain video format." However, the code used to select the frame rate pick the first match it finds, rather than the best match. For example, when requesting a 240 fps camera on iOS, I get a 60 fps camera, since 60 fps is with the bounds specified by the [minFrameRate, maxFrameRate] request of [2, 240].
The current code, in qtmultimedia/src/plugins/multimedia/darwin/camera.avfcamerautility.mm line 125:]
{{ if (frameRateRange.minFrameRate >= cameraFormatPrivate->minFrameRate
&& frameRateRange.maxFrameRate <= cameraFormatPrivate->maxFrameRate) {}}
{{ newFormat = format;}}
{{ break;}}
{} }{}{}
Note that this picks the first match, not the best match. My revised code:
{{ AVCaptureDeviceFormat *newFormat = nil;
qreal newFormatMaxFrameRate = 0;
NSArray<AVCaptureDeviceFormat *> *formats = captureDevice.formats;
for (AVCaptureDeviceFormat *format in formats) {
CMFormatDescriptionRef formatDesc = format.formatDescription;
CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
FourCharCode cvPixFormat = CMVideoFormatDescriptionGetCodecType(formatDesc);
if (requiredCvPixFormat == cvPixFormat
&& cameraFormatPrivate->resolution == QSize(dim.width, dim.height)
&& (!cvFormatValidator || cvFormatValidator(cvPixFormat))) {
for (AVFrameRateRange *frameRateRange in format.videoSupportedFrameRateRanges) {
if (frameRateRange.minFrameRate >= cameraFormatPrivate->minFrameRate
&& frameRateRange.maxFrameRate <= cameraFormatPrivate->maxFrameRate
&& (newFormat == nil || newFormatMaxFrameRate < frameRateRange.maxFrameRate))
}
}}}
Note that this source file does contain a qt_find_best_framerate_match function that might be helpful.