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

feat(android): add videoBitrate option for recordAsync #2055

Merged
merged 8 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,14 @@ private void setUpMediaRecorder(String path, int maxDuration, int maxFileSize, b
mMediaRecorder.setOutputFile(path);
mVideoPath = path;

CamcorderProfile camProfile;
if (CamcorderProfile.hasProfile(mCameraId, profile.quality)) {
setCamcorderProfile(CamcorderProfile.get(mCameraId, profile.quality), recordAudio);
camProfile = CamcorderProfile.get(mCameraId, profile.quality);
} else {
setCamcorderProfile(CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH), recordAudio);
camProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
}
camProfile.videoBitRate = profile.videoBitRate;
setCamcorderProfile(camProfile, recordAudio);

mMediaRecorder.setOrientationHint(calcCameraRotation(mOrientation != Constants.ORIENTATION_AUTO ? orientationEnumToRotation(mOrientation) : mDeviceOrientation));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,12 @@ private void setUpMediaRecorder(String path, int maxDuration, int maxFileSize, b
mMediaRecorder.setOutputFile(path);
mVideoPath = path;

if (CamcorderProfile.hasProfile(Integer.parseInt(mCameraId), profile.quality)) {
setCamcorderProfile(profile, recordAudio);
} else {
setCamcorderProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH), recordAudio);
CamcorderProfile camProfile = profile;
if (!CamcorderProfile.hasProfile(Integer.parseInt(mCameraId), profile.quality)) {
camProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
}
camProfile.videoBitRate = profile.videoBitRate;
setCamcorderProfile(camProfile, recordAudio);

mMediaRecorder.setOrientationHint(getOutputRotation());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public void record(ReadableMap options, final Promise promise, File cacheDirecto
if (options.hasKey("quality")) {
profile = RNCameraViewHelper.getCamcorderProfile(options.getInt("quality"));
}
if (options.hasKey("videoBitrate")) {
profile.videoBitRate = options.getInt("videoBitrate");
}

boolean recordAudio = true;
if (options.hasKey("mute")) {
Expand Down
4 changes: 4 additions & 0 deletions docs/RNCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ Supported options:
- `ios` Specifies capture settings suitable for CIF quality (352x288 pixel) video output.
- `android` Not supported.

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

- `orientation` (string or number). Specifies the orientation that us used for recording the video. Possible values: `"portrait"`, `"portraitUpsideDown"`, `"landscapeLeft"` or `"landscapeRight"`.

If nothing is passed the device's highest camera quality will be used as default.
Expand Down
8 changes: 8 additions & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type RecordingOptions = {
codec?: string,
mute?: boolean,
path?: string,
videoBitrate?: number,
};

type EventCallbackArgumentsType = {
Expand Down Expand Up @@ -339,6 +340,13 @@ export default class Camera extends React.Component<PropsType, StateType> {
}
}

if (__DEV__) {
if (options.videoBitrate && typeof options.videoBitrate !== 'number') {
// eslint-disable-next-line no-console
console.warn('Video Bitrate should be a positive integer');
}
}

const { captureAudio } = this.props

if (!captureAudio) {
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ interface RecordOptions {
mirrorVideo?: boolean;
path?: string;

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

/** iOS only */
codec?: keyof VideoCodec | VideoCodec[keyof VideoCodec];
}
Expand Down