Java Code Examples for android.media.CamcorderProfile

The following examples show how to use android.media.CamcorderProfile. These examples are extracted from open source projects. 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
/**
 * @return max size that device can record.
 */
private Camera.Size getMaxEncoderSizeSupported() {
  if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) {
    return camera.new Size(3840, 2160);
  } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) {
    return camera.new Size(1920, 1080);
  } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
    return camera.new Size(1280, 720);
  } else {
    return camera.new Size(640, 480);
  }
}
 
Example 2
Source Project: Lassi-Android   Source File: CamcorderProfiles.java    License: 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 3
Source Project: LiTr   Source File: DeviceUtil.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@NonNull
private static String getCameraInfo(@NonNull Context context, int camcorderProfileId) {
    CamcorderProfile camcorderProfile = null;
    try {
        camcorderProfile = CamcorderProfile.get(camcorderProfileId);
    } catch (RuntimeException e) {
        // do nothing
    }

    if (camcorderProfile == null) {
        return context.getString(R.string.camcorder_profile_not_supported, camcorderProfileId) + '\n';
    }

    return context.getString(R.string.video_frame_width, camcorderProfile.videoFrameWidth)
        + context.getString(R.string.video_frame_height, camcorderProfile.videoFrameHeight)
        + context.getString(R.string.file_output_format, getFileFormat(camcorderProfile.fileFormat))
        + context.getString(R.string.video_codec, getVideoCodec(camcorderProfile.videoCodec))
        + context.getString(R.string.video_bitrate, camcorderProfile.videoBitRate / 1000000)
        + context.getString(R.string.video_frame_rate, camcorderProfile.videoFrameRate)
        + context.getString(R.string.audio_codec, getAudioCodec(camcorderProfile.audioCodec))
        + context.getString(R.string.audio_bitrate, camcorderProfile.audioBitRate / 1000)
        + context.getString(R.string.audio_sample_rate, camcorderProfile.audioSampleRate / 1000)
        + context.getString(R.string.audio_channels, camcorderProfile.audioChannels)
        + '\n';
}
 
Example 4
Source Project: Camera2   Source File: SettingsUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Starting from 'start' this method returns the next supported video
 * quality.
 */
private static int getNextSupportedVideoQualityIndex(int cameraId, int start)
{
    for (int i = start + 1; i < sVideoQualities.length; ++i)
    {
        if (isVideoQualitySupported(sVideoQualities[i])
                && CamcorderProfile.hasProfile(cameraId, sVideoQualities[i]))
        {
            // We found a new supported quality.
            return i;
        }
    }

    // Failed to find another supported quality.
    if (start < 0 || start >= sVideoQualities.length)
    {
        // This means we couldn't find any supported quality.
        throw new IllegalArgumentException("Could not find supported video qualities.");
    }

    // We previously found a larger supported size. In this edge case, just
    // return the same index as the previous size.
    return start;
}
 
Example 5
Source Project: KrGallery   Source File: CameraSession.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);
    recorder.setOrientationHint(displayOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 6
Source Project: phoenix   Source File: Camera2Manager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence[] getVideoQualityOptions() {
    final List<CharSequence> videoQualities = new ArrayList<>();

    if (cameraConfigProvider.getMinimumVideoDuration() > 0)
        videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_AUTO, CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_AUTO, getCameraId()), cameraConfigProvider.getMinimumVideoDuration()));


    CamcorderProfile camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_HIGH, mCameraId);
    double videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));

    camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_MEDIUM, mCameraId);
    videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));

    camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_LOW, mCameraId);
    videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));

    CharSequence[] array = new CharSequence[videoQualities.size()];
    videoQualities.toArray(array);

    return array;
}
 
Example 7
Source Project: phoenix   Source File: Camera1Manager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence[] getVideoQualityOptions() {
    final List<CharSequence> videoQualities = new ArrayList<>();

    if (cameraConfigProvider.getMinimumVideoDuration() > 0)
        videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_AUTO, CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_AUTO, getCameraId()), cameraConfigProvider.getMinimumVideoDuration()));

    CamcorderProfile camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_HIGH, getCameraId());
    double videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));

    camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_MEDIUM, getCameraId());
    videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));

    camcorderProfile = CameraUtils.getCamcorderProfile(CameraConfig.MEDIA_QUALITY_LOW, getCameraId());
    videoDuration = CameraUtils.calculateApproximateVideoDuration(camcorderProfile, cameraConfigProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfig.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));

    final CharSequence[] array = new CharSequence[videoQualities.size()];
    videoQualities.toArray(array);

    return array;
}
 
