Unable to get tracks of AVAsset using HLS while retrieveing bitrate

回眸只為那壹抹淺笑 提交于 2019-12-06 09:25:07

问题


I am using HLS streaming in my application and I am using AVPlayer. Now I want to get bitrate of the video track using AVAsset. Although I have added observer and other stuff I am getting tracks array as empty always.Am I on right track or missing anything?


回答1:


HLS is adaptive, therefore, bitrate can vary across the duration of the stream based on various conditions. You are on completely the wrong track, unlike playing a file, either local or from a network URL, currentItem.asset.tracks will always be nil.

You'll need to query the AVPlayer's currentItem's accessLog and inspect the appropriate "events".

The following from the documentation should give you the information you need;

Look at ;

AVPlayerItemAccessLog

and

AVPlayerItemAccessLogEvent

EDIT:

You might benefit from reading apple's Live streaming overview this will give you a better understanding of the .m3u8 index files, specifically that the media file can be encoded for various bit rates to accommodate different network throughput/congestion. The client is responsible for switching between segments encoded at different bit rates.

The observedMinBitrate and observedMaxBitrate are likely to be the properties you'll find most useful, however withought knowing your intended use, it's hart to say if any will suffice. Keep in mind also, as per the Docs, these are Per Segment (refer to the overview for a better understanding of segment).




回答2:


An AVPlayerItem has a tracks property, which is an array of AVPlayerItemTracks. These probably represent the current tracks that are loaded in the AVPlayerItem. They will change as playback progresses and can be observed via KVO. An AVPlayerItemTrack has an assetTrack property referencing an AVAssetTrack. Video, audio, closed captions, and all variants of those will appear as independent tracks. Their types can be inspected via their mediaType property if you're only interested in video -- though you may be interested in all enabled tracks. An AVAssetTrack has an estimatedDataRate which may be what you're looking for.

You can find sparse documentation of these classes and properties by drilling down from AVPlayerItem.



来源:https://stackoverflow.com/questions/31289200/unable-to-get-tracks-of-avasset-using-hls-while-retrieveing-bitrate

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