From 4f6bf17407bc2fe89d42537fdf5fc431c82902db Mon Sep 17 00:00:00 2001 From: Nipun Kwatra Date: Fri, 10 Sep 2010 18:14:55 -0700 Subject: [PATCH] Enabling time lapse in setProfile, added setCaptureRate - Time lapse is automatically enabled in setProfile() if a time lapse profile is selected. Also audio setup is skipped for time lapse. - Added setCaptureRate() to set the frame capture rate, which may be different from the video playback rate. - Getting rid of enableTimeLapse() since setProfile() and setFrameCaptureDelay() do its job now. Change-Id: Ifd9f89cea0d05ffbefc22eac4ea5d34147cc1fbe --- media/java/android/media/MediaRecorder.java | 34 +++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java index 19b0c178ecc69..4c43baa7d6fd3 100644 --- a/media/java/android/media/MediaRecorder.java +++ b/media/java/android/media/MediaRecorder.java @@ -277,11 +277,17 @@ public class MediaRecorder setVideoFrameRate(profile.videoFrameRate); setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); setVideoEncodingBitRate(profile.videoBitRate); - setAudioEncodingBitRate(profile.audioBitRate); - setAudioChannels(profile.audioChannels); - setAudioSamplingRate(profile.audioSampleRate); setVideoEncoder(profile.videoCodec); - setAudioEncoder(profile.audioCodec); + if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW && + profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_1080P) { + // Enable time lapse. Also don't set audio for time lapse. + setParameter(String.format("time-lapse-enable=1")); + } else { + setAudioEncodingBitRate(profile.audioBitRate); + setAudioChannels(profile.audioChannels); + setAudioSamplingRate(profile.audioSampleRate); + setAudioEncoder(profile.audioCodec); + } } /** @@ -305,16 +311,24 @@ public class MediaRecorder } /** - * Enables time lapse capture and sets its parameters. This method should - * be called after setProfile(). + * Set video frame capture rate. This can be used to set a different video frame capture + * rate than the recorded video's playback rate. Currently this works only for time lapse mode. * - * @param timeBetweenTimeLapseFrameCaptureMs time between two captures of time lapse frames. + * @param fps Rate at which frames should be captured in frames per second. + * The fps can go as low as desired. However the fastest fps will be limited by the hardware. + * For resolutions that can be captured by the video camera, the fastest fps can be computed using + * {@link android.hardware.Camera.Parameters#getPreviewFpsRange(int[])}. For higher + * resolutions the fastest fps may be more restrictive. + * Note that the recorder cannot guarantee that frames will be captured at the + * given rate due to camera/encoder limitations. However it tries to be as close as + * possible. * @hide */ - public void enableTimeLapse(int timeBetweenTimeLapseFrameCaptureMs) { - setParameter(String.format("time-lapse-enable=1")); + public void setCaptureRate(double fps) { + double timeBetweenFrameCapture = 1 / fps; + int timeBetweenFrameCaptureMs = (int) (1000 * timeBetweenFrameCapture); setParameter(String.format("time-between-time-lapse-frame-capture=%d", - timeBetweenTimeLapseFrameCaptureMs)); + timeBetweenFrameCaptureMs)); } /**