Java Code Examples for android.media.CamcorderProfile#get()

The following examples show how to use android.media.CamcorderProfile#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamcorderProfiles.java    From Lassi-Android with MIT License 6 votes vote down vote up
/**
 * Returns a CamcorderProfile that's somewhat coherent with the target size,
 * to ensure we get acceptable video/audio parameters for MediaRecorders (most notably the bitrate).
 *
 * @param cameraId   the camera id
 * @param targetSize the target video size
 * @return a profile
 */
@NonNull
static CamcorderProfile get(int cameraId, @NonNull Size targetSize) {
    final int targetArea = targetSize.getWidth() * targetSize.getHeight();
    List<Size> sizes = new ArrayList<>(sizeToProfileMap.keySet());
    Collections.sort(sizes, new Comparator<Size>() {
        @Override
        public int compare(Size s1, Size s2) {
            int a1 = Math.abs(s1.getWidth() * s1.getHeight() - targetArea);
            int a2 = Math.abs(s2.getWidth() * s2.getHeight() - targetArea);
            //noinspection UseCompareMethod
            return (a1 < a2) ? -1 : ((a1 == a2) ? 0 : 1);
        }
    });
    while (sizes.size() > 0) {
        Size candidate = sizes.remove(0);
        //noinspection ConstantConditions
        int quality = sizeToProfileMap.get(candidate);
        if (CamcorderProfile.hasProfile(cameraId, quality)) {
            return CamcorderProfile.get(cameraId, quality);
        }
    }
    // Should never happen, but fallback to low.
    return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
}
 
Example 2
Source File: CameraUtils.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(int currentCameraId, long maximumFileSize, int minimumDurationInSeconds) {
    if (maximumFileSize <= 0)
        return CamcorderProfile.get(currentCameraId, CameraConfig.MEDIA_QUALITY_HIGHEST);

    int[] qualities = new int[]{CameraConfig.MEDIA_QUALITY_HIGHEST,
            CameraConfig.MEDIA_QUALITY_HIGH, CameraConfig.MEDIA_QUALITY_MEDIUM,
            CameraConfig.MEDIA_QUALITY_LOW, CameraConfig.MEDIA_QUALITY_LOWEST};

    CamcorderProfile camcorderProfile;
    for (int i = 0; i < qualities.length; ++i) {
        camcorderProfile = CameraUtils.getCamcorderProfile(qualities[i], currentCameraId);
        double fileSize = CameraUtils.calculateApproximateVideoSize(camcorderProfile, minimumDurationInSeconds);

        if (fileSize > maximumFileSize) {
            long minimumRequiredBitRate = calculateMinimumRequiredBitRate(camcorderProfile, maximumFileSize, minimumDurationInSeconds);

            if (minimumRequiredBitRate >= camcorderProfile.videoBitRate / 4 && minimumRequiredBitRate <= camcorderProfile.videoBitRate) {
                camcorderProfile.videoBitRate = (int) minimumRequiredBitRate;
                return camcorderProfile;
            }
        } else return camcorderProfile;
    }
    return CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_LOWEST, currentCameraId);
}
 
