简体   繁体   English

在iOS设备上以编程方式限制HLS流的比特率

[英]Capping the bit rate of an HLS stream programmatically on iOS devices

I have an HD video that I am streaming to an iOS app. 我有一个高清视频,我正在流媒体到iOS应用程序。 I want to allow the user the ability to cap the max stream quality (low, medium, high) considering the video is several GBs when streaming at the max bit rate. 我想让用户能够限制最大流质量(低,中,高),考虑到以最大比特率流式传输时视频为几GB。 Along the same lines, I would like to automatically choose a setting based on cellular vs wifi connection, for the obvious data-cap reasons. 同样,我想根据明显的数据上限原因自动选择基于蜂窝与wifi连接的设置。

I have no problem getting the current bit rate by accessing the AVPlayerItemAccessLogEvent , but am lost when it comes to forcing a lower quality stream. 通过访问AVPlayerItemAccessLogEvent获取当前比特率没有问题,但是在强制降低质量流时丢失了。

Is this even possible with HLS? 这对HLS来说甚至可能吗? Thanks! 谢谢!

It's not exactly dynamic, but I did solve this problem by creating four different m3u8 playlists. 它不是完全动态的,但我确实通过创建四个不同的m3u8播放列表来解决这个问题。 I labeled each playlist to represent a stream quality (low, medium, high, extreme). 我将每个播放列表标记为代表流质量(低,中,高,极端)。 The user would select one based on the desired max quality. 用户将根据所需的最高质量选择一个。 The extreme playlist includes the URLs of all qualities. 极端播放列表包含所有品质的URL。 The high playlist has less URLs than the extreme, the medium less URLs than the high, and the low less URLs than the medium. 高播放列表的URL少于极端,URL少于高,URL少于媒体。 Whenever the user selects a different quality, I would just switch the base stream playlist to the respective quality playlist URL. 每当用户选择不同的质量时,我只需将基本流播放列表切换到相应的质量播放列表URL。

Here is a simple example of the four different playlists. 以下是四个不同播放列表的简单示例。

HLS_Movie_Extreme.m3u8 HLS_Movie_Extreme.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000
stream-0-64000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000
stream-1-350000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=800000
stream-2-800000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000
stream-3-1200000/index prog_index.m3u8 m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1800000
stream-4-1800000/prog_index.m3u8

HLS_Movie_High.m3u8 HLS_Movie_High.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000
stream-0-64000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000
stream-1-350000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=800000
stream-2-800000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000
stream-3-1200000/index prog_index.m3u8 m3u8

HLS_Movie_Medium.m3u8 HLS_Movie_Medium.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000
stream-0-64000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000
stream-1-350000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=800000
stream-2-800000/prog_index.m3u8

HLS_Movie_Low.m3u8 HLS_Movie_Low.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000
stream-0-64000/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000
stream-1-350000/prog_index.m3u8

Like I said, it's not dynamic, but you could use various techniques to get the users network connection and point to the desired quality playlist if needed. 就像我说的那样,它不是动态的,但你可以使用各种技术来获得用户的网络连接,并在需要时指向所需的质量播放列表。 For me, it was sufficient to get the user's preference, and adjust the stream accordingly. 对我来说,获得用户的偏好就足够了,并相应地调整流。

If you are using AVPlayer, the right way should be 如果您使用的是AVPlayer,那么正确的方法应该是

preferredPeakBitRate

From Apple doc here , The desired limit, in bits per second, of network bandwidth consumption for this item. 此处的 Apple doc,此项目的网络带宽消耗的所需限制(以每秒位数为单位)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM