android h264转mp4文件,Android - Save an rtsp (h264) stream to mp4 file

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 !!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值