How to find AVPlayer current bitrate

后端 未结 1 1114
粉色の甜心
粉色の甜心 2021-02-04 19:57

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

相关标签:
1条回答
  • 2021-02-04 20:51

    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.

    0 讨论(0)
提交回复
热议问题