[英]Downloading rtsp stream to play locally
I manage to play a live stream from a url such as this 我设法从这样的网址播放实时流
rtsp://192.168.0.18:554/user=admin&password=&channel=1&stream=0.sdp?
But I want to download this stream into a temporary file and then play it locally so that I can make it seems like the buffering time is short (around 2-4 seconds delay maybe) 但是我想将此流下载到一个临时文件中,然后在本地播放,这样我可以使缓冲时间似乎很短(可能会延迟2-4秒左右)
Is it possible to do this with rtsp
? 可以使用
rtsp
做到这一点吗? or do I have to use http
?Because this url only works on rtsp
protocol 还是我必须使用
http
?因为此网址仅适用于rtsp
协议
If so,a bit of example would help me alot 如果是这样,那么一些例子可以帮助我很多
Example of my codes 我的代码示例
cA.mPlayer1 = new MediaPlayer();
try {
cA.mPlayer1.setDataSource("rtsp://192.168.0.18:554/user=admin&password=&channel=1&stream=0.sdp?");
cA.mPlayer1.prepareAsync();
cA.mPlayer1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
cA.mPlayer1.start();
Toast.makeText(getBaseContext(), "Connecting...", Toast.LENGTH_LONG).show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
cA.mCallback1 = new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
cA.mPlayer1.setDisplay(surfaceHolder);
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
};
final SurfaceView surfaceView1 =
(SurfaceView) findViewById(R.id.surfaceView1);
// Configure the Surface View.
surfaceView1.setKeepScreenOn(true);
// Configure the Surface Holder and register the callback.
SurfaceHolder holder1 = surfaceView1.getHolder();
holder1.addCallback(cA.mCallback1);
holder1.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
you can not use MediaPlayer
to save a Raw stream in file . 您不能使用
MediaPlayer
在文件中保存Raw流。 you can use one of these : 您可以使用以下之一:
use 'vlc' to save the stream like this: https://wiki.videolan.org/Documentation:Streaming_HowTo/Receive_and_Save_a_Stream/ 使用'vlc'这样保存流: https ://wiki.videolan.org/Documentation:Streaming_HowTo/Receive_and_Save_a_Stream /
or use 'VLC lib' for android that can downloaded from : https://github.com/mrmaffen/vlc-android-sdk 或使用可从以下网址下载的Android版本的“ VLC lib”: https : //github.com/mrmaffen/vlc-android-sdk
use FFMPEG
library to record RTSP recording locally in sd card : 使用
FFMPEG
库在SD卡中本地记录RTSP记录:
1- Capture or decode the RAW frames from live stream and pass them to ffmpeg and save them to sdcard in .h264 format.
1-从实时流中捕获或解码RAW帧,然后将它们传递到ffmpeg,然后以.h264格式保存到sdcard。
2- Then again pick .h264 raw file and decode the file using ffmpeg, and save the file with extention .mp4 into sd card.
2-然后再次选择.h264原始文件,并使用ffmpeg对其进行解码,然后将扩展名为.mp4的文件保存到sd卡中。
3- delete the .h264 file programmatically, and save only .mp4, or which format you want.
3-以编程方式删除.h264文件,并仅保存.mp4或所需的格式。 Try .mp4 playback.
尝试播放.mp4。
https://stackoverflow.com/a/24586256/6502368 https://stackoverflow.com/a/24586256/6502368
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.