0
錄像機捕獲視頻我試圖使用Android的媒體錄像機捕獲視頻但僅一個第二記錄視頻。我花了一天,但無法解決它,我的代碼有什麼問題,任何幫助都會感激。這是媒體捕獲的代碼。媒體只1秒
mCamera.unlock();
MediaRecorder mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(mCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoSize(640, 480);
mediaRecorder.setVideoFrameRate(16);
mediaRecorder.setVideoEncodingBitRate(2000000);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setMaxDuration(maxDurationInMs);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaStorageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Ethos"
+ File.separator + "Video");
if (!mediaStorageDir.mkdirs()) {
Log.d("Camera Guide", "Required media storage does not exist");
}
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"video" + timeStamp + ".mp4");
SharedPreferenceUtil.putValue("path_video", mediaFile.toString());
SharedPreferenceUtil.save();
mediaRecorder.setOutputFile(mediaFile.getPath());
mediaRecorder.setPreviewDisplay(mHolder.getSurface());
mediaRecorder.setMaxFileSize(maxFileSizeInBytes);
mediaRecorder.setOrientationHint(90);
try {
mediaRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaRecorder.start()
我已經設置maxDurationInMs = 300000
什麼是'maxFileSizeInBytes'的價值? –
它是maxFileSizeInBytes = 500000 – PARESH
此文件大小解析爲'488 KB'。而且您正在使用H.264和分辨率的高質量編碼器。使用所有這些參數,您的fileSize限制在您的持續時間限制之前首先達到。嘗試評論'fileSize'限制,然後檢查它。 –