android camera 质量,android - 如何使用Camera 2 API获得尺寸更小的高质量视频? - 堆栈内存溢出...

我在我的项目中使用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();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值