How can we change frame rates of an existing video as well as while capturing video from iPhone?
Can we implement it using either AVFoundation framework or by any third party library?
Code for choosing custom frame rate is as below - Added checks to Apple RosyWriter to verify if current format supports FPS chosen
- (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];
}
}
}
In case current format ( activeFormat
) didn't support your chosen FPS, use below code to change activeFormat
and then chose FPS. Will need to get format dimension to match your needs though.
- (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];
}
}
}
Note: Usage of AVCaptureConnection
videoMinFrameDuration
to set FPS is deprecated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.