@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, currentCameraId); double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize()); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration)); camcorderProfile = CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_MEDIUM, currentCameraId); videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize()); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration)); camcorderProfile = CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_LOW, currentCameraId); videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize()); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration)); CharSequence[] array = new CharSequence[videoQualities.size()]; videoQualities.toArray(array); return array; }
@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; }
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); }
private void setUpMediaRecorder() throws IOException { final Activity activity = (Activity) getContext(); if (null == activity) { return; } mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString()); if (sensorOrientation == SENSOR_ORIENTATION_DEFAULT_DEGREES) { mediaRecorder.setOrientationHint(ORIENTATION_90); } else { mediaRecorder.setOrientationHint(ORIENTATION_270); } CamcorderProfile profile = getCamcorderProfile(); profile.videoFrameWidth = videoSize.getWidth(); profile.videoFrameHeight = videoSize.getHeight(); mediaRecorder.setProfile(profile); mediaRecorder.setVideoEncodingBitRate(BITRATE); mediaRecorder.prepare(); }
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; }
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); }
@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; }
@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); }
@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()); }
public static CamcorderProfile getCamcorderProfile(int currentCameraId, long maximumFileSize, int minimumDurationInSeconds) { if (maximumFileSize <= 0) return CamcorderProfile.get(currentCameraId, AnncaConfiguration.MEDIA_QUALITY_HIGHEST); int[] qualities = new int[]{AnncaConfiguration.MEDIA_QUALITY_HIGHEST, AnncaConfiguration.MEDIA_QUALITY_HIGH, AnncaConfiguration.MEDIA_QUALITY_MEDIUM, AnncaConfiguration.MEDIA_QUALITY_LOW, AnncaConfiguration.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(AnncaConfiguration.MEDIA_QUALITY_LOWEST, currentCameraId); }
@Override protected CharSequence[] getVideoQualityOptions() { List<CharSequence> videoQualities = new ArrayList<>(); if (getMinimumVideoDuration() > 0) videoQualities.add(new VideoQualityOption(AnncaConfiguration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(AnncaConfiguration.MEDIA_QUALITY_AUTO, getCameraController().getCurrentCameraId()), getMinimumVideoDuration())); CamcorderProfile camcorderProfile = CameraHelper.getCamcorderProfile(AnncaConfiguration.MEDIA_QUALITY_HIGH, getCameraController().getCurrentCameraId()); double videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize()); videoQualities.add(new VideoQualityOption(AnncaConfiguration.MEDIA_QUALITY_HIGH, camcorderProfile, videoDuration)); camcorderProfile = CameraHelper.getCamcorderProfile(AnncaConfiguration.MEDIA_QUALITY_MEDIUM, getCameraController().getCurrentCameraId()); videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize()); videoQualities.add(new VideoQualityOption(AnncaConfiguration.MEDIA_QUALITY_MEDIUM, camcorderProfile, videoDuration)); camcorderProfile = CameraHelper.getCamcorderProfile(AnncaConfiguration.MEDIA_QUALITY_LOW, getCameraController().getCurrentCameraId()); videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, getVideoFileSize()); videoQualities.add(new VideoQualityOption(AnncaConfiguration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration)); CharSequence[] array = new CharSequence[videoQualities.size()]; videoQualities.toArray(array); return array; }
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; }
@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(); } }
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(); }
private List<Size> getSizes(StreamConfigurationMap map) { Size[] sizes = map.getOutputSizes(MediaRecorder.class); // StreamConfigurationMap.getOutputSizes(MediaRecorder.class) only tells us if the // camera supports these sizes. It does not tell us if MediaRecorder supports these // sizes, odd as that sounds. Therefore, we need to filter ourselves manually. List<Size> filtered; if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_2160P)) { filtered = filter(sizes, SIZE_4K); if (!filtered.isEmpty()) { return filtered; } } if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_1080P)) { filtered = filter(sizes, SIZE_1080P); if (!filtered.isEmpty()) { return filtered; } } if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_720P)) { filtered = filter(sizes, SIZE_720P); if (!filtered.isEmpty()) { return filtered; } } if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_480P)) { filtered = filter(sizes, SIZE_480P); if (!filtered.isEmpty()) { return filtered; } } return Arrays.asList(sizes); }
private void chooseCamcorderProfile(Size sizeHint) { // For android 2.3 devices video quality = low if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_LOW)); else { // For >= Android 3.0 devices select 720p, 480p or low quality of video if (CamcorderProfile.hasProfile(getCameraID(), CamcorderProfile.QUALITY_720P) && (sizeHint == null || sizeHint.height >= 720)) { profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_720P)); return; } if (CamcorderProfile.hasProfile(getCameraID(), CamcorderProfile.QUALITY_480P) && (sizeHint == null || sizeHint.height >= 480)) { profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_480P)); return; } profile = (CamcorderProfile.get(CamcorderProfile.QUALITY_LOW)); } }
public CaptureSurface(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); Log.d(Tag, "Setting up recorder."); recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); // recorder.setMaxDuration(50000); // 50 seconds // recorder.setMaxFileSize(5000000); // Approximately 5 megabytes //CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); recorder.setProfile(cpHigh); // recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); // recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); outputFile = Environment.getExternalStorageDirectory().getPath() + "/videoexample.mp4"; recorder.setOutputFile(outputFile); Log.d(Tag, "finished setting up recorder."); }
private void initRecorder() { Log.d(TAG, "initRecorder"); // recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile cpHigh = CamcorderProfile .get(CamcorderProfile.QUALITY_HIGH); recorder.setProfile(cpHigh); VideoFile = MainActivity.getOutputMediaFile(MainActivity.MEDIA_TYPE_VIDEO); Log.d(TAG, "File is " + VideoFile.toString()); recorder.setOutputFile(VideoFile.toString()); //if you wanted to limit the video size, you can use one of these. // recorder.setMaxDuration(50000); // 50 seconds // recorder.setMaxFileSize(5000000); // Approximately 5 megabytes }
public CaptureSurface(Context context, AttributeSet attrs) { super(context, attrs); holder = getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); Log.d(Tag, "Setting up recorder."); recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); recorder.setMaxDuration(50000); // 50 seconds recorder.setMaxFileSize(5000000); // Approximately 5 megabytes //CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); recorder.setProfile(cpHigh); // recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); // recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); outputFile = Environment.getExternalStorageDirectory().getPath() +"/videoexample.mp4"; recorder.setOutputFile(outputFile); Log.d(Tag, "finished setting up recorder."); }
/** * 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; }
public static int getVideoCaptureDurationLimit(long bytesAvailable) { CamcorderProfile camcorder = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); if (camcorder == null) { return 0; } bytesAvailable *= 8; // convert to bits long seconds = bytesAvailable / (camcorder.audioBitRate + camcorder.videoBitRate); // Find the best match for one of the fixed durations for (int i = sVideoDuration.length - 1; i >= 0; i--) { if (seconds >= sVideoDuration[i]) { return sVideoDuration[i]; } } return 0; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void configureRecorderProfile(int cameraId, MediaRecorder recorder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH)) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW)) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW)); } else { throw new IllegalStateException( "cannot find valid CamcorderProfile"); } }
@Override public void configureRecorder(CameraSession session, int cameraId, VideoTransaction xact, MediaRecorder recorder) { int highProfile=getHigh(); boolean canGoHigh=CamcorderProfile.hasProfile(cameraId, highProfile); boolean canGoLow=CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW); if (canGoHigh && (xact.getQuality()==1 || !canGoLow)) { recorder.setProfile(CamcorderProfile.get(cameraId, highProfile)); } else if (canGoLow) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW)); } else { throw new IllegalStateException( "cannot find valid CamcorderProfile"); } }
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); }
@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); }
@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()); }
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1) void startRecord(boolean audioOnly) { try { mRecorder = new MediaRecorder(); if (audioOnly == false) { mRecorder.setVideoSource(VideoSource.CAMERA); } mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mRecorder.setProfile(camcorderProfile_HQ); mPreview.getHolder().addCallback(this); mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); //mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setOutputFile(pathName); // Recording is now started } catch (Exception e) { e.printStackTrace(); } }
@SuppressLint("InlinedApi") private List<Integer> getFrameRatesFromCameraProfile(int camId) { List<Integer> list = new ArrayList<Integer>(); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_HIGH); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_LOW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_CIF); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_1080P); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_720P); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_480P); addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_QCIF); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) addProfileFrameRate(camId, list, CamcorderProfile.QUALITY_QVGA); } // deduplicate sizes Set<Integer> set = new TreeSet<Integer>(list); list.clear(); list.addAll(set); // sort Collections.sort(list); return list; }
/** * Determine maximum video resolution that device supports. * * @return VIDEO_720P if device supports 720p video recording, <br> * VIDEO_360P if device supports 360p video recording, and <br> * UNSUPPORTED if it supports less than 360p video recording. * <p> * If it is impossible to determine video recording frame size we * assume that device support VIDEO_720p. */ static public EVideoRecorderCapability getMaxSupportedVideoRes() { EVideoRecorderCapability videoResolution = EVideoRecorderCapability.VIDEO_720P; CamcorderProfile profile = null; profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); if (profile != null) { if (profile.videoFrameHeight >= 720) { videoResolution = EVideoRecorderCapability.VIDEO_720P; } else if (profile.videoFrameHeight >= 360) { videoResolution = EVideoRecorderCapability.VIDEO_360P; } else if (profile.videoFrameHeight < 360) { videoResolution = EVideoRecorderCapability.NOT_SUPPORTED; } } return videoResolution; }
public void refreshCamera() { CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight); camera.setParameters(parameters); try { camera.setPreviewDisplay(surfaceHolder); camera.startPreview(); } catch (IOException e) { Log.e(TAG, "Error starting camera preview: " + e.getMessage()); } }
@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); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static CamcorderProfile getCamcorderProfile(@Configuration.MediaQuality int mediaQuality, String cameraId) { if (TextUtils.isEmpty(cameraId)) { return null; } int cameraIdInt = Integer.parseInt(cameraId); return getCamcorderProfile(mediaQuality, cameraIdInt); }