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 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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("targetBitrate")) {
profile.videoBitRate = options.getInt("targetBitrate");
}

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

- `targetBitrate`. (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
7 changes: 7 additions & 0 deletions src/RNCamera.js
Expand Up @@ -72,6 +72,7 @@ type RecordingOptions = {
codec?: string,
mute?: boolean,
path?: string,
targetBitrate?: number,
};

type EventCallbackArgumentsType = {
Expand Down Expand Up @@ -338,6 +339,12 @@ export default class Camera extends React.Component<PropsType, StateType> {
}
}
}
if (options.targetBitrate) {
if (typeof options.targetBitrate !== 'number') {
// eslint-disable-next-line no-console
console.warn('Target Bitrate should be a positive integer');
}
}

const { captureAudio } = this.props

Expand Down