mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-08-27 11:41:09 +00:00
Merge pull request #1339 from n1ru4l/ios-codec-option
feat(rn-camera): add codec option for ios
This commit is contained in:
+9
-2
@@ -284,8 +284,13 @@ The promise will be fulfilled with an object with some of the following properti
|
||||
- `ios` Specifies capture settings suitable for VGA quality (640x480 pixel) video output. (Same as RNCamera.Constants.VideoQuality.480p).
|
||||
- `android` Quality level corresponding to the 480p (720 x 480) resolution but with video frame width set to 640.
|
||||
|
||||
If nothing is passed the device's highest camera quality will be used as default.
|
||||
|
||||
If nothing is passed the device's highest camera quality will be used as default.
|
||||
- `iOS` `codec`. This option specifies the codec of the output video. Setting the codec is only supported on `iOS >= 10`. The possible values are:
|
||||
- `RNCamera.Constants.VideoCodec['H264']`
|
||||
- `RNCamera.Constants.VideoCodec['JPEG']`
|
||||
- `RNCamera.Constants.VideoCodec['HVEC']` (`iOS >= 11`)
|
||||
- `RNCamera.Constants.VideoCodec['AppleProRes422']` (`iOS >= 11`)
|
||||
- `RNCamera.Constants.VideoCodec['AppleProRes4444']` (`iOS >= 11`)
|
||||
- `maxDuration` (float greater than 0). Specifies the maximum duration of the video to be recorded in seconds. If nothing is specified, no time limit will be used.
|
||||
|
||||
- `maxFileSize` (int greater than 0). Specifies the maximum file size, in bytes, of the video to be recorded. For 1mb, for example, use 1*1024*1024. If nothing is specified, no size limit will be used.
|
||||
@@ -296,6 +301,8 @@ The promise will be fulfilled with an object with some of the following properti
|
||||
|
||||
- `uri`: returns the path to the video saved on your app's cache directory.
|
||||
|
||||
- `iOS` `codec`: the codec of the recorded video. One of `RNCamera.Constants.VideoCodec`
|
||||
|
||||
#### `stopRecording: void`
|
||||
|
||||
Should be called after recordAsync() to make the promise be fulfilled and get the video uri.
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
@property (assign, nonatomic) float focusDepth;
|
||||
@property (assign, nonatomic) NSInteger whiteBalance;
|
||||
@property (nonatomic, assign, getter=isReadingBarCodes) BOOL barCodeReading;
|
||||
@property(assign, nonatomic) AVVideoCodecType videoCodecType;
|
||||
|
||||
- (id)initWithBridge:(RCTBridge *)bridge;
|
||||
- (void)updateType;
|
||||
|
||||
+22
-2
@@ -404,7 +404,21 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
|
||||
|
||||
AVCaptureConnection *connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
|
||||
[connection setVideoOrientation:[RNCameraUtils videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]];
|
||||
|
||||
|
||||
if (options[@"codec"]) {
|
||||
AVVideoCodecType videoCodecType = options[@"codec"];
|
||||
if (@available(iOS 10, *)) {
|
||||
if ([self.movieFileOutput.availableVideoCodecTypes containsObject:videoCodecType]) {
|
||||
[self.movieFileOutput setOutputSettings:@{AVVideoCodecKey:videoCodecType} forConnection:connection];
|
||||
self.videoCodecType = videoCodecType;
|
||||
} else {
|
||||
RCTLogWarn(@"%s: Video Codec '%@' is not supported on this device.", __func__, videoCodecType);
|
||||
}
|
||||
} else {
|
||||
RCTLogWarn(@"%s: Setting videoCodec is only supported above iOS version 10.", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_async(self.sessionQueue, ^{
|
||||
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingString:@"Camera"] withExtension:@".mov"];
|
||||
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:path];
|
||||
@@ -714,12 +728,18 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
|
||||
}
|
||||
}
|
||||
if (success && self.videoRecordedResolve != nil) {
|
||||
self.videoRecordedResolve(@{ @"uri": outputFileURL.absoluteString });
|
||||
AVVideoCodecType videoCodec = self.videoCodecType;
|
||||
if (videoCodec == nil) {
|
||||
videoCodec = [self.movieFileOutput.availableVideoCodecTypes firstObject];
|
||||
}
|
||||
|
||||
self.videoRecordedResolve(@{ @"uri": outputFileURL.absoluteString, @"codec":videoCodec });
|
||||
} else if (self.videoRecordedReject != nil) {
|
||||
self.videoRecordedReject(@"E_RECORDING_FAILED", @"An error occurred while recording a video.", error);
|
||||
}
|
||||
self.videoRecordedResolve = nil;
|
||||
self.videoRecordedReject = nil;
|
||||
self.videoCodecType = nil;
|
||||
|
||||
[self cleanupMovieFileCapture];
|
||||
// If face detection has been running prior to recording to file
|
||||
|
||||
@@ -49,6 +49,7 @@ typedef NS_ENUM(NSInteger, RNCameraVideoResolution) {
|
||||
@interface RNCameraManager : RCTViewManager <RCTBridgeModule>
|
||||
|
||||
+ (NSDictionary *)validBarCodeTypes;
|
||||
+ (NSDictionary *)validCodecTypes;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ RCT_EXPORT_VIEW_PROPERTY(onFacesDetected, RCTDirectEventBlock);
|
||||
@"480p": @(RNCameraVideo4x3),
|
||||
@"4:3": @(RNCameraVideo4x3),
|
||||
},
|
||||
@"VideoCodec": [[self class] validCodecTypes],
|
||||
@"BarCodeType" : [[self class] validBarCodeTypes],
|
||||
@"FaceDetection" : [[self class] faceDetectorConstants]
|
||||
};
|
||||
@@ -65,6 +66,24 @@ RCT_EXPORT_VIEW_PROPERTY(onFacesDetected, RCTDirectEventBlock);
|
||||
return @[@"onCameraReady", @"onMountError", @"onBarCodeRead", @"onFacesDetected"];
|
||||
}
|
||||
|
||||
+ (NSDictionary *)validCodecTypes
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return @{
|
||||
@"H264": AVVideoCodecTypeH264,
|
||||
@"HVEC": AVVideoCodecTypeHEVC,
|
||||
@"JPEG": AVVideoCodecTypeJPEG,
|
||||
@"AppleProRes422": AVVideoCodecTypeAppleProRes422,
|
||||
@"AppleProRes4444": AVVideoCodecTypeAppleProRes4444
|
||||
};
|
||||
} else {
|
||||
return @{
|
||||
@"H264": AVVideoCodecH264,
|
||||
@"JPEG": AVVideoCodecJPEG
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSDictionary *)validBarCodeTypes
|
||||
{
|
||||
return @{
|
||||
|
||||
@@ -35,6 +35,7 @@ type RecordingOptions = {
|
||||
maxDuration?: number,
|
||||
maxFileSize?: number,
|
||||
quality?: number | string,
|
||||
codec?: string,
|
||||
mute?: boolean,
|
||||
};
|
||||
|
||||
@@ -96,6 +97,7 @@ export default class Camera extends React.Component<PropsType> {
|
||||
AutoFocus: CameraManager.AutoFocus,
|
||||
WhiteBalance: CameraManager.WhiteBalance,
|
||||
VideoQuality: CameraManager.VideoQuality,
|
||||
VideoCodec: CameraManager.VideoCodec,
|
||||
BarCodeType: CameraManager.BarCodeType,
|
||||
FaceDetection: CameraManager.FaceDetection,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user