我在我的项目中使用camera 2 API进行视频录制。 我正在使用媒体记录器来设置视频配置。 问题是我用于获取较小尺寸的高质量视频的配置并非在所有设备上都是唯一的,这意味着如果我将“摄像机配置文件”质量设置为“高”,而媒体记录仪的输出格式为MPEG 4或3 GP视频,则会被删除而且我无法在Motorola g7设备中录制视频,但是使用相同的配置,我可以在Honor 8X设备中录制视频,但是质量很差。 因此,请在下面找到我的代码段,并帮助我使我的代码在所有设备上都独一无二,从而以较小的尺寸获得高质量的视频。 提前致谢。
private void setUpMediaRecorder() throws IOException {
final AppCompatActivity activity = (AppCompatActivity) getActivity();
if (null == activity) {
return;
}
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
/**
* create video output file
*/
mCurrentFile = getOutputMediaFile();
/**
* set output file in media recorder
*/
mMediaRecorder.setOutputFile(mCurrentFile.getAbsolutePath());
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
switch (mSensorOrientation) {
case SENSOR_ORIENTATION_DEFAULT_DEGREES:
mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
break;
case SENSOR_ORIENTATION_INVERSE_DEGREES:
mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
break;
}
mMediaRecorder.prepare();
}