HLS stream rate retention programmatically on iOS devices

I have an HD video that I transfer to an iOS app. I want the user to be able to limit the maximum stream quality (low, medium, high), given that the video has several GB when streaming at the maximum transfer rate. At the same time, I would like to automatically select a setting based on cellular Wi-Fi for obvious reasons for data limitation.

I have no problem getting the current data rate by contacting AVPlayerItemAccessLogEvent, but I get lost when it comes to the fact that you are getting a lower quality stream.

Is this possible with HLS? Thanks!

+4
source share
2 answers

This is not entirely dynamic, but I solved this problem by creating four different m3u8 playlists. I have designated each playlist to represent the quality of the stream (low, medium, high, extreme). The user will select one based on the desired maximum quality. The extreme playlist includes URLs of all qualities. A high playlist has fewer urls than the extreme, an average url less than a high, and less less urls than the medium. Whenever the user selects a different quality, I would simply switch the main streamโ€™s playlist to the corresponding playlist URL.

Here is a simple example of four different playlists.

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

#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

#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

#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

, , . .

+4

AVPlayer,

preferredPeakBitRate

Apple doc , .

+3

Source: https://habr.com/ru/post/1523969/


All Articles