カスタム フレーム レートを選択するためのコードは次のとおりです。Apple RosyWriterにチェックを追加して、現在のフォーマットが選択した FPS をサポートしているかどうかを確認します。
- (void)configureCamera:(AVCaptureDevice *)videoDevice withFrameRate:(int)desiredFrameRate
{
BOOL isFPSSupported = NO;
AVCaptureDeviceFormat *currentFormat = [videoDevice activeFormat];
for ( AVFrameRateRange *range in currentFormat.videoSupportedFrameRateRanges ) {
if ( range.maxFrameRate >= desiredFrameRate && range.minFrameRate <= desiredFrameRate ) {
isFPSSupported = YES;
break;
}
}
if( isFPSSupported ) {
if ( [videoDevice lockForConfiguration:NULL] ) {
videoDevice.activeVideoMaxFrameDuration = CMTimeMake( 1, desiredFrameRate );
videoDevice.activeVideoMinFrameDuration = CMTimeMake( 1, desiredFrameRate );
[videoDevice unlockForConfiguration];
}
}
}
現在のフォーマット ( activeFormat
) が選択した FPS をサポートしていない場合は、以下のコードを使用して変更activeFormat
し、FPS を選択してください。ただし、ニーズに合わせてフォーマット ディメンションを取得する必要があります。
- (void)configureCamera:(AVCaptureDevice *)device withFrameRate:(int)desiredFrameRate
{
AVCaptureDeviceFormat *desiredFormat = nil;
for ( AVCaptureDeviceFormat *format in [device formats] ) {
for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) {
if ( range.maxFrameRate >= desiredFrameRate && range.minFrameRate <= desiredFrameRate ) {
desiredFormat = format;
goto desiredFormatFound;
}
}
}
desiredFormatFound:
if ( desiredFormat ) {
if ( [device lockForConfiguration:NULL] == YES ) {
device.activeFormat = desiredFormat ;
device.activeVideoMinFrameDuration = CMTimeMake ( 1, desiredFrameRate );
device.activeVideoMaxFrameDuration = CMTimeMake ( 1, desiredFrameRate );
[device unlockForConfiguration];
}
}
}
注: を使用しAVCaptureConnection
videoMinFrameDuration
て FPS を設定することは非推奨です。