Reputation: 489
I've working android camera video streaming for a while. I tried libstreaming package first, but had this issue. So I followed the Google Camera sample code to write my own class. But after I passing a ParcelFileDescriptor
to mMediaRecorder.setOutputFile
, I get this error:
E/MediaRecorder: start failed: -2147483648
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: sharedcameraandroid, PID: 14868
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at MainActivity.startRecordingVideo(MainActivity.java:268)
at MainActivity.setUpMediaRecorder(MainActivity.java:257)
So I checked online and find this (change outputformat to 3GPP), this to add Thread.sleep
and this. But all of them didnt work. So I come to ask if anyone knows how to fix the issue.
Here is my code:
private void setUpMediaRecorder() throws IOException {
final Activity activity = mActivity;
if (null == activity) {
return;
}
ParcelFileDescriptor[] parcelFileDescriptors = ParcelFileDescriptor.createPipe();
mParcelRead = new ParcelFileDescriptor(parcelFileDescriptors[0]);
mParcelWrite = new ParcelFileDescriptor(parcelFileDescriptors[1]);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
// mMediaRecorder.setOutputFile((new File(mActivity.getExternalFilesDir(null), "video.mp4")).getAbsolutePath());
// Log.d(TAG, (new File(mActivity.getExternalFilesDir(null), "video.mp4")).getAbsolutePath());
mMediaRecorder.setOutputFile(mParcelWrite.getFileDescriptor());
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
// mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.prepare();
startRecordingVideo();
// https://stackoverflow.com/questions/14598299/how-to-record-video-on-android-into-stream
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
RtspClient client = new RtspClient(is, releaseSampleFile());
client.startStream();
}
If I change the mMediaRecorder.setOutputFile(mParcelWrite.getFileDescriptor());
with the commented lines, everything is fine.
Thanks for any help!
Upvotes: 6
Views: 1422
Reputation: 98
Recently i got stuck in this problem in my project. so tried changing some of the parameters. and luckily when i changed the OutputFormat to MPEG_2_TS it worked.
So what's i am saying is change the outputformat to MPEG_2_TS. It worked for me. So lets hope it works for you.
Upvotes: 3