I am trying to fetch bit rate at which the AVPlayer is playing the video stream . I tried with observed bit rate
property of AVPlayerItemAccessLogEvent
You are right about observedBitrate
. That shows the download speed.
The indicatedBitrate
should tell you the advertised bitrate required to play the current stream. I believe that value comes from the HLS master manifest. When playing a stream that does not have multiple bitrate variants, and there's only one bitrate variant available, the value of indicatedBitrate
will be -1
.
If you are always dealing with streams that have a master manifest, then indicatedBitrate
is the best option.
If you are dealing with streams that don't have a master manifest, then one way to estimate the bitrate is to grab the last AVPlayerItemAccessLogEvent
entry, and calculate it using:
numberOfBitsTransferred = (numberOfBytesTransferred * 8)
numberOfBitsTransferred / segmentsDownloadedDuration
Empirically speaking, every time the player switches bitrate, it will post a new access log entry. The latest access log entry will contain data about the most recently selected stream.