使用AVFoundation在iOS上播放socket-streamamed h.264电影 [英] Play socket-streamed h.264 movie on iOS using AVFoundation

查看:113
本文介绍了使用AVFoundation在iOS上播放socket-streamamed h.264电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款小型iPhone应用程序,它使用常规套接字通过网络连接流式传输电影内容。该视频采用 H.264 格式。然而,我在播放/解码数据方面遇到了困难。我一直在考虑使用 FFMPEG ,但许可证使它不适合该项目。我一直在研究Apple的 AVFoundation 框架(特别是 AVPlayer ),它似乎能够处理h264内容但是我只能找到使用url启动电影的方法 - 而不是通过证明从网络流式传输的内存缓冲区。

I’m working on a small iPhone app which is streaming movie content over a network connection using regular sockets. The video is in H.264 format. I’m however having difficulties with playing/decoding the data. I’ve been considering using FFMPEG, but the license makes it unsuitable for the project. I’ve been looking into Apple’s AVFoundation framework (AVPlayer in particular), which seems to be able to handle h264 content, however I’m only able to find methods to initiate the movie using an url – not by proving a memory buffer streamed from the network.

我一直在做一些测试,无论如何都要使用以下方法:

I’ve been doing some tests to make this happen anyway, using the following approaches:


  1. 使用常规 AVPlayer 播放电影。每次在网络上接收数据时,都会使用fopen和append-mode将其写入文件。然后使用更新的数据重新加载/重新创建 AVPlayer 的资产。这种方法似乎存在两个问题:首先,当第一个资产被卸载并且新加载时,屏幕会短暂变黑。其次,我不确切知道播放的确切位置,所以我不确定如何找到合适的地方开始播放新资产。

  2. 第二种方法是写与第一种方法一样,数据到文件,但不同之处在于数据被加载到第二个资产中。然后使用 AVQueuedPlayer ,其中第二个资产在播放器中插入/排队,然后在缓冲完成后调用。然后可以在没有黑屏的情况下卸载第一个资产。但是,使用这种方法,找出从哪里开始播放新资产更麻烦(比第一种方法)。

  1. Play the movie using a regular AVPlayer. Every time data is received on the network, it’s written to a file using fopen with append-mode. The AVPlayer’s asset is then reloaded/recreated with the updated data. There seems to be two issues with this approach: firstly, the screen goes black for a short moment while the first asset is unloaded and the new loaded. Secondly, I do not know exactly where the playing stopped, so I’m unsure how I would find out the right place to start playing the new asset from.
  2. The second approach is to write the data to the file as in the first approach, but with the difference that the data is loaded into a second asset. A AVQueuedPlayer is then used where the second asset is inserted/queued in the player and then called when the buffering has been done. The first asset can then be unloaded without a black screen. However, using this approach it’s even more troublesome (than the first approach) to find out where to start playing the new asset.

有没有人做过这样的事情并使其有效?是否有正确的方法使用 AVFoundation

Has anyone done something like this and made it work? Is there a proper way of doing this using AVFoundation?

推荐答案

这样做的官方方法是HTTP Live Streaming格式,它支持多种质量等级(以及其他内容)并自动在它们之间切换(例如:如果用户从WiFi移动到手机)。

The official method to do this is the HTTP Live Streaming format which supports multiple quality levels (among other things) and automatically switches between them (eg: if the user moves from WiFi to cellular).

您可以在此处找到文档: Apple Http Streaming Docs

You can find the docs here: Apple Http Streaming Docs

这篇关于使用AVFoundation在iOS上播放socket-streamamed h.264电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