在 Android 设备上捕获 RTSP 流
我想使用 Nexus S 从网络摄像机捕获 RTSP 视频流。使用 VideoView 和媒体播放器观看流是没有问题的。
我尝试像这样保存它:
URL url = new URL("rtsp://192.168.4.222:554/ipcam.sdp");
URLConnection ucon = url.openConnection();
ucon.connect();
InputStream is = ucon.getInputStream();
fos = new FileOutputStream(VideoFile);
bis = new BufferedInputStream(is);
isRecording = true;
baf = new ByteArrayBuffer(50);
int current = 0;
FileOutputStream fos = new FileOutputStream(VideoFile);
while (((current = bis.read()) != -1) & isRecording) {
baf.append((byte) current);
fos.write(baf.toByteArray());
baf.clear();
}
fos.close();
我收到 MalformedURLException,因为 android 不支持 rtsp:// url。
有人知道如何解决这个问题吗?
I want to capture a RTSP video stream from an ip camera with my Nexus S. To watch the stream with a VideoView and the mediaplayer is no problem.
I tried to save it like this:
URL url = new URL("rtsp://192.168.4.222:554/ipcam.sdp");
URLConnection ucon = url.openConnection();
ucon.connect();
InputStream is = ucon.getInputStream();
fos = new FileOutputStream(VideoFile);
bis = new BufferedInputStream(is);
isRecording = true;
baf = new ByteArrayBuffer(50);
int current = 0;
FileOutputStream fos = new FileOutputStream(VideoFile);
while (((current = bis.read()) != -1) & isRecording) {
baf.append((byte) current);
fos.write(baf.toByteArray());
baf.clear();
}
fos.close();
I get a MalformedURLException, because android doesn't support rtsp:// urls.
Has somebody an idea how to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 http://developer.android.com/reference/java/net/URLConnection .html RTSP 尚不受支持的协议
According to http://developer.android.com/reference/java/net/URLConnection.html RTSP is not a supported protocol yet
您可以通过 JNI/NDK 使用 ffmpeg 库来捕获 rtsp 流。这不是很容易,但确实有效。
You can use ffmpeg libraries through JNI/NDK to capture an rtsp stream. It's not very easy, but it does work.