Re: Using AV Foundation to record m3u8 stream to disk
Re: Using AV Foundation to record m3u8 stream to disk
- Subject: Re: Using AV Foundation to record m3u8 stream to disk
- From: Kevin Meaney <email@hidden>
- Date: Mon, 15 Dec 2014 22:59:50 +0000
I'm not certain if this is useful to you but Bob McCune on Twitter mentioned a new tech note about new avfoundation apis which specifically mentions reference movies.
https://developer.apple.com/library/mac/technotes/tn2404/_index.html#//apple_ref/doc/uid/DTS40015060
I'd also recommend his book learning avfoundation.
Kevin
Sent from my iPad
> On 15 Dec 2014, at 02:57, Graham Cox <email@hidden> wrote:
>
> Just an update on this, since I've made some useful progress, but I'm a bit stuck again.
>
>
> I am able to download the video streams and write them to a .ts file which plays fine in apps such as VLC (Quicktime Player not so much). So far this is all done with NSURLSession, breaking apart the m3u8 file(s) and loading each media chunk, reassembling them into the correct order and writing them to the file.
>
> What I'd like to do now is to have a live preview of what data is being received (so far I just accumulate it to the file with no preview). AVPlayer can do this all by itself, but I assume that it's going to be duplicating the download, thus doubling the bandwidth I need. What I'd rather do is feed my already downloaded chunks of data to an AVPlayer somehow. This is where the AV Foundation programming guide and the framework itself is a bit daunting - I don't really know which objects I need to be looking at. I'm thinking AVCaptureInput... or is it AVCaptureInputPort, or maybe AVAssetReader. Unfortunately this sort of low level extension of AV Foundation isn't well covered in the programming guide.
>
> Some useful pointers to the rough shape of what I need to do would get my project moving again.
>
> --Graham
>
>
>
>
>
>
>> On 9 Dec 2014, at 10:37 am, Graham Cox <email@hidden> wrote:
>>
>> OK, thanks. I was hoping that I didn't need to delve into the internals of the m3u8 format itself, since AVPlayer/AVPlayerView handles it just fine - I just make a NSURL from the m3u8 url and away it goes.
>>
>> By the way, it isn't just audio, it's video and audio and possibly other things - there are three tracks in the asset for the stream I tested with but I forget what the third is now (first two were video and audio).
>>
>> It seems as if the architecture of AV Foundation allows what I want, but the actual implementation doesn't, *unless I've missed something*. I'm wondering if this gap in the implementation is deliberate for some reason, is there but requires some other combinaiton of parameters from the nes I've tried, on Apple's 'to do' list or is fundamentally not possible.
>>
>>
>> --Graham
>>
>>
>>
>>
>>> On 9 Dec 2014, at 4:50 am, email@hidden wrote:
>>>
>>>
>>>
>>>
>>> Sent from my iPhone
>>>> On 2014/12/09, at 1:38, Jens Alfke <email@hidden> wrote:
>>>>
>>>> m3u8 isn't a stream, it's simply a small playlist file that contains one or more HTTP URLs, which resolve to audio files, usually MP3. In the case of streaming, the HTTP audio resource uses the Shoutcast format, which is basically just an audio stream that looks like an infinitely long MP3 file.
>>>>
>>>> So all you need to do is read the URL from the .m3u8 file (which is pretty trivial; IIRC it's just a text file containing a URL) and use something like NSURLConnection to read data from it and write it to a file with a ".mp3" extension. Since it's a stream you'll never hit EOF so you'll want to stop the connection after a while.
>>>>
>>>> If you need to write the audio into some other kind of movie file you should be able to feed the data received from the URL into AVFoundation. You'll just need to inform it that the data format is MP3.
>>> It is not limited to MP3
>>> Http Live Streaming uses this playlist format.
>>> Literally just a list of URLs really. Where each one is a short clip of media content.
>>> The content on the other end is usually small files as parts of the whole.
>>> The u on the end means UTF8.
>>> The video format could vary.
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden