以下是有助于捕获视频的代码,但问题在于帧速率,因为我已经将帧速率定义为每秒 30 帧。使用前置摄像头录制视频时,每秒输出 8 帧,后置摄像头最多输出 15 到 18 帧
private void startRecording() {
if(mrec != null){
mrec.reset();
}
mCamera.unlock();
mrec.setCamera(mCamera);
mrec.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mrec.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mrec.setVideoSize(640, 480);
mrec.setVideoEncodingBitRate(3000000);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mrec.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
File dir = new File(SdCardPath + Directory);
if (!dir.exists()) {
if (dir.mkdir()) {
Log.v(STORAGE_SERVICE, "Created directory");
} else {
Log.v(STORAGE_SERVICE, "Failed to create Directory");
}
}
FullFilePath = SdCardPath + Directory + RecordFileName;
mrec.setOutputFile(FullFilePath);
mrec.setVideoFrameRate(30);
mrec.setPreviewDisplay(surfaceHolder.getSurface());
try {
mrec.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mrec.start();
}