5

I have an iOS app that streams video on iPhone/iPad devices.

Now I need to get the bitrate on video streaming on the iPhone/iPad device. ObservedBitrate and IndicatedBitrate does not help with this.

I also came across this below post but few comments mention it works for mpeg4 videos only. How to check Resolution, bitrate of video in iOS

I'm looking for the bitrate of video streaming on iPhone/iPad and for any video format.

Thanks!

Raptor
  • 53,206
  • 45
  • 230
  • 366
sia
  • 1,872
  • 1
  • 23
  • 54
  • 1. what is the steaming protocol being used? Please provide an example. 2. what does `ObservedBitrate` and `IndicatedBitrate` tell? 3. where are your codes? – Raptor Mar 22 '21 at 04:38
  • @Raptor - using ABR over http. While observedbitrate is in range of 2-3 mbps while indicated also similar . Me looking for - is there any way to get actual video streaming bitrate - formula or any property. – sia Mar 22 '21 at 04:42
  • AVPlayerItemAccessLogEvent - does not hv any even for video streaming bitrate. – sia Mar 22 '21 at 04:44
  • So what is the expected bitrate? using Adobe HTTP Dynamic Streaming or Apple HTTP Live Streaming? – Raptor Mar 22 '21 at 04:45
  • Does [this](https://stackoverflow.com/questions/28964053/detect-when-avplayer-switch-bit-rate) help? – Raptor Mar 22 '21 at 04:49
  • USING Apple HTTP Live Streaming – sia Mar 22 '21 at 04:58
  • @raptor -I had tried - switchBitrate also.. does not help. – sia Mar 22 '21 at 04:58
  • Can you elaborate "does not help" by adding codes in your questions, and indicate your expected results. Currently the question is a bit too vague without details. – Raptor Mar 22 '21 at 05:01

1 Answers1

2

You can listen for AVPlayerItemNewAccessLogEntry notification to get current bitrates for your stream such as:

  • observedBitrate - aka your current download speed
  • indicatedBitrate - comes from m3u8 (BANDWIDTH) and means a min bitrate value to play your current stream

Adaptive video playback with AVPlayer can change a current stream to a stream with high or low bandwidth back and forth by network conditions but these changes do not appears on every stalls, network issues etc. because your steam can be buffered, m3u8 doesn't have stream with lower bandwidth to play etc. So if you need to detect a current realtime playback state look to stalls, FPS.

There is sample code in swift but it's easy convertible to objc if you need:

let url = URL(string: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8")!
let playerItem = AVPlayerItem(url: url)
self.player = AVPlayer(playerItem: playerItem)

NotificationCenter.default.addObserver(forName: .AVPlayerItemNewAccessLogEntry, object: playerItem, queue: nil) { notification in
    if let event = playerItem.accessLog()?.events.last {
        let bitrates = [event.observedBitrate,
                        event.indicatedBitrate,
                        event.averageVideoBitrate,
        ]
        print(">", bitrates)
    }
}

player?.play()

let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = view.bounds
view.layer.addSublayer(playerLayer)

Outputs:

> [16375938.865617642, 628000.0, 307568.0]
> [nan, 1728000.0, 0.0]
> [9830221.39078689, 2528000.0, 1422032.0]


iUrii
  • 11,742
  • 1
  • 33
  • 48
  • I have done the exact thing you mentioned above but with some of my own urls: http://stream.radiojar.com/nhq0vcqwuueuv or https://ice1.somafm.com/groovesalad-128-mp3 - the notification does not get called – Shawn Frank Jun 17 '21 at 11:35