java - camera2api 中是否有限制视频录制的设置?
问题描述
我正在创建一个 android 应用程序,并使用 Camera2api 创建了一个摄像头录制活动。但我想限制视频长度。我怎样才能做到这一点?
我已经尝试过 mMediaRecorder.setMaxDuration(8000);
private void setUpMediaRecorder() throws IOException {
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
// if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
// mNextVideoAbsolutePath = getVideoFilePath(getActivity());
// }
mMediaRecorder.setOutputFile(file.toString());
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setMaxDuration(8000);
// mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
int rotation =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();
}
解决方案
推荐阅读
- r - 在管道中的同一对象上调用两个不同的函数 (%>%)
- java - 为什么我的登录和注册不起作用甚至重定向?
- c# - SAP.Middleware.Connector.RfcSerializationException:未找到 RFCID.TableContLZ 的结束标记
- javascript - 如何修复 TypeError:无法在我的 MEAN 堆栈应用程序中读取未定义的属性“地图”?
- java - Spring Java应用程序找不到密钥库文件
- postgresql - NOT NULL 表达式中的 NULL 值
- javascript - React:改变消费者的上下文
- c# - 是否可以在 Grpc.Core 中接受自签名证书?
- python - 如何从 csv 中获取具有开始时间和结束时间的两个日期范围之间的重叠?
- if-statement - 确定不同薪酬水平的 IF THEN 公式是什么?生产 25 到 30 小时,每小时增加 1.50 美元