android.media.CamcorderProfile Java Examples

The following examples show how to use android.media.CamcorderProfile. 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: Camera1ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 7 votes vote down vote up
/**
 * @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 File: CameraSession.java    From KrGallery with GNU General Public License v2.0 7 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 #3
Source File: CameraHelper.java    From sandriosCamera with 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 #4
Source File: VideoRecorderTest.java    From LandscapeVideoCamera with 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 #5
Source File: DeviceUtil.java    From LiTr with 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 #6
Source File: VideoRecorderTest.java    From LandscapeVideoCamera with 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 #7
Source File: SettingsUtil.java    From Camera2 with 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 #8
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 #9
Source File: RecordingSession.java    From Telecine with 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 #10
Source File: CameraActivity.java    From BluetoothCameraAndroid with 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 #11
Source File: TestActivity.java    From BluetoothCameraAndroid with 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 #12
Source File: MainActivity.java    From VideoRecorderTest with 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 #13
Source File: VideoRecorderTest.java    From VideoCamera with 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 #14
Source File: CameraHelper.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, 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 #15
Source File: Camera1Manager.java    From phoenix with 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 #16
Source File: Camera1Activity.java    From sandriosCamera with 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 #17
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 #18
Source File: Camera2Activity.java    From sandriosCamera with 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 #19
Source File: VideoRecorderTest.java    From VideoCamera with 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 #20
Source File: Camera1Manager.java    From phoenix with 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 #21
Source File: Camera2Manager.java    From phoenix with 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 #22
Source File: TakeVideoActivity.java    From MultiMediaSample with 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 #23
Source File: CameraHelper.java    From sandriosCamera with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static CamcorderProfile getCamcorderProfile(String cameraId, long maximumFileSize, int minimumDurationInSeconds) {
    if (TextUtils.isEmpty(cameraId)) {
        return null;
    }
    int cameraIdInt = Integer.parseInt(cameraId);
    return getCamcorderProfile(cameraIdInt, maximumFileSize, minimumDurationInSeconds);
}
 
Example #24
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 #25
Source File: CameraHelper.java    From sandriosCamera with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static CamcorderProfile getCamcorderProfile(@CameraConfiguration.MediaQuality int mediaQuality, String cameraId) {
    if (TextUtils.isEmpty(cameraId)) {
        return null;
    }
    int cameraIdInt = Integer.parseInt(cameraId);
    return getCamcorderProfile(mediaQuality, cameraIdInt);
}
 
Example #26
Source File: CameraSession.java    From Telegram-FOSS with GNU General Public License v2.0 5 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);


    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 #27
Source File: VideoQualityOption.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public VideoQualityOption(@Configuration.MediaQuality int mediaQuality, CamcorderProfile camcorderProfile, double videoDuration) {
    this.mediaQuality = mediaQuality;

    long minutes = TimeUnit.SECONDS.toMinutes((long) videoDuration);
    long seconds = ((long) videoDuration) - minutes * 60;

    if (mediaQuality == Configuration.MEDIA_QUALITY_AUTO) {
        title = "Auto " + ", (" + (minutes > 10 ? minutes : ("0" + minutes)) + ":" + (seconds > 10 ? seconds : ("0" + seconds)) + " min)";
    } else {
        title = String.valueOf(camcorderProfile.videoFrameWidth)
                + " x " + String.valueOf(camcorderProfile.videoFrameHeight)
                + (videoDuration <= 0 ? "" : ", (" + (minutes > 10 ? minutes : ("0" + minutes)) + ":" + (seconds > 10 ? seconds : ("0" + seconds)) + " min)");
    }
}
 
Example #28
Source File: VideoQualityOption.java    From sandriosCamera with MIT License 5 votes vote down vote up
public VideoQualityOption(@CameraConfiguration.MediaQuality int mediaQuality, CamcorderProfile camcorderProfile, double videoDuration) {
    this.mediaQuality = mediaQuality;

    long minutes = TimeUnit.SECONDS.toMinutes((long) videoDuration);
    long seconds = ((long) videoDuration) - minutes * 60;

    if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_AUTO) {
        title = "Auto " + ", (" + (minutes > 10 ? minutes : ("0" + minutes)) + ":" + (seconds > 10 ? seconds : ("0" + seconds)) + " min)";
    } else {
        title = camcorderProfile.videoFrameWidth
                + " x " + camcorderProfile.videoFrameHeight
                + (videoDuration <= 0 ? "" : ", (" + (minutes > 10 ? minutes : ("0" + minutes)) + ":" + (seconds > 10 ? seconds : ("0" + seconds)) + " min)");
    }
}
 
Example #29
Source File: VideoRecorderTest.java    From LandscapeVideoCamera with Apache License 2.0 5 votes vote down vote up
private CamcorderProfile getEmptyCamcorderProfile() {
    try {
        Constructor<CamcorderProfile> constructor =
                CamcorderProfile.class.getDeclaredConstructor(new Class[]{int.class, int.class, int.class, int.class, int.class, int.class, int.class,
                                                                          int.class, int.class, int.class, int.class, int.class});
        constructor.setAccessible(true);
        return constructor.newInstance(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    } catch (Exception e) {
    }
    return null;
}
 
Example #30
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;
    }