将RTSP流保存到android中的mp4文件 [英] Save a RTSP stream to mp4 file in android
本文介绍了将RTSP流保存到android中的mp4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个项目中,我需要从IPCamera读取输入流.我可以通过rtsp网址获取该信息.
I am working on a project where I need to read input stream from an IPCamera. I am able to fetch this in through an rtsp url.
显示IPCamera流.我可以使用-
Display the IPCamera stream. I am able to do same by using -
videoView = (VideoView) this.findViewById(R.id.videoView1);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("rtsp://xxxxxxxx/camera1"));
videoView.requestFocus();
现在,我想将此流记录到MP4文件中.同样,我正在使用mediarecorder.在这里,我被卡住了.
Now I want to record this stream to an MP4 file. For same I am using mediarecorder.Here I am stuck.
MediaRecorder mediaRecorder = new MediaRecorder();
//mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setOutputFile("rtsp://xxxxxxxxx/camera1");
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaRecorder.start();
谢谢
推荐答案
使用ffmpeg
.
-
添加
ffmpeg
依赖项.
compile 'nl.bravobit:android-ffmpeg:1.1.5'
记录流.
Record Stream.
String RTSP_URL = "rtsp://<your_rtsp_url>";
final File targetFile = new File( getExternalStoragePublicDirectory( Environment.DIRECTORY_MOVIES ) + "/recording1.mp4" );
final FFmpeg ffmpeg = FFmpeg.getInstance(this);
String[] ffmpegCommand = new String[]{ "-i", RTSP_URL, "-acodec", "copy", "-vcodec", "copy", targetFile.toString() };
final FFtask ffTask = ffmpeg.execute( ffmpegCommand, new FFcommandExecuteResponseHandler() {
@Override
public void onStart() {}
@Override
public void onProgress(String message) {}
@Override
public void onFailure(String message) {}
@Override
public void onSuccess(String message) {}
@Override
public void onFinish() {}
} );
final Timer timer = new java.util.Timer();
TimerTask timerTask = new TimerTask() { @Override public void run() {
ffTask.sendQuitSignal();
} };
timer.schedule( timerTask, 30000 ); // Will stop recording after 30 seconds.
这篇关于将RTSP流保存到android中的mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文