Example 3
Source File: CameraSource.java    From Camera2Vision with Apache License 2.0 5 votes vote down vote up
public boolean canRecordVideo(@VideoMode int videoMode) {
    try {
        CamcorderProfile.get(getIdForRequestedCamera(mFacing), videoMode);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 4
Source File: CameraWrapper.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
public CamcorderProfile getBaseRecordingProfile() {
    CamcorderProfile returnProfile;
    if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
        returnProfile = getDefaultRecordingProfile();
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
    } else {
        returnProfile = getDefaultRecordingProfile();
    }
    return returnProfile;
}
 
Example 5
Source File: VideoCapture.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/** Set audio record parameters by CamcorderProfile */
private void setAudioParametersByCamcorderProfile(Size currentResolution, String cameraId) {
    CamcorderProfile profile;
    boolean isCamcorderProfileFound = false;

    for (int quality : CamcorderQuality) {
        if (CamcorderProfile.hasProfile(Integer.parseInt(cameraId), quality)) {
            profile = CamcorderProfile.get(Integer.parseInt(cameraId), quality);
            if (currentResolution.getWidth() == profile.videoFrameWidth
                && currentResolution.getHeight() == profile.videoFrameHeight) {
                mAudioChannelCount = profile.audioChannels;
                mAudioSampleRate = profile.audioSampleRate;
                mAudioBitRate = profile.audioBitRate;
                isCamcorderProfileFound = true;
                break;
            }
        }
    }

    // In case no corresponding camcorder profile can be founded, * get default value from
    // VideoCaptureConfig.
    if (!isCamcorderProfileFound) {
        VideoCaptureConfig config = (VideoCaptureConfig) getUseCaseConfig();
        mAudioChannelCount = config.getAudioChannelCount();
        mAudioSampleRate = config.getAudioSampleRate();
        mAudioBitRate = config.getAudioBitRate();
    }
}
 
Example 6
Source File: VideoRecordSurface.java    From VideoRecord with Apache License 2.0 5 votes vote down vote up
private void initParameters() {
    CamcorderProfile mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
    Camera.Parameters mParams = mCamera.getParameters();
    mParams.setPreviewSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
    size = mParams.getPreviewSize();
    List<String> focusModes = mParams.getSupportedFocusModes();
    if (focusModes.contains("continuous-video")) {
        mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
    mCamera.setParameters(mParams);
}
 
Example 7
Source File: CameraWrapper.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
private CamcorderProfile getDefaultRecordingProfile() {
    CamcorderProfile highProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    if (highProfile != null) {
        return highProfile;
    }
    CamcorderProfile lowProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
    if (lowProfile != null) {
        return lowProfile;
    }
    throw new RuntimeException("No quality level found");
}
 
Example 8
Source File: CameraHelper.java    From RecordVideo with Apache License 2.0 5 votes vote down vote up
/**
     * 获取相机录制CIF质量视频的宽高
     * @param cameraId
     * @param camera
     * @return
     */
    public static Camera.Size getCameraPreviewSizeForVideo(int cameraId, Camera camera) {
        CamcorderProfile cameraProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        return camera.new Size(cameraProfile.videoFrameWidth, cameraProfile.videoFrameHeight);



//        Camera.Parameters parameters = camera.getParameters();
//        List<Camera.Size> supportedVideoSizeList = parameters.getSupportedVideoSizes();
//        if (supportedVideoSizeList == null) {
//            supportedVideoSizeList = parameters.getSupportedPreviewSizes();
//        }
////        for (Camera.Size size : supportedVideoSizeList) {
////        }
//        return supportedVideoSizeList.get(supportedVideoSizeList.size() - 4);



//        Camera.Size currentSize = parameters.getPreviewSize();
//        Log.d(TAG, "current camera preview size w: " + currentSize.width + "---h: " + currentSize.height);
//
//        Camera.Size willSetSize = currentSize;
//        Camera.Size tempSize = null;
//        List<Camera.Size> sizeList = parameters.getSupportedPreviewSizes();
//        for (Camera.Size size : sizeList) {
//            Log.d(TAG, "supported camera preview size w: " + size.width + "---h: " + size.height);
//            // 如果宽高符合4:3要求,并且宽度比之前获得的宽度大,则取当前这个
//            if (1.0f * size.width / size.height == ratio) {
//                if (tempSize == null || size.width >= tempSize.width) {
//                    tempSize = size;
//                }
//            }
//        }
//
//        if (tempSize != null)
//            willSetSize = tempSize;
//
//        return willSetSize;
    }
 
Example 9
Source File: CameraSource.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
public boolean canRecordVideo(@VideoMode int videoMode) {
    try {
        CamcorderProfile.get(getIdForRequestedCamera(mFacing), videoMode);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 10
Source File: CameraWrapper.java    From LandscapeVideoCamera with Apache License 2.0 5 votes vote down vote up
private CamcorderProfile getDefaultRecordingProfile() {
    CamcorderProfile highProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    if (highProfile != null) {
        return highProfile;
    }
    CamcorderProfile lowProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
    if (lowProfile != null) {
        return lowProfile;
    }
    throw new RuntimeException("No quality level found");
}
 
Example 11
Source File: CameraEngine.java    From In77Camera with MIT License 4 votes vote down vote up
private boolean prepareMediaRecorder() {
        try {
           // final Activity activity = getActivity();
            //if (null == activity) return false;
            //final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity;

           // setCameraDisplayOrientation(mCamera.getParameters());
            mMediaRecorder = new MediaRecorder();
            camera.stopPreview();
            camera.unlock();
            mMediaRecorder.setCamera(camera);

  //          boolean canUseAudio = true;
            //boolean audioEnabled = !mInterface.audioDisabled();
            //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            //    canUseAudio = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;

//            if (canUseAudio && audioEnabled) {
                mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
//            } else if (audioEnabled) {
//                Toast.makeText(getActivity(), R.string.mcam_no_audio_access, Toast.LENGTH_LONG).show();
//            }
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

            final CamcorderProfile profile = CamcorderProfile.get(currentCameraId, CamcorderProfile.QUALITY_HIGH);
            mMediaRecorder.setOutputFormat(profile.fileFormat);
            mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
            mMediaRecorder.setVideoSize(previewSize.width, previewSize.height);
            mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
            mMediaRecorder.setVideoEncoder(profile.videoCodec);

            mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
            mMediaRecorder.setAudioChannels(profile.audioChannels);
            mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
            mMediaRecorder.setAudioEncoder(profile.audioCodec);


            Uri uri = Uri.fromFile(FileUtils.makeTempFile(
                    new File(Environment.getExternalStorageDirectory(),
                            "/Omoshiroi/videos").getAbsolutePath(),
                    "VID_", ".mp4"));

            mMediaRecorder.setOutputFile(uri.getPath());

//            if (captureInterface.maxAllowedFileSize() > 0) {
//                mMediaRecorder.setMaxFileSize(captureInterface.maxAllowedFileSize());
//                mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
//                    @Override
//                    public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
//                        if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
//                            Toast.makeText(getActivity(), R.string.mcam_file_size_limit_reached, Toast.LENGTH_SHORT).show();
//                            stopRecordingVideo(false);
//                        }
//                    }
//                });
//            }

            mMediaRecorder.setOrientationHint(90);
     //       mMediaRecorder.setPreviewDisplay(mPreviewView.getHolder().getSurface());

            mMediaRecorder.prepare();
            return true;

        } catch (Exception e) {
            camera.lock();
            e.printStackTrace();
            return false;
        }
    }
 
Example 12
Source File: VideoModule.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
private void readVideoPreferences()
{
    // The preference stores values from ListPreference and is thus string type for all values.
    // We need to convert it to int manually.
    SettingsManager settingsManager = mActivity.getSettingsManager();
    String videoQualityKey = isCameraFrontFacing() ? Keys.KEY_VIDEO_QUALITY_FRONT
            : Keys.KEY_VIDEO_QUALITY_BACK;
    String videoQuality = settingsManager
            .getString(SettingsManager.SCOPE_GLOBAL, videoQualityKey);
    int quality = SettingsUtil.getVideoQuality(videoQuality, mCameraId);
    Log.d(TAG, "Selected video quality for '" + videoQuality + "' is " + quality);

    // Set video quality.
    Intent intent = mActivity.getIntent();
    if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY))
    {
        int extraVideoQuality =
                intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
        if (extraVideoQuality > 0)
        {
            quality = CamcorderProfile.QUALITY_HIGH;
        } else
        {  // 0 is mms.
            quality = CamcorderProfile.QUALITY_LOW;
        }
    }

    // Set video duration limit. The limit is read from the preference,
    // unless it is specified in the intent.
    if (intent.hasExtra(MediaStore.EXTRA_DURATION_LIMIT))
    {
        int seconds =
                intent.getIntExtra(MediaStore.EXTRA_DURATION_LIMIT, 0);
        mMaxVideoDurationInMs = 1000 * seconds;
    } else
    {
        mMaxVideoDurationInMs = SettingsUtil.getMaxVideoDuration(mActivity
                .getAndroidContext());
    }

    // If quality is not supported, request QUALITY_HIGH which is always supported.
    if (CamcorderProfile.hasProfile(mCameraId, quality) == false)
    {
        quality = CamcorderProfile.QUALITY_HIGH;
    }
    mProfile = CamcorderProfile.get(mCameraId, quality);
    mPreferenceRead = true;
}
 
Example 13
Source File: VideoDataFactory.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
public VideoItemData fromCursor(Cursor c)
{
    long id = c.getLong(VideoDataQuery.COL_ID);
    String title = c.getString(VideoDataQuery.COL_TITLE);
    String mimeType = c.getString(VideoDataQuery.COL_MIME_TYPE);
    long creationDateInMilliSeconds = c.getLong(VideoDataQuery.COL_DATE_TAKEN);
    long lastModifiedDateInSeconds = c.getLong(VideoDataQuery.COL_DATE_MODIFIED);
    Date creationDate = new Date(creationDateInMilliSeconds);
    Date lastModifiedDate = new Date(lastModifiedDateInSeconds * 1000);

    String filePath = c.getString(VideoDataQuery.COL_DATA);
    int width = c.getInt(VideoDataQuery.COL_WIDTH);
    int height = c.getInt(VideoDataQuery.COL_HEIGHT);

    Size dimensions;

    // If the media store doesn't contain a width and a height, use the width and height
    // of the default camera mode instead. When the metadata loader runs, it will set the
    // correct values.
    if (width == 0 || height == 0)
    {
        Log.w(TAG, "failed to retrieve width and height from the media store, defaulting " +
                " to camera profile");
        CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        if (profile != null)
        {
            dimensions = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
        } else
        {
            Log.w(TAG, "Video profile was null, defaulting to unknown width and height.");
            dimensions = UNKNOWN_SIZE;
        }
    } else
    {
        dimensions = new Size(width, height);
    }

    long sizeInBytes = c.getLong(VideoDataQuery.COL_SIZE);
    double latitude = c.getDouble(VideoDataQuery.COL_LATITUDE);
    double longitude = c.getDouble(VideoDataQuery.COL_LONGITUDE);
    long videoDurationMillis = c.getLong(VideoDataQuery.COL_DURATION);
    Location location = Location.from(latitude, longitude);

    Uri uri = VideoDataQuery.CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).build();

    return new VideoItemData(
            id,
            title,
            mimeType,
            creationDate,
            lastModifiedDate,
            filePath,
            uri,
            dimensions,
            sizeInBytes,
            0 /* orientation */,
            location,
            videoDurationMillis);
}
 
Example 14
Source File: CameraEngine.java    From Fatigue-Detection with MIT License 4 votes vote down vote up
private boolean prepareMediaRecorder() {
        try {
           // final Activity activity = getActivity();
            //if (null == activity) return false;
            //final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity;

           // setCameraDisplayOrientation(mCamera.getParameters());
            mMediaRecorder = new MediaRecorder();
            camera.stopPreview();
            camera.unlock();
            mMediaRecorder.setCamera(camera);

  //          boolean canUseAudio = true;
            //boolean audioEnabled = !mInterface.audioDisabled();
            //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            //    canUseAudio = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;

//            if (canUseAudio && audioEnabled) {
                mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
//            } else if (audioEnabled) {
//                Toast.makeText(getActivity(), R.string.mcam_no_audio_access, Toast.LENGTH_LONG).show();
//            }
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

            final CamcorderProfile profile = CamcorderProfile.get(currentCameraId, CamcorderProfile.QUALITY_HIGH);
            mMediaRecorder.setOutputFormat(profile.fileFormat);
            mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
            mMediaRecorder.setVideoSize(previewSize.width, previewSize.height);
            mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
            mMediaRecorder.setVideoEncoder(profile.videoCodec);

            mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
            mMediaRecorder.setAudioChannels(profile.audioChannels);
            mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
            mMediaRecorder.setAudioEncoder(profile.audioCodec);


            Uri uri = Uri.fromFile(FileUtils.makeTempFile(
                    new File(Environment.getExternalStorageDirectory(),
                            "/Omoshiroi/videos").getAbsolutePath(),
                    "VID_", ".mp4"));

            mMediaRecorder.setOutputFile(uri.getPath());

//            if (captureInterface.maxAllowedFileSize() > 0) {
//                mMediaRecorder.setMaxFileSize(captureInterface.maxAllowedFileSize());
//                mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
//                    @Override
//                    public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
//                        if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
//                            Toast.makeText(getActivity(), R.string.mcam_file_size_limit_reached, Toast.LENGTH_SHORT).show();
//                            stopRecordingVideo(false);
//                        }
//                    }
//                });
//            }

            mMediaRecorder.setOrientationHint(90);
     //       mMediaRecorder.setPreviewDisplay(mPreviewView.getHolder().getSurface());

            mMediaRecorder.prepare();
            return true;

        } catch (Exception e) {
            camera.lock();
            e.printStackTrace();
            return false;
        }
    }
 
Example 15
Source File: CameraUtils.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(@CameraConfig.MediaQuality int mediaQuality, int cameraId) {
    if (Build.VERSION.SDK_INT > 10) {
        if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGH) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_MEDIUM) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOW) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    } else {
        if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGH) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_MEDIUM) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOW) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    }
}
 
