Selecting high bit rate video from master playlist .m3u8 to play video using AVPlayer - objective-c

I have mater playlist .m3u8 that files contain's other index file of type .m3u8 now app requirement's is to play video of high bit rate video, is it possible to achieve this and play high bit rate video using AVPlayer(apple tvOS).
Master playlist contains following index files
EXTM3U
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=378000,RESOLUTION=256x144,CODECS="avc1.42001e,mp4a.40.2"
someurl.m3u8
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2072000,RESOLUTION=480x270,CODECS="avc1.42001e,mp4a.40.2"
someurl.m3u8
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2671000,RESOLUTION=640x360,CODECS="avc1.4d001f,mp4a.40.2"
someurl.m3u8
Now according to requirement app needs to play below url from master play list.
ID=1,BANDWIDTH=2671000,RESOLUTION=640x360,CODECS="avc1.4d001f,mp4a.40.2"
someurl.m3u8
Is it possible to achieve this using AVPlayer.

Setting
player.currentItem?.preferredPeakBitRate = 2072000
only sets an upper bound on bitrate, so for example you could exclude the highest bitrate using this.
The thing is, AVFoundation will not choose a bitrate that is higher than the network connection's throughput, because that would result in choppy playback, which is not a sensible strategy.
That said, if you really want to force playback of the highest bitrate asset, you could intercept the fetching of the outer m3u8 file and suppress the lower bitrate entries, or parse the file and play the highest bitrate URL directly with AVPlayer.

Related

HLS Player: Clear video.js buffer on click

I have two live videos feeding an encoder which creates H.264 chunk files and an HLS manifest which is being served by an apache web server.
A browser page using video.js shows a player. Pressing "play" on the browser properly plays the video. It works well.
However, if we change video sources (by flipping the switch in the picture below), there is a considerable delay (10 seconds) before the new content is displayed in the player. I'd like to get that to 3 seconds.
It appears that video.js and/or the HTML5 player in browser is buffering that amount of content. (if you delete the files on the web server, kill apache, or even pull the ethernet cable, the video keeps on playing!)
A button on the web page controls the switch. When clicked, I would also like to clear or reset the player so that it immediately re-reads the index.m3u8 manifest and downloads the new chunks.
So far, haven't found anything promising searching the internet or in the video.js API docs. There are lots of articles on API calls for fetching the current buffer percentage but cannot find any API for clearing it altogether.
Any ideas?
The encoder is set for 3 second chunks and the playlist depth is set for 10 entries.
I had a similar problem. Since i could not find a reliable API for this, i came up with a rather dirty workaround to clear the buffer:
var ctime = player.currentTime();
player.currentTime(0);
player.currentTime(ctime);
This currently works for me in all major browsers.

HLS live streaming subtitle?

I am using rtmp to broadcast streams to the server and using HLS to stream the video to my device.
Is there a subtitle protocol that I can update the subtitle on real time,
for example, there is a subtitle file in server, I can keep write into that file and my player also can keep read from that file.
I know WebVTT works for recorded streaming video, but will it work for live streaming video? Can I link my player to the webVTT file and I can just update the subtitle by keeping writing to it?
You can use WebVTT to add subtitles to a live HLS stream. You do this by using a live subtitle playlist. It works just like a live playlist - you add and remove entries from it as time progresses.
First create a master playlist and add a reference to your subtitle playlist (subtitles.m3u8) to it. Here’s a (simplified) example:
#EXTM3U
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",URI="subtitles.m3u8",LANGUAGE="en"
#EXT-X-STREAM-INF:BANDWIDTH=500000,RESOLUTION=1920x1080,SUBTITLES="subs"
prog_index.m3u8
The next step is updating the subtitle playlist during the live broadcast. Let’s say your subtitle playlist looks like this initially:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10,
1.webvtt
#EXTINF:10,
2.webvtt
#EXTINF:10,
3.webvtt
Notice that the #EXT-X-ENDLIST tag is missing from the playlist. This will cause the player to keep retrieving the playlist.
Then some time later (segment duration) it will look like this:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:2
#EXTINF:10,
2.webvtt
#EXTINF:10,
3.webvtt
#EXTINF:10,
4.webvtt
And so on. You’ll probably have to write some custom code to update the subtitle playlist.

HTML5 video toggle audio tracks

Given a video file with multiple audio tracks, I'm looking for a way to toggle the played audio stream during playback to save space and add multiple different translations to the same video file. I read about the video.audioTracks property, however, according to this page it's only available in IE11+ and Safari browsers as of now. From what I've of about so far it might be possible to store the video without any audio tracks whatsoever and play the audiotracks separately (which would most likely lead to asynchronous playback). Are there any better ways of achieving this behaviour?

Html5 player only sound no picture

I have a few video files with mpeg4 format, these are not playing properly in the HTML5 player. There is sound but no picture.
Link apscservices.com/kishen_test.html
The file is working in offline players like vlc and wmp.
MP4 files can contain video and audio in a variety of formats with different profiles. However what is commonly supported in an MP4 file for HTML5 video is H.264 video (also known as MPEG-4 Part 10 or MPEG-4 AVC) High Profile or lower (i.e. no more than bit depth 8, with 4:2:0 chroma subsampling), and AAC-LC or MP3 audio. If you are using a supported audio format but an unsupported video format then you may hear sound but see no picture.
In your case you are using MPEG-4 Part 2 video, which is not commonly supported by browsers, with AAC-LC audio.

MPMoviePlayerController mp4 file streaming

I have few links to .mp4 video files like
file1.mp4
file2.mp4
file3.mp4
I need to play them all in player as one file. Actually not necessarily "as one" file, the player must act like it's one file. My best guess is to create custom controls and playback area for MPMoviePlayerController and divide the playback by time slices.
For instance
file1.mp4 file2.mp4 file3.mp4
-----------|------------|------------
Is this a good approach? Can this be done anyhow easier?
Also, the server, from which I'll get the videos is not customizable and I can't convert videos to MPEG-2 and stream them via .m3u8 files.
Thanks in advance
I guess you can use AVQueuePlayer. It supports multi-item playback. Haven't tried that myself (I used AVPlayer for single-item playback). I believe that AVQueuePlayer usage should reduce your overall efforts. ( You will still be responsible for drawing playback controls )
I sticked up to the scenario I described in the question and was able to create the player component.