feat(ios): Expose an ability to change the frames per second via an fps option in record. (#2711)

This commit is contained in:
cinjon 2020-02-27 12:47:45 -05:00 committed by GitHub
parent adae4a294d
commit d60d201eb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 5 deletions

View File

@ -1050,11 +1050,8 @@ BOOL _sessionInterrupted = NO;
}
[connection setVideoOrientation:orientation];
BOOL recordAudio = [options valueForKey:@"mute"] == nil || ([options valueForKey:@"mute"] != nil && ![options[@"mute"] boolValue]);
// sound recording connection, we can easily turn it on/off without manipulating inputs, this prevents flickering.
// note that mute will also be set to true
// if captureAudio is set to false on the JS side.
@ -1097,6 +1094,47 @@ BOOL _sessionInterrupted = NO;
self.movieFileOutput.maxRecordedFileSize = [options[@"maxFileSize"] integerValue];
}
if (options[@"fps"]) {
AVCaptureDevice *device = [self.videoCaptureDeviceInput device];
AVCaptureDeviceFormat *activeFormat = device.activeFormat;
CMFormatDescriptionRef activeDescription = activeFormat.formatDescription;
CMVideoDimensions activeDimensions = CMVideoFormatDescriptionGetDimensions(activeDescription);
NSInteger fps = [options[@"fps"] integerValue];
CGFloat desiredFPS = (CGFloat)fps;
AVCaptureDeviceFormat *selectedFormat = nil;
int32_t activeWidth = activeDimensions.width;
int32_t maxWidth = 0;
for (AVCaptureDeviceFormat *format in [device formats]) {
CMFormatDescriptionRef formatDescription = format.formatDescription;
CMVideoDimensions formatDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
int32_t formatWidth = formatDimensions.width;
if (formatWidth != activeWidth || formatWidth < maxWidth) {
continue;
}
for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
if (range.minFrameRate <= desiredFPS && desiredFPS <= range.maxFrameRate) {
selectedFormat = format;
maxWidth = formatWidth;
}
}
}
if (selectedFormat) {
if ([device lockForConfiguration:nil]) {
device.activeFormat = selectedFormat;
device.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
device.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
[device unlockForConfiguration];
}
} else {
RCTLog(@"We could not find a suitable format for this device.");
}
}
if (options[@"codec"]) {
if (@available(iOS 10, *)) {
AVVideoCodecType videoCodecType = options[@"codec"];
@ -1123,7 +1161,6 @@ BOOL _sessionInterrupted = NO;
}
}
NSString *path = nil;
if (options[@"path"]) {
path = options[@"path"];
@ -2161,4 +2198,3 @@ BOOL _sessionInterrupted = NO;
}
@end

View File

@ -223,6 +223,7 @@ type RecordingOptions = {
maxFileSize?: number,
orientation?: Orientation,
quality?: number | string,
fps?: number,
codec?: string,
mute?: boolean,
path?: string,

1
types/index.d.ts vendored
View File

@ -412,6 +412,7 @@ interface RecordOptions {
/** iOS only */
codec?: keyof VideoCodec | VideoCodec[keyof VideoCodec];
fps?: number;
}
export interface RecordResponse {