Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
feat(ios): videoBitrate option for iOS (#2504)
Browse files Browse the repository at this point in the history
* Update RNCamera.m

Add videoBitrate option for ios, setting video bitrate requires a codec to be set

* Update API documentation

* Update documentation

* Update typings
  • Loading branch information
xHeinrich authored and sibelius committed Sep 24, 2019
1 parent 0026b46 commit 38a5ffb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 1 addition & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ interface RecordOptions {
mute?: boolean;
mirrorVideo?: boolean;
path?: string;

/** Android only */
videoBitrate?: number;

/** iOS only */
Expand Down Expand Up @@ -266,4 +264,4 @@ const isRecording = await isRecording();
} */
```

---
---
2 changes: 1 addition & 1 deletion docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Supported options:

- `videoBitrate`. (int greater than 0) This option specifies a desired video bitrate. For example, 5\*1000\*1000 would be 5Mbps.

- `ios` Not supported.
- `ios` Supported however requires that the codec key is also set.
- `android` Supported.

- `orientation` (string or number). Specifies the orientation that us used for recording the video. Possible values: `"portrait"`, `"portraitUpsideDown"`, `"landscapeLeft"` or `"landscapeRight"`.
Expand Down
29 changes: 20 additions & 9 deletions ios/RN/RNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,28 @@ - (void)record:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve r
[connection setVideoOrientation:orientation];

if (options[@"codec"]) {
if (@available(iOS 10, *)) {
AVVideoCodecType videoCodecType = options[@"codec"];
if ([self.movieFileOutput.availableVideoCodecTypes containsObject:videoCodecType]) {
[self.movieFileOutput setOutputSettings:@{AVVideoCodecKey:videoCodecType} forConnection:connection];
self.videoCodecType = videoCodecType;
} else {
RCTLogWarn(@"%s: Setting videoCodec is only supported above iOS version 10.", __func__);
if (@available(iOS 10, *)) {
AVVideoCodecType videoCodecType = options[@"codec"];
if ([self.movieFileOutput.availableVideoCodecTypes containsObject:videoCodecType]) {
self.videoCodecType = videoCodecType;
if(options[@"videoBitrate"]) {
NSString *videoBitrate = options[@"videoBitrate"];
[self.movieFileOutput setOutputSettings:@{
AVVideoCodecKey:videoCodecType,
AVVideoCompressionPropertiesKey:
@{
AVVideoAverageBitRateKey:videoBitrate
}
} forConnection:connection];
} else {
[self.movieFileOutput setOutputSettings:@{AVVideoCodecKey:videoCodecType} forConnection:connection];
}
} else {
RCTLogWarn(@"%s: Setting videoCodec is only supported above iOS version 10.", __func__);
}
}
}
}

dispatch_async(self.sessionQueue, ^{
[self updateFlashMode];
NSString *path = nil;
Expand Down
2 changes: 0 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ interface RecordOptions {
mute?: boolean;
mirrorVideo?: boolean;
path?: string;

/** Android only */
videoBitrate?: number;

/** iOS only */
Expand Down

0 comments on commit 38a5ffb

Please sign in to comment.