I have written an opensource camera for Google glass but some of the people who have used it have reported that the video recorded doesn't get saved properly for lengthy videos.
I couldn't find info regarding any such limitation in the Android documentation
So Upon checking it out i found that for videos greater than 26 minutes
, the video file got saved in Glass and Its size was around 2.7 GB
but its duration was 0:00
. And it couldn't be played using any video player.
So i am wondering why is that? Why does the video get properly recorded for duration < 26 minutes
and gets messed up for longer videos.
Code to start video Recording is
/**
* Initialize video recorder to record video
*/
private void initRecorder() {
try {
File dir = new File(Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_PICTURES
+ File.separator + "My Videos");
if (!dir.exists()) {
dir.mkdirs();
}
videofile = new File(dir, "video.mp4");
recorder.setCamera(mCamera);
// Step 2: Set sources
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
recorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));
// Step 4: Set output file
recorder.setOutputFile(videofile.getAbsolutePath());
// Step 5: Set the preview output
recorder.setPreviewDisplay(mPreview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
recorder.setMaxDuration(3600* 1000);
recorder.setMaxFileSize(-1);
recorder.setOnErrorListener(new OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Log.e("Error Recording", what+" Extra "+extra);
}
});
recorder.setOnInfoListener(new OnInfoListener() {
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
endVideoRecording();
}
}
});
recorder.prepare();
recorder.start();
mOverlay.setMode(Mode.RECORDING);
} catch (Exception e) {
if (e != null && e.getMessage() != null)
Log.e("Error Starting CuXtom Camera for video recording",
e.getMessage());
}
}