Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get tracks of AVAsset using HLS while retrieveing bitrate

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?

like image 249
Pooja M. Bohora Avatar asked Sep 14 '25 22:09

Pooja M. Bohora


1 Answers

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).

like image 137
MDB983 Avatar answered Sep 17 '25 13:09

MDB983