How to change video playback quality in AVPlayer?

How can I change video quality like YouTube?

I am currently playing with original quality and I give options like 360p, 480p, 720p to change the quality.

How can I change this?

+3


source to share


3 answers


You cannot simply do this with AVplayer

. you need a different url for high quality video. When the user chooses a different quality, you can switch to this video using the replaceCurrentItemWithPlayerItem method for the AVPlayer.



AVPlayerItem *playeriem= [AVPlayerItem playerItemWithURL:urlOfSelectedQualityVideo];
[playeriem seekToTime:player.currentTime];
[player replaceCurrentItemWithPlayerItem:playeriem];

      

+3


source


To do things like converting videos, you have to use the FFmpeg library . Try to find some libraries that use ffmpeg for github.

Like this one: https://github.com/iMoreApps/ffmpeg-avplayer-for-ios-tvos



You cannot do this with AVPlayer. When streaming, you use M3U index files, TS files containing video data, and just switch streams.

Check out Apple HLS Documentation and Playlist Examples .

+3


source


You can also create multiple versions of m3u8 with lower quality video streams, say 128k to 650k and another from 650k to higher bitrates, and use the higher quality url suggested in the answer above.

AVPlayerItem *playeriem= [AVPlayerItem playerItemWithURL:urlOfSelectedQualityVideo];

      

+1


source







All Articles