Video Quality selection in HLS streams

Hello there,
in our team we were requested to add the possibility to manually select the video quality. I know that HLS is an adaptive stream and that depending on the network condition it choose the best quality that fits to the current situation.

I also tried some setting with preferredMaximumResolution and preferredPeakBitRate but none of them worked once the user was watching the steam. I also tried something like replacing the currentPlayerItem with the new configuration but anyway this only allowed me to downgrade the quality of the video. When I wanted to set it for example to 4k it did not change to that track event if I set a very high values to both params mentioned above.

My question is if there is any method which would allow me to force certain quality from the manifest file. I already have some kind of extraction which can parse the manifest file and provide me all the available information but I couldn't still figure out how to make the player reproduce specific stream with my desired quality from the available playlist.

Accepted Reply

As you've discovered, preferredMaximumResolution and preferredPeakBitRate should generally be sufficient to handle the mobile data case, where you want to downgrade network usage.

If the user wants to upgrade quality, I think it's not going to work out well to assume that a content quality decision can be made from the HLS playlist alone. The decision should probably be made at the content server, either with multiple static playlists pre-built for each quality level, or dynamic playlists generated at client request.

Keep in mind that stalling is not the only possible problem with high-quality streams. More likely, dropped frames and inconsistent frame rates might be perceived as lower quality than a lower quality variant that streams smoothly. This might be a case where giving the user the appearance of a choice leads to a worse outcome than no choice. (I'm not sure, but it's something worth thinking about.)

Replies

The short answer is that there isn't any way to do this. Dynamically monitoring network conditions, and dynamically switching between variants, is integral to HLS.

What is your use-case for downgrading during playback? If the user's playback and network has already established that a given variant is the best choice, why would the user or your app want to limit that?

@Polyphonic first thanks for you answer. What I am trying to achieve is implement a video quality picker in our app where the user can pick specific quality of the stream available from the manifest (something like youtube has) so for example even if the user doesn't have a great network connection but he wants/needs to see the video in high quality and don't care about stalling make this possible for him and prevent the AVPlayer switching the video back to lower quality and keep the one that our user selects.

Other use case may be when you are watching video using mobile data. Some users have unlimited data plans and don't care about data consumption but others may have limited data plans and want to switch to lower qualities.
As you've discovered, preferredMaximumResolution and preferredPeakBitRate should generally be sufficient to handle the mobile data case, where you want to downgrade network usage.

If the user wants to upgrade quality, I think it's not going to work out well to assume that a content quality decision can be made from the HLS playlist alone. The decision should probably be made at the content server, either with multiple static playlists pre-built for each quality level, or dynamic playlists generated at client request.

Keep in mind that stalling is not the only possible problem with high-quality streams. More likely, dropped frames and inconsistent frame rates might be perceived as lower quality than a lower quality variant that streams smoothly. This might be a case where giving the user the appearance of a choice leads to a worse outcome than no choice. (I'm not sure, but it's something worth thinking about.)

Hi @RaulBatista . I've found open source project which allows you to change between qualities while player is playing.

[https://github.com/IvanoBilenchi/Adaptive-Video-Player)