AVAssetReader,如何使用流而不是文件?

AVAssetReader, how to use with a stream rather than a file?

AVAssetReader 很棒,但我只能看到如何将它与本地资产、文件或我猜的合成一起使用,

所以,

assetReader = try AVAssetReader(asset: self.asset)
...
assetReader.addOutput(readerOutput)

等等,

假设您有一个到达流

(也许苹果的.M3U8文件的例子,

https://developer.apple.com/streaming/examples/)

其实AVAssetReader可以用于流吗?或者只有本地文件?

我只是在任何地方都找不到这个解释。 (如果你更熟悉它,也许它是显而易见的。:/ )

不明显。将 AVAssetReaderAVComposition 的头文件注释拼凑在一起给人一种 API 仅为本地资产设计的强烈印象,尽管该语言并未明确排除非本地资产。

来自 AVAssetReader 头文件:

Instances of AVAssetReader read media data from an instance of AVAsset, whether the asset is file-based or represents an assembly of media data from multiple sources, as is the case with AVComposition.

来自 AVComposition:

An AVComposition combines media data from multiple local file-based sources in a custom temporal arrangement, in order to present or process media data from multiple sources together. All local file-based audiovisual assets are eligible to be combined, regardless of container type.

如果您只对视频感兴趣,并且不介意将处理作为播放的一部分,则可以通过向 AVPlayerItem 添加 AVPlayerItemVideoOutput 从远程资产捕获帧。如果您对音频感兴趣,那您就上当了。