【问题标题】:Capture a RTSP Stream on an android device在 Android 设备上捕获 RTSP 流
【发布时间】:2024-01-11 21:45:01
【问题描述】:

我想用我的 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。

有人知道如何解决这个问题吗?

【问题讨论】:

  • 你找到解决办法了吗???

标签: android capture rtsp


【解决方案1】:

【讨论】:

  • 是的,其中提到了创建自定义 URLStreamHandlerFactory 并使用 setURLStreamHandlerFactory (URLStreamHandlerFactory factory) 方法将其设置在 URL 中,但神秘的部分是如何创建 RTSP URLStreamHandlerFactory???
【解决方案2】:

您可以通过 JNI/NDK 使用 ffmpeg 库来捕获 rtsp 流。这不是很容易,但确实有效。

【讨论】: