use of android.media.CamcorderProfile in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderStressTest method recordVideoAndPlayback.
// Helper method for record & playback testing with different camcorder profiles
private void recordVideoAndPlayback(int profile) throws Exception {
int iterations;
int recordDuration;
boolean removeVideo;
int videoEncoder;
int audioEncoder;
int frameRate;
int videoWidth;
int videoHeight;
int bitRate;
if (profile != USE_TEST_RUNNER_PROFILE) {
assertTrue(String.format("Camera doesn't support profile %d", profile), CamcorderProfile.hasProfile(CAMERA_ID, profile));
CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
videoEncoder = camcorderProfile.videoCodec;
audioEncoder = camcorderProfile.audioCodec;
frameRate = camcorderProfile.videoFrameRate;
videoWidth = camcorderProfile.videoFrameWidth;
videoHeight = camcorderProfile.videoFrameHeight;
bitRate = camcorderProfile.videoBitRate;
} else {
videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
frameRate = MediaRecorderStressTestRunner.mFrameRate;
videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
bitRate = MediaRecorderStressTestRunner.mBitRate;
}
iterations = MediaRecorderStressTestRunner.mIterations;
recordDuration = MediaRecorderStressTestRunner.mDuration;
removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
mOutput.write("Total number of loops: " + iterations + "\n");
try {
mOutput.write("No of loop: ");
for (int i = 0; i < iterations; i++) {
String fileName = String.format("%s/temp%d%s", Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
Log.v(TAG, "iterations : " + iterations);
Log.v(TAG, "video encoder : " + videoEncoder);
Log.v(TAG, "audio encoder : " + audioEncoder);
Log.v(TAG, "frame rate : " + frameRate);
Log.v(TAG, "video width : " + videoWidth);
Log.v(TAG, "video height : " + videoHeight);
Log.v(TAG, "bit rate : " + bitRate);
Log.v(TAG, "record duration : " + recordDuration);
mRecorder.setOnErrorListener(mRecorderErrorCallback);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(fileName);
mRecorder.setVideoFrameRate(frameRate);
mRecorder.setVideoSize(videoWidth, videoHeight);
mRecorder.setVideoEncoder(videoEncoder);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setVideoEncodingBitRate(bitRate);
Log.v(TAG, "mediaRecorder setPreview");
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
//start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
mp.prepare();
mp.start();
Thread.sleep(recordDuration);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (i == 0) {
mOutput.write(i + 1);
} else {
mOutput.write(String.format(", %d", (i + 1)));
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Record and playback");
}
}
use of android.media.CamcorderProfile in project material-camera by afollestad.
the class Camera2Fragment method setUpMediaRecorder.
private boolean setUpMediaRecorder() {
final Activity activity = getActivity();
if (null == activity)
return false;
final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity;
if (mMediaRecorder == null)
mMediaRecorder = new MediaRecorder();
boolean canUseAudio = true;
boolean audioEnabled = !mInterface.audioDisabled();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
canUseAudio = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
if (canUseAudio && audioEnabled) {
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
} else if (audioEnabled) {
Toast.makeText(getActivity(), R.string.mcam_no_audio_access, Toast.LENGTH_LONG).show();
}
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
final CamcorderProfile profile = CamcorderProfile.get(0, mInterface.qualityProfile());
mMediaRecorder.setOutputFormat(profile.fileFormat);
mMediaRecorder.setVideoFrameRate(mInterface.videoFrameRate(profile.videoFrameRate));
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncodingBitRate(mInterface.videoEncodingBitRate(profile.videoBitRate));
mMediaRecorder.setVideoEncoder(profile.videoCodec);
if (canUseAudio && audioEnabled) {
mMediaRecorder.setAudioEncodingBitRate(mInterface.audioEncodingBitRate(profile.audioBitRate));
mMediaRecorder.setAudioChannels(profile.audioChannels);
mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
mMediaRecorder.setAudioEncoder(profile.audioCodec);
}
Uri uri = Uri.fromFile(getOutputMediaFile());
mOutputUri = uri.toString();
mMediaRecorder.setOutputFile(uri.getPath());
if (captureInterface.maxAllowedFileSize() > 0) {
mMediaRecorder.setMaxFileSize(captureInterface.maxAllowedFileSize());
mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
Toast.makeText(getActivity(), R.string.mcam_file_size_limit_reached, Toast.LENGTH_SHORT).show();
stopRecordingVideo(false);
}
}
});
}
mMediaRecorder.setOrientationHint(mDisplayOrientation);
try {
mMediaRecorder.prepare();
return true;
} catch (Throwable e) {
throwError(new Exception("Failed to prepare the media recorder: " + e.getMessage(), e));
return false;
}
}
use of android.media.CamcorderProfile in project qksms by moezbhatti.
the class MessageUtils method getVideoCaptureDurationLimit.
// Public for until tests
public static int getVideoCaptureDurationLimit(long bytesAvailable) {
CamcorderProfile camcorder = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
if (camcorder == null) {
return 0;
}
// convert to bits
bytesAvailable *= 8;
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;
}
use of android.media.CamcorderProfile in project platform_frameworks_base by android.
the class MediaRecorderStressTest method recordVideoAndPlayback.
// Helper method for record & playback testing with different camcorder profiles
private void recordVideoAndPlayback(int profile) throws Exception {
int iterations;
int recordDuration;
boolean removeVideo;
int videoEncoder;
int audioEncoder;
int frameRate;
int videoWidth;
int videoHeight;
int bitRate;
if (profile != USE_TEST_RUNNER_PROFILE) {
assertTrue(String.format("Camera doesn't support profile %d", profile), CamcorderProfile.hasProfile(CAMERA_ID, profile));
CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
videoEncoder = camcorderProfile.videoCodec;
audioEncoder = camcorderProfile.audioCodec;
frameRate = camcorderProfile.videoFrameRate;
videoWidth = camcorderProfile.videoFrameWidth;
videoHeight = camcorderProfile.videoFrameHeight;
bitRate = camcorderProfile.videoBitRate;
} else {
videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
frameRate = MediaRecorderStressTestRunner.mFrameRate;
videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
bitRate = MediaRecorderStressTestRunner.mBitRate;
}
iterations = MediaRecorderStressTestRunner.mIterations;
recordDuration = MediaRecorderStressTestRunner.mDuration;
removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
mOutput.write("Total number of loops: " + iterations + "\n");
try {
mOutput.write("No of loop: ");
for (int i = 0; i < iterations; i++) {
String fileName = String.format("%s/temp%d%s", Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
Log.v(TAG, "iterations : " + iterations);
Log.v(TAG, "video encoder : " + videoEncoder);
Log.v(TAG, "audio encoder : " + audioEncoder);
Log.v(TAG, "frame rate : " + frameRate);
Log.v(TAG, "video width : " + videoWidth);
Log.v(TAG, "video height : " + videoHeight);
Log.v(TAG, "bit rate : " + bitRate);
Log.v(TAG, "record duration : " + recordDuration);
mRecorder.setOnErrorListener(mRecorderErrorCallback);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(fileName);
mRecorder.setVideoFrameRate(frameRate);
mRecorder.setVideoSize(videoWidth, videoHeight);
mRecorder.setVideoEncoder(videoEncoder);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setVideoEncodingBitRate(bitRate);
Log.v(TAG, "mediaRecorder setPreview");
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
//start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
mp.prepare();
mp.start();
Thread.sleep(recordDuration);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (i == 0) {
mOutput.write(i + 1);
} else {
mOutput.write(String.format(", %d", (i + 1)));
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Record and playback");
}
}
use of android.media.CamcorderProfile in project android_packages_apps_Camera by CyanogenMod.
the class VideoModule method readVideoPreferences.
private void readVideoPreferences() {
// The preference stores values from ListPreference and is thus string type for all values.
// We need to convert it to int manually.
String defaultQuality = CameraSettings.getDefaultVideoQuality(mCameraId, mActivity.getResources().getString(R.string.pref_video_quality_default));
String videoQuality = mPreferences.getString(CameraSettings.KEY_VIDEO_QUALITY, defaultQuality);
int quality = Integer.valueOf(videoQuality);
// Set video quality.
Intent intent = mActivity.getIntent();
if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY)) {
int extraVideoQuality = intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
if (extraVideoQuality > 0) {
quality = CamcorderProfile.QUALITY_HIGH;
} else {
// 0 is mms.
quality = CamcorderProfile.QUALITY_LOW;
}
}
// unless it is specified in the intent.
if (intent.hasExtra(MediaStore.EXTRA_DURATION_LIMIT)) {
int seconds = intent.getIntExtra(MediaStore.EXTRA_DURATION_LIMIT, 0);
mMaxVideoDurationInMs = 1000 * seconds;
} else {
mMaxVideoDurationInMs = CameraSettings.getMaxVideoDuration(mActivity);
}
// Set effect
mEffectType = CameraSettings.readEffectType(mPreferences);
if (mEffectType != EffectsRecorder.EFFECT_NONE) {
mEffectParameter = CameraSettings.readEffectParameter(mPreferences);
// Set quality to be no higher than 480p.
CamcorderProfile profile = CamcorderProfile.get(mCameraId, quality);
if (profile.videoFrameHeight > 480) {
quality = getLowVideoQuality();
}
} else {
mEffectParameter = null;
}
// Read time lapse recording interval.
if (ApiHelper.HAS_TIME_LAPSE_RECORDING) {
String frameIntervalStr = mPreferences.getString(CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, mActivity.getString(R.string.pref_video_time_lapse_frame_interval_default));
mTimeBetweenTimeLapseFrameCaptureMs = Integer.parseInt(frameIntervalStr);
mCaptureTimeLapse = (mTimeBetweenTimeLapseFrameCaptureMs != 0);
}
// TODO: This should be checked instead directly +1000.
if (mCaptureTimeLapse)
quality += 1000;
mProfile = CamcorderProfile.get(mCameraId, quality);
getDesiredPreviewSize();
}
Aggregations