Example 8
Source Project: phoenix   Source File: CameraUtils.java    License: 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 9
Source Project: phoenix   Source File: Camera1Manager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence[] getVideoQualityOptions() {
    final List<CharSequence> videoQualities = new ArrayList<>();

    if (configurationProvider.getMinimumVideoDuration() > 0)
        videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_AUTO, getCurrentCameraId()), configurationProvider.getMinimumVideoDuration()));

    CamcorderProfile camcorderProfile = CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_HIGH, getCurrentCameraId());
    double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_MEDIUM, getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_LOW, getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize());
    videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));

    final CharSequence[] array = new CharSequence[videoQualities.size()];
    videoQualities.toArray(array);

    return array;
}
 
Example 10
Source Project: phoenix   Source File: CameraHelper.java    License: 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, Configuration.MEDIA_QUALITY_HIGHEST);

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

    CamcorderProfile camcorderProfile;
    for (int i = 0; i < qualities.length; ++i) {
        camcorderProfile = CameraHelper.getCamcorderProfile(qualities[i], currentCameraId);
        double fileSize = CameraHelper.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 CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_LOWEST, currentCameraId);
}
 
Example 11
Source Project: sandriosCamera   Source File: CameraHelper.java    License: MIT License 6 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(int currentCameraId, long maximumFileSize, int minimumDurationInSeconds) {
    if (maximumFileSize <= 0)
        return CamcorderProfile.get(currentCameraId, CameraConfiguration.MEDIA_QUALITY_HIGHEST);

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

    CamcorderProfile camcorderProfile;
    for (int i = 0; i < qualities.length; ++i) {
        camcorderProfile = CameraHelper.getCamcorderProfile(qualities[i], currentCameraId);
        double fileSize = CameraHelper.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 CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_LOWEST, currentCameraId);
}
 
Example 12
Source Project: sandriosCamera   Source File: Camera1Activity.java    License: MIT License 6 votes vote down vote up
@Override
protected CharSequence[] getVideoQualityOptions() {
    List<CharSequence> videoQualities = new ArrayList<>();

    if (getMinimumVideoDuration() > 0)
        videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_AUTO, getCameraController().getCurrentCameraId()), getMinimumVideoDuration()));

    CamcorderProfile camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_HIGH, getCameraController().getCurrentCameraId());
    double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_MEDIUM, getCameraController().getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_LOW, getCameraController().getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));

    CharSequence[] array = new CharSequence[videoQualities.size()];
    videoQualities.toArray(array);

    return array;
}
 
Example 13
Source Project: sandriosCamera   Source File: Camera2Activity.java    License: MIT License 6 votes vote down vote up
@Override
protected CharSequence[] getVideoQualityOptions() {
    List<CharSequence> videoQualities = new ArrayList<>();

    if (getMinimumVideoDuration() > 0)
        videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_AUTO, getCameraController().getCurrentCameraId()), getMinimumVideoDuration()));


    CamcorderProfile camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_HIGH, getCameraController().getCurrentCameraId());
    double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_MEDIUM, getCameraController().getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration));

    camcorderProfile = CameraHelper.getCamcorderProfile(CameraConfiguration.MEDIA_QUALITY_LOW, getCameraController().getCurrentCameraId());
    videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize());
    videoQualities.add(new VideoQualityOption(CameraConfiguration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));

    CharSequence[] array = new CharSequence[videoQualities.size()];
    videoQualities.toArray(array);

    return array;
}
 
Example 14
Source Project: VideoCamera   Source File: VideoRecorderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void mediaRecorderShouldHaveMediaRecorderOptions() throws Exception {
    final CaptureConfiguration config = new CaptureConfiguration();
    CamcorderProfile profile = getEmptyCamcorderProfile();
    final VideoRecorder recorder =
            new VideoRecorder(null, config, mock(VideoFile.class), createMockCameraWrapperForPrepare(profile), mock(SurfaceHolder.class));

    final MediaRecorder mockRecorder = mock(MediaRecorder.class);
    recorder.configureMediaRecorder(mockRecorder, mock(Camera.class));

    verify(mockRecorder, times(1)).setAudioSource(config.getAudioSource());
    verify(mockRecorder, times(1)).setVideoSource(config.getVideoSource());
    assertEquals(profile.fileFormat, config.getOutputFormat());
    assertEquals(profile.audioCodec, config.getAudioEncoder());
    assertEquals(profile.videoCodec, config.getVideoEncoder());
    verify(mockRecorder, times(1)).setProfile(profile);
}
 
