I am working on a project where I need to
Read input H.264 encoded stream from an IPCamera - I am able to fetch this in through an rtsp url like rtsp://192.168.1.83:8001/
Display the IPCamera stream - This I am able to do using the
final VideoView vv = (VideoView) findViewById(R.id.video_view_h264);
MediaController mc = new MediaController(getApplicationContext());
vv.setVideoURI(video);
vv.setMediaController(mc);
vv.requestFocus();
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
vv.start();
}
});
Now I want to record this stream to an MP4 file. This is where I am stuck and I am considering the following options
a) MediaRecorder - Based on my google searches I believe for this class the input can only from a device camera. Is there a way to tweak this where I can provide an input from rtsp stream ?
b) MediaCodec API - 4.1 onwards Android has released this low level API with and MediaExtractor and MediaCodec. For this option I think an rtsp stream cannot be used in the following snippet
final String STREAM_URL = "rtsp://192.168.1.83:8001/";
MediaExtractor mediaExtractor = new MediaExtractor();
mediaExtractor.setDataSource(STREAM_URL); // I get an exception 04-28 18:30:18.914: E/AndroidRuntime(8140): Caused by: java.io.IOException: Failed to instantiate extractor.
c) Can I do a read from the url and store it like a file. How to I convert this stream to an MP4 file ? Any code snippet will be really helpful.
I had also tried to use FFMPEG but the performance was so poor that I dropped this option.
Any inputs on the above three options or any other additional option which I can consider will be greatly appreciated.
Thanks !!