From e6d8a74b306d39b6b834549c67a6dfdc31f4575a Mon Sep 17 00:00:00 2001 From: Mohamed Hamdan Date: Thu, 18 Jun 2020 14:01:16 +0300 Subject: [PATCH] Add setter method for capture rate, can be used to record timelapse video --- .../otaliastudios/cameraview/CameraView.java | 20 +++++++++++++++++++ .../otaliastudios/cameraview/VideoResult.java | 1 + .../cameraview/engine/CameraBaseEngine.java | 13 ++++++++++++ .../cameraview/engine/CameraEngine.java | 3 +++ .../cameraview/video/FullVideoRecorder.java | 1 + 5 files changed, 38 insertions(+) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index 89eb0016e..38fba0585 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1575,6 +1575,26 @@ public int getVideoBitRate() { return mCameraEngine.getVideoBitRate(); } + /** + * Sets the capture rate in frame per second for video capturing. + * it's can used to capture timelapse video + * Will be used by {@link #takeVideo(File)}. + * + * @param captureRate desired capture rate + */ + public void setVideoCaptureRate(double captureRate) { + mCameraEngine.setVideoCaptureRate(captureRate); + } + + /** + * Returns the current video bit rate. + * @return current bit rate + */ + @SuppressWarnings("unused") + public double getVideoCaptureRate() { + return mCameraEngine.getVideoCaptureRate(); + } + /** * A flag to control the behavior when calling {@link #setPreviewFrameRate(float)}. * diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java index 45daf3ec7..616329946 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java @@ -41,6 +41,7 @@ public static class Stub { public int maxDuration; public int endReason; public int videoBitRate; + public double videoCaptureRate; public int videoFrameRate; public int audioBitRate; } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java index a751f4b0f..acb3bae2a 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java @@ -85,6 +85,7 @@ public abstract class CameraBaseEngine extends CameraEngine { private long mVideoMaxSize; private int mVideoMaxDuration; private int mVideoBitRate; + private double mVideoCaptureRate; private int mAudioBitRate; private long mAutoFocusResetDelayMillis; private int mSnapshotMaxWidth; // in REF_VIEW like SizeSelectors @@ -245,6 +246,16 @@ public final int getVideoBitRate() { return mVideoBitRate; } + @Override + public final void setVideoCaptureRate(double videoCaptureRate) { + mVideoCaptureRate = videoCaptureRate; + } + + @Override + public final double getVideoCaptureRate() { + return mVideoCaptureRate; + } + @Override public final void setAudioCodec(@NonNull AudioCodec codec) { mAudioCodec = codec; @@ -601,6 +612,7 @@ public void run() { stub.maxSize = mVideoMaxSize; stub.maxDuration = mVideoMaxDuration; stub.videoBitRate = mVideoBitRate; + stub.videoCaptureRate = mVideoCaptureRate; stub.audioBitRate = mAudioBitRate; onTakeVideo(stub); } @@ -626,6 +638,7 @@ public void run() { stub.location = mLocation; stub.facing = mFacing; stub.videoBitRate = mVideoBitRate; + stub.videoCaptureRate = mVideoCaptureRate; stub.audioBitRate = mAudioBitRate; stub.audio = mAudio; stub.maxSize = mVideoMaxSize; diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java index e695b61c9..fb45a5ceb 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java @@ -635,6 +635,9 @@ public final void onSurfaceDestroyed() { public abstract void setVideoBitRate(int videoBitRate); public abstract int getVideoBitRate(); + public abstract void setVideoCaptureRate(double videoCaptureRate); + public abstract double getVideoCaptureRate(); + public abstract void setAudioBitRate(int audioBitRate); public abstract int getAudioBitRate(); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java index 1bcca1286..47e3e7499 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java @@ -215,6 +215,7 @@ private boolean prepareMediaRecorder(@NonNull VideoResult.Stub stub, flip ? stub.size.getHeight() : stub.size.getWidth(), flip ? stub.size.getWidth() : stub.size.getHeight()); mMediaRecorder.setVideoFrameRate(stub.videoFrameRate); + mMediaRecorder.setCaptureRate(stub.videoCaptureRate); mMediaRecorder.setVideoEncoder(mProfile.videoCodec); mMediaRecorder.setVideoEncodingBitRate(stub.videoBitRate);