如何在 iOS 中显示来自 IP Camera/CCTV 的 RTSP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15063720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:26:18  来源:igfitidea点击:

How to display RTSP from IP Camera/CCTV in iOS

iosios4streamingvideo-streaminglive-streaming

提问by vulvaji

There is obviously a way to do this because so many applications are already doing it - NetCamViewer and iCamviewer to name just one.

显然有一种方法可以做到这一点,因为很多应用程序已经在这样做了——NetCamViewer 和 iCamviewer 仅举一个例子。

I have searched and searched, but I'm not finding anything of value that gives a hint as to how this is done. I'm reaching out hoping that someone will give me a clue.

我已经搜索了又搜索,但我没有找到任何有价值的东西来暗示这是如何完成的。我伸出手希望有人能给我一个线索。

I'm trying to connect to an video security camera (Y-CAM), which supports the RTSP protocol, and display the video from my iPhone/iPad application. The camera has an IP address and I can view the video from a web browser and from Quicktime running on my Mac. The problem is that RSTP is not supported on iOS so even trying to connect using Safari on an iPad doesn't work.

我正在尝试连接到支持 RTSP 协议的视频安全摄像头 (Y-CAM),并显示来自我的 iPhone/iPad 应用程序的视频。摄像头有一个 IP 地址,我可以从 Web 浏览器和 Mac 上运行的 Quicktime 查看视频。问题是 iOS 不支持 RSTP,因此即使尝试在 iPad 上使用 Safari 进行连接也不起作用。

I've read that some are trying to use Live5555, but I haven't seen an article that describes if it has been done successfully and how.

我读过一些人正在尝试使用 Live5555,但我还没有看到一篇文章描述它是否已经成功完成以及如何完成。

An alternative is to capture the RTSP stream on a server, convert it to an HTTP Live stream and then connect to the HTTP Live stream from iOS. Unfortunately, this hasn't proved as easy as it sounds.

另一种方法是在服务器上捕获 RTSP 流,将其转换为 HTTP Live 流,然后从 iOS 连接到 HTTP Live 流。不幸的是,事实证明这并不像听起来那么容易。

I'd prefer to go directly to the camera like other applications I've seen do. the RTSP to Live is a fall back if I have to.

我更喜欢像我见过的其他应用程序一样直接进入相机。如果我必须的话,RTSP to Live 是一个退路。

Any hints are greatly appreciated. Thanks!

任何提示都非常感谢。谢谢!

回答by Tarum

This is wrong :) or not necessary (An alternative is to capture the RTSP stream on a server, convert it to an HTTP Live stream and then connect to the HTTP Live stream from iOS. Unfortunately, this hasn't proved as easy as it sounds.)

这是错误的 :) 或没有必要(另一种方法是在服务器上捕获 RTSP 流,将其转换为 HTTP Live 流,然后从 iOS 连接到 HTTP Live 流。不幸的是,事实证明这并不容易声音。)

You should use ffmpeg library, as this library can connect any streaming server (supporting rtsp, mms, tcp, udp ,rtmp ...) and then draw pictures to the screen.. (for drawing you can use opengles or uiimage also works)

您应该使用 ffmpeg 库,因为该库可以连接任何流媒体服务器(支持 rtsp、mms、tcp、udp、rtmp ...),然后将图片绘制到屏幕上..(对于绘图,您可以使用 opengles 或 uiimage 也可以)

First of all, use avformat_open_input to connect to your ip address then use avcodec_find_decoder & avcodec_open2 to find codecs and to open them (you should call them for both audio & video)

首先,使用 avformat_open_input 连接到您的 IP 地址,然后使用 avcodec_find_decoder & avcodec_open2 查找编解码器并打开它们(您应该为音频和视频调用它们)

Then, in a while loop read packets from server by using av_read_frame method When you get frame, if it is audio then sent it to AudioUnit or AudioQueue, if it is video, then convert it from yuv to rgb format by using sws_scale method and draw the picture to the screen.

然后,在while循环中使用av_read_frame方法从服务器读取数据包当您获得帧时,如果是音频则将其发送到AudioUnit或AudioQueue,如果是视频,则使用sws_scale方法将其从yuv格式转换为rgb格式并绘制图片到屏幕。

That's all.

就这样。

look at this wrapper also (http://www.videostreamsdk.com), it's written on ffmpeg library and supports iOS

也看看这个包装器(http://www.videostreamsdk.com),它写在 ffmpeg 库上,支持 iOS

回答by Michelle Cannon

You really need to search stack overflow before posting , this question has been asked many times. Yes live 555 sort of works and some of us have gotten it to work..

你真的需要在发布之前搜索堆栈溢出,这个问题已经被问过很多次了。是的,有 555 种作品,我们中的一些人已经开始使用它了。

There are other players too, including ours http://www.streammore.tv/

还有其他玩家,包括我们的http://www.streammore.tv/

回答by Spawnrider

You can find an open source FFMepg Decoderfor iOS (and somes samples) on GitHub : https://github.com/mooncatventures-group

您可以在 GitHub 上找到适用于 iOS 的开源FFMepg 解码器(和一些示例):https: //github.com/mooncatventures-group

Sample use of this library : http://sol3.typepad.com/exotic_particles/

该库的示例使用:http: //sol3.typepad.com/exotic_particles/

回答by ankitr

There are two general technology to display RTSP video on iOS Safari:

在 iOS Safari 上显示 RTSP 视频有两种通用技术:

  • RTSP / HLS (H.264+AAC)
  • RTSP / Websocket (H.264+AAC ==> MPEG+G.711 or H.264+?)
  • RTSP / HLS (H.264+AAC)
  • RTSP / Websocket(H.264+AAC ==> MPEG+G.711 或 H.264+?)

For HLS you can consider Wowza server. For Websocket playback in iOS Safari you can use WCS4 server.

对于 HLS,您可以考虑 Wowza 服务器。对于 iOS Safari 中的 Websocket 播放,您可以使用WCS4 服务器

Main idea for websocket playback is direct HTML5 rendering to HTML page Canvas element and audio context. In the case of MPEG playback video decoding will be done on iOS Safari side using plain JavaScript.

websocket 播放的主要思想是将 HTML5 直接渲染到 HTML 页面 Canvas 元素和音频上下文。在 MPEG 播放的情况下,视频解码将在 iOS Safari 端使用纯 JavaScript 完成。

Another option - install a WebRTC plugin with getUserMedia support and play this stream via WebRTC. Anyway you will need a server side RTSP-WebRTC transcoder in such case.

另一种选择 - 安装支持 getUserMedia 的 WebRTC 插件并通过 WebRTC 播放此流。无论如何,在这种情况下,您将需要一个服务器端 RTSP-WebRTC 转码器。