Example 15
Source Project: VideoCamera   Source File: VideoRecorderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void mediaRecorderShouldHaveConfigurationOptions() throws Exception {
    final CaptureConfiguration config = new CaptureConfiguration();
    CamcorderProfile profile = getEmptyCamcorderProfile();
    CameraWrapper mockWrapper = createMockCameraWrapperForPrepare(profile);
    doReturn(new RecordingSize(777, 888)).when(mockWrapper).getSupportedRecordingSize(anyInt(), anyInt());
    final VideoRecorder recorder = new VideoRecorder(null, config, mock(VideoFile.class), mockWrapper, mock(SurfaceHolder.class));

    final MediaRecorder mockRecorder = mock(MediaRecorder.class);
    recorder.configureMediaRecorder(mockRecorder, mock(Camera.class));

    assertEquals(profile.videoFrameWidth, 777);
    assertEquals(profile.videoFrameHeight, 888);
    assertEquals(profile.videoBitRate, config.getVideoBitrate());
    verify(mockRecorder, times(1)).setMaxDuration(config.getMaxCaptureDuration());
    verify(mockRecorder, times(1)).setProfile(profile);
    verify(mockRecorder, times(1)).setMaxFileSize(config.getMaxCaptureFileSize());
}
 
Example 16
Source Project: MultiMediaSample   Source File: TakeVideoActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initSupportProfile() {

        if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_480P)) {//无声音的480p
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_480P;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_QVGA)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_QVGA;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_CIF)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_CIF;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_720P)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_720P;
        }
        Log.d(TAG, "finally mQuality resolution:" + mQuality);
        CamcorderProfile profile = CamcorderProfile.get(mQuality);
        //因为竖屏被旋转了90度
        mVideoHeiht = profile.videoFrameWidth;
        mVideoWidth = profile.videoFrameHeight;
        Log.d(TAG, "video screen from CamcorderProfile resolution:" + mVideoWidth + "*" + mVideoHeiht);
    }
 
Example 17
Source Project: VideoRecorderTest   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private boolean prepareMediaRecorder() {
    mMediaRecorder = new MediaRecorder();
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P));
    mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
    String path = getSDPath();
    if (path != null) {

        File dir = new File(path + "/VideoRecorderTest");
        if (!dir.exists()) {
            dir.mkdir();
        }
        path = dir + "/" + getDate() + ".mp4";
        mMediaRecorder.setOutputFile(path);
        try {
            mMediaRecorder.prepare();
        } catch (IOException e) {
            releaseMediaRecorder();
            e.printStackTrace();
        }
    }
    return true;
}
 
Example 18
Source Project: BluetoothCameraAndroid   Source File: CameraActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void startRecording(Camera.PreviewCallback previewCallback) {
    recording = true;
    mCamera.unlock();
    mRecordbutton.setBackgroundResource(R.drawable.red_circle_background);
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setCamera(mCamera);
    mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
    mMediaRecorder.setOutputFile("/sdcard/Video.mp4");
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setOrientationHint(90);
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    try {
        mMediaRecorder.prepare();
        mMediaRecorder.start();
        mCamera.startPreview();
        mCamera.setPreviewCallback(previewCallback);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 19
Source Project: BluetoothCameraAndroid   Source File: TestActivity.java    License: MIT License 6 votes vote down vote up
protected void startRecording() throws IOException {
    mMediaRecorder = new MediaRecorder();  // Works well
    mCamera.unlock();

    mMediaRecorder.setCamera(mCamera);

    mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    mMediaRecorder.setOutputFile("/sdcard/zzzz.mp4");

    mMediaRecorder.prepare();
    mMediaRecorder.start();
}
 
Example 20
Source Project: Telecine   Source File: RecordingSession.java    License: Apache License 2.0 6 votes vote down vote up
private RecordingInfo getRecordingInfo() {
  DisplayMetrics displayMetrics = new DisplayMetrics();
  WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
  wm.getDefaultDisplay().getRealMetrics(displayMetrics);
  int displayWidth = displayMetrics.widthPixels;
  int displayHeight = displayMetrics.heightPixels;
  int displayDensity = displayMetrics.densityDpi;
  Timber.d("Display size: %s x %s @ %s", displayWidth, displayHeight, displayDensity);

  Configuration configuration = context.getResources().getConfiguration();
  boolean isLandscape = configuration.orientation == ORIENTATION_LANDSCAPE;
  Timber.d("Display landscape: %s", isLandscape);

  // Get the best camera profile available. We assume MediaRecorder supports the highest.
  CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
  int cameraWidth = camcorderProfile != null ? camcorderProfile.videoFrameWidth : -1;
  int cameraHeight = camcorderProfile != null ? camcorderProfile.videoFrameHeight : -1;
  int cameraFrameRate = camcorderProfile != null ? camcorderProfile.videoFrameRate : 30;
  Timber.d("Camera size: %s x %s framerate: %s", cameraWidth, cameraHeight, cameraFrameRate);

  int sizePercentage = videoSizePercentage.get();
  Timber.d("Size percentage: %s", sizePercentage);

  return calculateRecordingInfo(displayWidth, displayHeight, displayDensity, isLandscape,
      cameraWidth, cameraHeight, cameraFrameRate, sizePercentage);
}
 
Example 21
Source Project: LandscapeVideoCamera   Source File: VideoRecorderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void mediaRecorderShouldHaveMediaRecorderOptions() throws Exception {
    final CaptureConfiguration config = CaptureConfiguration.getDefault();
    CamcorderProfile profile = getEmptyCamcorderProfile();
    final VideoRecorder recorder =
            new VideoRecorder(null, config, mock(VideoFile.class), createMockCameraWrapperForPrepare(profile), mock(SurfaceHolder.class), false);

    final MediaRecorder mockRecorder = mock(MediaRecorder.class);
    recorder.configureMediaRecorder(mockRecorder, mock(Camera.class));

    verify(mockRecorder, times(1)).setAudioSource(config.getAudioSource());
    verify(mockRecorder, times(1)).setVideoSource(config.getVideoSource());
    assertEquals(profile.fileFormat, config.getOutputFormat());
    assertEquals(profile.audioCodec, config.getAudioEncoder());
    assertEquals(profile.videoCodec, config.getVideoEncoder());
    verify(mockRecorder, times(1)).setProfile(profile);
}
 
Example 22
Source Project: LandscapeVideoCamera   Source File: VideoRecorderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void mediaRecorderShouldHaveConfigurationOptions() throws Exception {
    final CaptureConfiguration config = CaptureConfiguration.getDefault();
    CamcorderProfile profile = getEmptyCamcorderProfile();
    CameraWrapper mockWrapper = createMockCameraWrapperForPrepare(profile);
    doReturn(new RecordingSize(777, 888)).when(mockWrapper).getSupportedRecordingSize(anyInt(), anyInt());
    final VideoRecorder recorder = new VideoRecorder(null, config, mock(VideoFile.class), mockWrapper, mock(SurfaceHolder.class), false);

    final MediaRecorder mockRecorder = mock(MediaRecorder.class);
    recorder.configureMediaRecorder(mockRecorder, mock(Camera.class));

    assertEquals(profile.videoFrameWidth, 777);
    assertEquals(profile.videoFrameHeight, 888);
    assertEquals(profile.videoBitRate, config.getVideoBitrate());
    verify(mockRecorder, times(1)).setMaxDuration(config.getMaxCaptureDuration());
    verify(mockRecorder, times(1)).setProfile(profile);
    verify(mockRecorder, times(1)).setMaxFileSize(config.getMaxCaptureFileSize());
}
 
Example 23
Source Project: mollyim-android   Source File: VideoCapture.java    License: 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 24
Source Project: LiTr   Source File: DeviceUtil.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
public static String getCaptureFormats(@NonNull Context context) {
    String captureFormats = getCameraInfo(context, CamcorderProfile.QUALITY_720P)
        + getCameraInfo(context, CamcorderProfile.QUALITY_1080P);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        captureFormats += getCameraInfo(context, CamcorderProfile.QUALITY_2160P);
    }

    return captureFormats;
}
 
Example 25
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 26
public boolean canRecordVideo(@VideoMode int videoMode) {
    try {
        CamcorderProfile.get(getIdForRequestedCamera(mFacing), videoMode);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 27
Source Project: Camera2   Source File: SettingsUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the given {@link CamcorderProfile} is supported on the
 * current device/OS version.
 */
private static boolean isVideoQualitySupported(int videoQuality)
{
    // 4k is only supported on L or higher but some devices falsely report
    // to have support for it on K, see b/18172081.
    if (!ApiHelper.isLOrHigher() && videoQuality == CamcorderProfile.QUALITY_2160P)
    {
        return false;
    }
    return true;
}
 
Example 28
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 29
Source Project: VideoRecord   Source File: VideoRecordSurface.java    License: 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 30
Source Project: Camera2Vision   Source File: CameraSource.java    License: 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;
    }
}