I'm using MediaRecorder to record video with a MPEG2TS container on a Samsung Galaxy Note 2. It initializes without any errors, and actually writes data to the file (the file grows to several MB). However, the file is not playable in any media player.
Here's my code for initializing the MediaRecorder:
CamcorderProfile profile = null;
if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
}else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
}else{ profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); }
myMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
myMediaRecorder.setOutputFormat(8);
myMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
myMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
myMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
myMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
String f = Environment.getExternalStorageDirectory().toString() + "/video.ts";
myMediaRecorder.setOutputFile(f);
myMediaRecorder.setPreviewDisplay(previewHolder.getSurface());
myMediaRecorder.prepare();
myMediaRecorder.start();
The above code works just fine when I set the output format to MP4 ("2") instead of MPEG2-TS ("8"), but when it's set to 8, it produces an unplayable (but not empty) video!
What could be going on?
Edit: here's a sample video recorded on the device, if anyone's interested.