MPmovieplayer and streaming m3u8 file? - ios

Am using MPMoviePlayerController to stream n play a video. Its, in m3u8 format and plays with no problems. However, lets say it has buffered n played 50% of the total video, now if i seek backward, it starts buffering from that point. shouldn't it just play the video and not buffer from the seeked point as it has already buffered that part..??
This behaviour is observed only in case of m3u8 file, if I play a mp4 file, it doesn't do that. I mean, it won't buffer again.
So, is this an expected behaviour or am I just missing something..?
Thanks in advance.

m3u8 is a playlist file. It has links to either other playlist files or video files in TS(transport stream) format. The ts files are most commonly 10 seconds chunks of video. So, every N(10) seconds it fetches a new stream.So, when you seek, it will go and fetch the stream that had that chunk of the video. So, you will see buffering again.

Related

Adding an external audio track to HLS video

I am using AVPlayer to run a HLS video. The video has no sound. Also i have a audio track url of same format m3u8. Can i somehow change the AVPlayer item asset or something while running my video without sound to add my other audio track so that they are sort of played together.
Disappointingly, you can't create an AVComposition using non local video and audio tracks and play that.
But HLS is at its heart a sort of textual playlist consisting of media pieces that can be played either serially or concurrently. If you inspect both your video and audio m3u8 streams, you should be able to concoct a new single m3u8 stream that includes both video and audio.
HOWEVER, disappointingly, it seems you can't play this resulting stream as a local file (why!?!), so you'd set up an http server to serve it to you, either locally or from or afar, or maybe (!?) you could avoid all that with a clever use of AVAssetResourceLoaderDelegate.
It also seems synchronising two AVPlayers is unsupported too, although perhaps that situation has improved.

How to setup HLS Live Video Streaming from iOS Device

Good day everyone!
So, as the title suggests, i am developing an app with similar functionality to that off Periscope and Facebook Live video streaming. Here is what the end goal is:
A Broadcasting device [user]
EC2 Instance [Hosting an ffmpeg transcoder]
Cloudfront Distrubution [CDN]
1 to n viewers of the live feed
I've been doing a lot of googling and what I cant seem to figure out is:
As you send chunks of video to the server from the Broadcaster, how do
you create an
.m3u8 playlist when you don't have all the chunks of video yet (e.g. the
device sends its first 5second chunk of video)?
It seems a .m3u8 file is created from a .mp4 file that is already complete, then broken down into chunks... But i'm sending chunks of the video to the server, how can it generate the .m3u8 file when more chunks are still coming from the Broadcaster, so the watchers / clients can continuously stitch together the video chunks?
I'll be happy to clarify this question further. Thanks!
If you take a look at the docs for the segment muxer you can specify the m3u8 to be outputted and you can also tell it to update the m3u8 as it goes. It might look something like this:
ffmpeg -i infile.mp4 -c:v copy -c:a copy -map 0 -f ssegment -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 10 -segment_list_flags +live -segment_time 4 outchunk%07d.ts
Note the segment_list_size is the maximum number of chunks referenced in the m3u8 file at one time and the segment_list_flags tells ffmpeg that this a live stream.
I think your confusion is that you are trying to send HLS fragments to their server. Don’t. Send a stream via another protocol like RTPM. Then let the server convert to HLS.

How to download a LIVE HLS m3u8 stream on iOS

HLS streams can be "live" or "VOD". Downloading a VOD HLS stream is easy.
However, I want to download (or record) say 5 minutes of a LIVE HLS stream. Is this possible?
If I do so, I am sure I have to make significant changes to the m3u8 file... One reason is live streams do not have a "duration", but the stream I download has to be streamed as VOD so it must have a duration. There might be various other changes required that I am not aware of. Presumably URLs of ts segments would also need to be changed.
Any tips or advice (hopefully actual code!)?
Thanks!
PS. Note that this question is not about playing back the stream in offline mode - I know I need an HTTP server for that.
The Live playlist uses a sliding-window. You need to periodically reload it after target-duration time and download only the new segments as they appear in the list (they will be removed at a later time).
Save the #EXTINF for each segment and start writing them in a VOD playlist using the same target-duration and a media sequence starting at 0.
When you want to stop recording add the EXT-X-ENDLIST tag at the end.
It doesn't matter how you name your segments as long as you use the same name in the m3u8.

MP3 stream record, flat line in waveform record glitch

I record audio streams as byte sequence, for playing via https://github.com/mattgallagher/AudioStreamer.
If i play mp3 stream from URL it plays fine, but if i play it from local file it has glitches, i opened file in audio editor, i see flat lines in place of glitches in record(on screenshot), when i remove this flat lines in editor record works fine.
I also opened record in Audacity and it open it without this lines, and play audio without glitches, but when i open record in my app, or in any mac audio player it play with this glitches.
My record algorithm is simple, i just add bytes from stream to NSMutableData and write it in file, and then open it via same AudioStreamer like stream but from local file system.
Also i save structures for play, like AudioStreamBasicDescription, because without them AudioQueue will not start play.
As i understand i didn't save some structure that need to cut this empty pieces when playing. Because when i playing it from online URL stream it works without glitches.
i found a bug, when i write a stream to file it write also stream metadata like song name. When i start wrote only audio data all works fine.

Why does Youtube buffer some videos partially, but others fully?

This is a question on Youtube's video buffering.
For example, this video buffers gradually as it plays along:
(1) http://www.youtube.com/watch?v=XGNOc7FYWKA
So if you pause the video, it buffers up to some point and then stops.
But try this video. It buffers the entire length, even if you pause:
(2) http://www.youtube.com/watch?v=fK1eWVrO_fE
I explored this a bit.
For video (1), the browser sends 2 extra parameters while requesting the FLV video:
GET /videoplayback?ipbits=8&algorithm=throttle-factor&cp=U0hRTVJRUV9OUENOMV9KS1VGOlczX1hyNGxsZU5T&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Calgorithm%2Cburst%2Cfactor%2Ccp&id=5c634e73b15858a0&factor=1.25&ip=69.0.0.0&source=youtube&key=yt1&burst=40&fexp=903104%2C910103&keepalive=yes&sver=3&itag=34&signature=855EF17A58816C002AD9B13DE556B4A61A9D5418.2A2EF1CC340227895ED945AC8FC7D23EE7B0B569&expire=1328263596&range=13-1781759&redirect_counter=2 HTTP/1.1
It slides the range as the video plays on.
For video (2), the browser skips those 2 parameters, and the server responds with a plain HTTP "Content-Length: (actual video file length)" response. This is why the video downloads fully.
Now for my question:
Anyone know what causes this difference in buffering? Is it a property of the video, or the server, or something else?
Ideally I would like to use buffering of type (1) to prevent wasted bandwidth, if I don't watch the video fully.
FWIW, I tried tweaking the request in the second case by manually adding the range and keepalive parameters. I got "Error playing the video".

Resources