· Enable video and audio configuration properties on CameraView component

- Audio bit rate
- Audio sample rate
- Audio channels
- Video bit rate
- Video Frame Rate
pull/354/head
Iván Álvarez Pereira 7 years ago
parent 229109f228
commit 323257db23
  1. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 21
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  4. 1
      cameraview/src/main/res/values/attrs.xml

@ -715,6 +715,12 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
mMediaRecorder.setVideoEncodingBitRate(getVideoBitRate()); mMediaRecorder.setVideoEncodingBitRate(getVideoBitRate());
} }
if(getVideoFrameRate() <= 0) {
mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
} else {
mMediaRecorder.setVideoFrameRate(getVideoFrameRate());
}
if (mAudio == Audio.ON) { if (mAudio == Audio.ON) {
if(getAudioSampleRate() <= 0) { if(getAudioSampleRate() <= 0) {
mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate); mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);

@ -62,6 +62,7 @@ abstract class CameraController implements
protected Size mPreviewSize; protected Size mPreviewSize;
protected int mPreviewFormat; protected int mPreviewFormat;
protected int mVideoBitRate; protected int mVideoBitRate;
protected int mVideoFrameRate;
protected int mAudioBitRate; protected int mAudioBitRate;
protected int mAudioSampleRate; protected int mAudioSampleRate;
protected int mAudioChannels; protected int mAudioChannels;
@ -298,6 +299,10 @@ abstract class CameraController implements
mVideoBitRate = videoBitRate; mVideoBitRate = videoBitRate;
} }
final void setVideoFrameRate(int videoBitRate) {
mVideoFrameRate = videoBitRate;
}
final void setAudioBitRate(int audioBitRate) { final void setAudioBitRate(int audioBitRate) {
mAudioBitRate = audioBitRate; mAudioBitRate = audioBitRate;
} }
@ -442,6 +447,10 @@ abstract class CameraController implements
return mVideoBitRate; return mVideoBitRate;
} }
final int getVideoFrameRate() {
return mVideoFrameRate;
}
final int getAudioBitRate() { final int getAudioBitRate() {
return mAudioBitRate; return mAudioBitRate;
} }

@ -117,6 +117,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
long videoMaxSize = (long) a.getFloat(R.styleable.CameraView_cameraVideoMaxSize, 0); long videoMaxSize = (long) a.getFloat(R.styleable.CameraView_cameraVideoMaxSize, 0);
int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0); int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0);
int videoBitRate = a.getInteger(R.styleable.CameraView_cameraVideoBitRate, 0); int videoBitRate = a.getInteger(R.styleable.CameraView_cameraVideoBitRate, 0);
int videoFrameRate = a.getInteger(R.styleable.CameraView_cameraVideoFrameRate, 0);
int audioBitRate = a.getInteger(R.styleable.CameraView_cameraAudioBitRate, 0); int audioBitRate = a.getInteger(R.styleable.CameraView_cameraAudioBitRate, 0);
int audioSampleRate = a.getInteger(R.styleable.CameraView_cameraAudioSampleRate, 0); int audioSampleRate = a.getInteger(R.styleable.CameraView_cameraAudioSampleRate, 0);
int audioChannels = a.getInteger(R.styleable.CameraView_cameraAudioChannels, 0); int audioChannels = a.getInteger(R.styleable.CameraView_cameraAudioChannels, 0);
@ -196,6 +197,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoMaxSize(videoMaxSize); setVideoMaxSize(videoMaxSize);
setVideoMaxDuration(videoMaxDuration); setVideoMaxDuration(videoMaxDuration);
setVideoBitRate(videoBitRate); setVideoBitRate(videoBitRate);
setVideoFrameRate(videoFrameRate);
setAudioBitRate(audioBitRate); setAudioBitRate(audioBitRate);
setAudioSampleRate(audioSampleRate); setAudioSampleRate(audioSampleRate);
setAudioChannels(audioChannels); setAudioChannels(audioChannels);
@ -1488,6 +1490,16 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
return mCameraController.isCapturingVideo(); return mCameraController.isCapturingVideo();
} }
/**
* Returns custom video frame rate, or 0 if no limit was set.
*
* @see #setVideoFrameRate(int)
* @return custom video frame rate
*/
public int getVideoFrameRate() {
return mCameraController.getVideoFrameRate();
}
/** /**
* Returns custom video bitrate, or 0 if no limit was set. * Returns custom video bitrate, or 0 if no limit was set.
* *
@ -1528,6 +1540,15 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mCameraController.setVideoBitRate(videoBitRate); mCameraController.setVideoBitRate(videoBitRate);
} }
/**
* Sets custom video frame rate for recording. Use 0 or negatives to disable.
*
* @param videoFrameRate The maximum video frame rate
*/
public void setVideoFrameRate(int videoFrameRate) {
mCameraController.setVideoFrameRate(videoFrameRate);
}
/** /**
* Sets custom audio bitrate for recording. Use 0 or negatives to disable. * Sets custom audio bitrate for recording. Use 0 or negatives to disable.
* *

@ -121,6 +121,7 @@
</attr> </attr>
<attr name="cameraVideoBitRate" format="integer" /> <attr name="cameraVideoBitRate" format="integer" />
<attr name="cameraVideoFrameRate" format="integer" />
<attr name="cameraAudioBitRate" format="integer" /> <attr name="cameraAudioBitRate" format="integer" />
<attr name="cameraAudioSampleRate" format="integer" /> <attr name="cameraAudioSampleRate" format="integer" />

Loading…
Cancel
Save