admin管理员组文章数量:1397102
I'm trying to use an Android MediaRecorder to record video. In order to limit the size of the file I want to periodically start a new video file, and just like the built-in Camera app I don't want to lose any frames. However, I am not reaching the point where I can even successfully test if frames are lost. Here is my workflow:
handler gets run after specified delay:
File videoFile = ...; // here is where i set the next file to output to
mediaRecorder.reset(); // i also tried calling stop() first, but the state machine diagram says this is not necessary
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile(videoFile.getAbsolutePath());
// Set video resolution and adjust size and bitrate
mediaRecorder.setVideoSize(sharedPreferencesManager.getCameraResolution().getWidth(), sharedPreferencesManager.getCameraResolution().getHeight());
mediaRecorder.setVideoEncodingBitRate(getVideoBitrate());
// Set frame rate and capture rate
mediaRecorder.setVideoFrameRate(sharedPreferencesManager.getVideoFrameRate());
mediaRecorder.setCaptureRate(sharedPreferencesManager.getVideoFrameRate());
// Audio settings: high-quality audio
mediaRecorder.setAudioEncodingBitRate(384000);
mediaRecorder.setAudioSamplingRate(48000);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
VideoCodec videoCodec = sharedPreferencesManager.getVideoCodec();
mediaRecorder.setVideoEncoder(videoCodec.getEncoder());
// Set orientation based on camera selection
if (sharedPreferencesManager.getCameraSelection().equals(CameraType.FRONT)) {
mediaRecorder.setOrientationHint(270);
} else {
mediaRecorder.setOrientationHint(90);
}
// Prepare MediaRecorder
mediaRecorder.prepare();
mediaRecorder.start();
backgroundHandler.postDelayed(this, intervalMillis);
The first video file created is playable. However, I can't get the second video file to even work. If I wait until the third video file is created I get a playable second video file that is the correct length but empty (black output, no sound, minimal size), but if I manually stop during recording of the second video I get an exception trying to call stop() telling me that stop was called while neither recording nor paused.
Yet I plainly called start(), so it's not clear to me why it's not recording.
This is running under Android 14.
本文标签: javaMediaRecorder fails to properly transition to second video fileStack Overflow
版权声明:本文标题:java - MediaRecorder fails to properly transition to second video file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744149245a2592982.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论