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

旧街凉风 提交于 2019-12-24 04:29:15

问题


AVAssetReader is fantastic, but I can only see how to use it with a local asset, a file, or I guess a composition,

So,

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

and so on,

Say you have an arriving stream

(perhaps Apple's examples of .M3U8 files,

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

In fact, can AVAssetReader be used for streams? Or only local files?

I just plain cannot find this explained anywhere. (Maybe it's obvious if you're more familiar with it. :/ )


回答1:


It's not obvious. Patching together the header file comments for both AVAssetReader and AVComposition gives the strong impression of an API designed only for local assets, although the language does not explicitly rule out non-local assets.

From the AVAssetReader header file:

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.

and from 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.

If you're interested in video only, and don't mind processing as part of playback, you can capture frames from a remote asset by adding an AVPlayerItemVideoOutput to your AVPlayerItem. If you're interested in audio, you're up a creek.



来源:https://stackoverflow.com/questions/53796395/avassetreader-how-to-use-with-a-stream-rather-than-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!