Example usage for android.hardware.camera2 CaptureRequest CONTROL_AE_TARGET_FPS_RANGE

List of usage examples for android.hardware.camera2 CaptureRequest CONTROL_AE_TARGET_FPS_RANGE

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureRequest CONTROL_AE_TARGET_FPS_RANGE.

Prototype

Key CONTROL_AE_TARGET_FPS_RANGE

To view the source code for android.hardware.camera2 CaptureRequest CONTROL_AE_TARGET_FPS_RANGE.

Click Source Link

Document

Range over which the auto-exposure routine can adjust the capture frame rate to maintain good exposure.

Only constrains auto-exposure (AE) algorithm, not manual control of CaptureRequest#SENSOR_EXPOSURE_TIME android.sensor.exposureTime and CaptureRequest#SENSOR_FRAME_DURATION android.sensor.frameDuration .

Units: Frames per second (FPS)

Range of valid values:
Any of the entries in CameraCharacteristics#CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES android.control.aeAvailableTargetFpsRanges

This key is available on all devices.

Usage

From source file:freed.cam.apis.camera2.modules.VideoModuleApi2.java

@TargetApi(VERSION_CODES.LOLLIPOP)
private void startPreviewVideo() {
    recordingFile = new File(cameraUiWrapper.getActivityInterface().getStorageHandler()
            .getNewFilePath(appSettingsManager.GetWriteExternal(), ".mp4"));
    mediaRecorder = new MediaRecorder();
    mediaRecorder.reset();/*from  ww w  . j  a  v a2 s  .c  om*/
    mediaRecorder.setMaxFileSize(3037822976L); //~2.8 gigabyte
    mediaRecorder.setMaxDuration(7200000); //2hours
    mediaRecorder.setOnErrorListener(new OnErrorListener() {
        @Override
        public void onError(MediaRecorder mr, int what, int extra) {
            Log.d(TAG, "error MediaRecorder:" + what + "extra:" + extra);
            cameraUiWrapper.GetModuleHandler()
                    .onRecorderstateChanged(I_RecorderStateChanged.STATUS_RECORDING_STOP);
            changeCaptureState(ModuleHandlerAbstract.CaptureStates.video_recording_stop);
        }
    });

    mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
        @Override
        public void onInfo(MediaRecorder mr, int what, int extra) {
            if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
                recordnextFile(mr);
            } else if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
                recordnextFile(mr);
            }
        }
    });

    if (cameraUiWrapper.GetAppSettingsManager().getApiString(AppSettingsManager.SETTING_LOCATION)
            .equals(KEYS.ON)) {
        Location location = cameraUiWrapper.getActivityInterface().getLocationHandler().getCurrentLocation();
        if (location != null)
            mediaRecorder.setLocation((float) location.getLatitude(), (float) location.getLongitude());
    }
    switch (currentVideoProfile.Mode) {

    case Normal:
    case Highspeed:
        if (currentVideoProfile.isAudioActive)
            mediaRecorder.setAudioSource(AudioSource.CAMCORDER);
        break;
    case Timelapse:
        break;
    }
    mediaRecorder.setVideoSource(VideoSource.SURFACE);

    mediaRecorder.setOutputFormat(OutputFormat.MPEG_4);
    setRecorderFilePath();

    mediaRecorder.setVideoEncodingBitRate(currentVideoProfile.videoBitRate);

    try {
        cameraHolder.SetParameterRepeating(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
                new Range<>(currentVideoProfile.videoFrameRate, currentVideoProfile.videoFrameRate));
    } catch (Exception e) {
        e.printStackTrace();
    }

    //  if(currentVideoProfile.Mode == VideoMediaProfile.VideoMode.SlowMO)
    //     int SlowFactor = currentVideoProfile.videoFrameRate /30;

    if (currentVideoProfile.videoFrameRate == 120 && currentVideoProfile.videoFrameWidth == 1920)
        mediaRecorder.setVideoFrameRate(60);
    else
        mediaRecorder.setVideoFrameRate(currentVideoProfile.videoFrameRate);

    /*setCaptureRate
            
    Added in API level 11
    void setCaptureRate (double fps)
    Set video frame capture rate. This can be used to set a different video frame capture rate than the recorded video's playback rate.
    !!!!!! This method also sets the recording mode to time lapse.!!!!!
    In time lapse video recording, only video is recorded.
    Audio related parameters are ignored when a time lapse recording session starts, if an application sets them.*/
    //mediaRecorder.setCaptureRate((double)currentVideoProfile.videoFrameRate);
    mediaRecorder.setVideoSize(currentVideoProfile.videoFrameWidth, currentVideoProfile.videoFrameHeight);
    try {
        mediaRecorder.setVideoEncoder(currentVideoProfile.videoCodec);
    } catch (IllegalArgumentException ex) {
        mediaRecorder.reset();
        cameraUiWrapper.GetCameraHolder().SendUIMessage("VideoCodec not Supported");
    }

    switch (currentVideoProfile.Mode) {
    case Normal:
    case Highspeed:
        if (currentVideoProfile.isAudioActive) {
            try {
                mediaRecorder.setAudioEncoder(currentVideoProfile.audioCodec);
            } catch (IllegalArgumentException ex) {
                mediaRecorder.reset();
                cameraUiWrapper.GetCameraHolder().SendUIMessage("AudioCodec not Supported");
            }
            mediaRecorder.setAudioChannels(currentVideoProfile.audioChannels);
            mediaRecorder.setAudioEncodingBitRate(currentVideoProfile.audioBitRate);
            mediaRecorder.setAudioSamplingRate(currentVideoProfile.audioSampleRate);
        }
        break;
    case Timelapse:
        float frame = 30;
        if (!appSettingsManager.getApiString(AppSettingsManager.TIMELAPSEFRAME).equals(""))
            frame = Float.parseFloat(
                    appSettingsManager.getApiString(AppSettingsManager.TIMELAPSEFRAME).replace(",", "."));
        else
            appSettingsManager.setApiString(AppSettingsManager.TIMELAPSEFRAME, "" + frame);
        mediaRecorder.setCaptureRate(frame);
        break;
    }
    try {
        mediaRecorder.prepare();
    } catch (IOException ex) {
        ex.printStackTrace();
        cameraUiWrapper.GetModuleHandler().onRecorderstateChanged(I_RecorderStateChanged.STATUS_RECORDING_STOP);
        changeCaptureState(ModuleHandlerAbstract.CaptureStates.video_recording_stop);
        return;
    }
    recorderSurface = mediaRecorder.getSurface();
    cameraHolder.CaptureSessionH.AddSurface(recorderSurface, true);

    if (currentVideoProfile.Mode != VideoMediaProfile.VideoMode.Highspeed)
        cameraHolder.CaptureSessionH.CreateCaptureSession(previewrdy);
    else
        cameraHolder.CaptureSessionH.CreateHighSpeedCaptureSession(previewrdy);
}