Example 16
Source File: CameraService.java    From glass_snippets with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
	camera = Camera.open();
	try {
		mediaRecorder = new MediaRecorder();

		List<int[]> fps = camera.getParameters().getSupportedPreviewFpsRange();
		int preview_fps[] = fps.get(0);

		for (int i[] : camera.getParameters().getSupportedPreviewFpsRange())
			preview_fps = (mCaptureRate <= i[1] && mCaptureRate > i[0]) ? i : preview_fps;

		Camera.Parameters param = camera.getParameters();
		param.setVideoStabilization(true);
		param.setPreviewFpsRange(preview_fps[0], preview_fps[1]);
		camera.setParameters(param);
		camera.unlock();

		mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
		mediaRecorder.setCamera(camera);

		mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
		CamcorderProfile profile;
		if (mCaptureRate > 25) {
			mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
			profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
		} else {
			profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
			mediaRecorder.setCaptureRate(mCaptureRate);
			profile.videoFrameRate = ((int) Math.ceil(mCaptureRate));
		}

		mediaRecorder.setProfile(profile);
		mediaRecorder.setOutputFile(mOutFile);

		mediaRecorder.prepare();
		mediaRecorder.start();

		ScaleAnimation a = new ScaleAnimation(3, 2, 3, 2);
		a.setDuration(2000);
		surfaceView.startAnimation(a);

		Log.i(TAG, String.format("recording %s with rate %.2f", mOutFile, mCaptureRate));
	} catch(Exception e) {
		onDestroy();
		Log.d(TAG, e.toString());
	}
}
 
