如何在 iOS 上播放从套接字手动加载的视频?
这是相当棘手的一个......
我正在尝试在 iOS 上通过网络传输视频(H264)。但是,我通过远程服务器的打开套接字(使用 CocoaAsyncSocket)将视频数据放入缓冲区,因此我没有可用于创建 AVAsset 或 MPMoviePlayer 的视频 URL。该视频是实时流,因此如果有任何区别,数据将不断出现(即没有设置持续时间)。
我必须这样做,因为服务器是 RTSP 服务器。我已经编写了自己的 RTSP 客户端,用于发送命令和接收响应,现在我尝试对通过连接传输的视频数据做一些有用的事情。
关于如何播放该视频有什么想法吗?我目前唯一能想到的就是以某种方式保存到文件并加载该文件(但我不知道这是如何工作的,因为我将不断加载新数据),或者以某种方式手动执行某些操作像 ffmpeg 一样。不,不幸的是我无法让服务器进行 HTTP Live Streaming。
任何帮助将不胜感激!
Rather tricky one this...
I'm trying to stream a video (H264) across a network on iOS. However, I'm getting the video data into a buffer through an open socket to the remote server (using CocoaAsyncSocket), so I don't have a URL to the video that I can use to create an AVAsset or an MPMoviePlayer. The video is a live stream, so the data will just keep coming (i.e. No set duration) if that makes any difference.
I'm having to do it this way as the server is an RTSP server. I've written my own RTSP client for the sending of commands and receiving of responses, and now I'm trying to do something useful with the video data that comes over the connection.
Any ideas on how I can play back this video? The only things I can think of currently are somehow saving to a file and loading that (but I don't see how that'll work, as I'll be continually loading new data), or resorting to doing it manually somehow with something like ffmpeg. And no, unfortunately I can't make the server do HTTP Live Streaming instead.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有深入研究 AVFoundation,但您也许可以通过使用
AVAssetWriter
创建一个AVAsset
来实现它。您提供AVAssetWriter
一个AVAssetWriterInput
实例,它获取CMSampleBuffer
数据并将其打包以供AVAssetWriter
使用。基于 文档 code>AVAssetWriterInput,它旨在从“实时源”获取数据。
我希望我能提供更多帮助,但希望这能为您指明正确的方向。
I haven't had to dig this deeply into AVFoundation yet, but you might be able to pull it off by creating an
AVAsset
with anAVAssetWriter
. You provideAVAssetWriter
an instance ofAVAssetWriterInput
which takesCMSampleBuffer
data and packages it up for theAVAssetWriter
.Based on the docs for
AVAssetWriterInput
, it is designed to take data from a "real-time source".I wish I could be of more help, but hopefully this will point you in the right direction.