Example 17
Source File: CameraActivity.java    From cordova-plugin-camera-preview with MIT License 4 votes vote down vote up
public void startRecord(final String filePath, final String camera, final int width, final int height, final int quality, final boolean withFlash){
  Log.d(TAG, "CameraPreview startRecord camera: " + camera + " width: " + width + ", height: " + height + ", quality: " + quality);
  Activity activity = getActivity();
  muteStream(true, activity);
  if (this.mRecordingState == RecordingState.STARTED) {
    Log.d(TAG, "Already Recording");
    return;
  }

  this.recordFilePath = filePath;
  int mOrientationHint = calculateOrientationHint();
  int videoWidth = 0;//set whatever
  int videoHeight = 0;//set whatever

  Camera.Parameters cameraParams = mCamera.getParameters();
  if (withFlash) {
    cameraParams.setFlashMode(withFlash ? Camera.Parameters.FLASH_MODE_TORCH : Camera.Parameters.FLASH_MODE_OFF);
    mCamera.setParameters(cameraParams);
    mCamera.startPreview();
  }

  mCamera.unlock();
  mRecorder = new MediaRecorder();

  try {
    mRecorder.setCamera(mCamera);

    CamcorderProfile profile;
    if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_HIGH)) {
      profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_HIGH);
    } else {
      if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_480P)) {
        profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_480P);
      } else {
        if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_720P)) {
          profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_720P);
        } else {
          if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_1080P)) {
            profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_1080P);
          } else {
            profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_LOW);
          }
        }
      }
    }


    mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
    mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mRecorder.setProfile(profile);
    mRecorder.setOutputFile(filePath);
    mRecorder.setOrientationHint(mOrientationHint);

    mRecorder.prepare();
    Log.d(TAG, "Starting recording");
    mRecorder.start();
    eventListener.onStartRecordVideo();
  } catch (IOException e) {
    eventListener.onStartRecordVideoError(e.getMessage());
  }
}
 
Example 18
Source File: RCTCamera.java    From react-native-camera-face-detector with MIT License 4 votes vote down vote up
public CamcorderProfile setCaptureVideoQuality(int cameraType, String captureQuality) {
    Camera camera = this.acquireCameraInstance(cameraType);
    if (camera == null) {
        return null;
    }

    Camera.Size videoSize = null;
    List<Camera.Size> supportedSizes = getSupportedVideoSizes(camera);
    CamcorderProfile cm = null;
    switch (captureQuality) {
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_LOW:
            videoSize = getSmallestSize(supportedSizes);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_480P);
            break;
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_MEDIUM:
            videoSize = supportedSizes.get(supportedSizes.size() / 2);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_720P);
            break;
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH:
            videoSize = getBestSize(supportedSizes, Integer.MAX_VALUE, Integer.MAX_VALUE);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_HIGH);
            break;
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_480P:
            videoSize = getBestSize(supportedSizes, RESOLUTION_480P.width, RESOLUTION_480P.height);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_480P);
            break;
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_720P:
            videoSize = getBestSize(supportedSizes, RESOLUTION_720P.width, RESOLUTION_720P.height);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_720P);
            break;
        case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_1080P:
            videoSize = getBestSize(supportedSizes, RESOLUTION_1080P.width, RESOLUTION_1080P.height);
            cm = CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_1080P);
            break;
    }

    if (cm == null){
        return null;
    }

    if (videoSize != null) {
        cm.videoFrameHeight = videoSize.height;
        cm.videoFrameWidth = videoSize.width;
    }

    return cm;
}
 
Example 19
Source File: Camera1.java    From camerakit-android with MIT License 4 votes vote down vote up
private CamcorderProfile getCamcorderProfile(@VideoQuality int videoQuality) {
    CamcorderProfile camcorderProfile = null;
    switch (videoQuality) {
        case CameraKit.Constants.VIDEO_QUALITY_QVGA:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_QVGA)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_QVGA);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_LOWEST);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_480P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_480P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_QVGA);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_720P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_720P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_480P);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_1080P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_1080P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_720P);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_2160P:
            try {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_2160P);
            } catch (Exception e) {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_HIGHEST);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_HIGHEST:
            camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
            break;

        case CameraKit.Constants.VIDEO_QUALITY_LOWEST:
            camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
            break;
    }

    if (camcorderProfile != null && mVideoBitRate != 0) {
        camcorderProfile.videoBitRate = mVideoBitRate;
    }

    return camcorderProfile;
}
 
Example 20
Source File: CameraHelper.java    From sandriosCamera with MIT License 4 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(@CameraConfiguration.MediaQuality int mediaQuality, int cameraId) {
    if (Build.VERSION.SDK_INT > 10) {
        if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGH) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_MEDIUM) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOW) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    } else {
        if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGH) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_MEDIUM) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOW) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    }
}