Can AVFoundation be coerced into playing a local .ts file?
Clearly, AVFoundation (and Quicktime X) can demux and play properly encoded
.ts containers, because
.ts containers underly HTTPS live streaming.
Short of setting up a local web service to serve the
.m3u8 and associated
.ts files, I’d really like to be able to either: convince
URLAssetWithURL to accept a local file
.m3u8 URI as if it were an HTTP URI, or better yet, be able to use
AVQueuePlayer to load and play a sequence of
.ts files without jumping through the live streaming hoops.
The reason I’m wanting to do this is that I need to locally generate movie assets on-the-fly in a somewhat piecemeal fashion – the entire asset won’t be available at once but will be generated as time goes by. Obviously this lends itself to an
AVQueuePlayer but for various reasons my asset fragments are packaged in
.ts containers. All this sounds like it’s perfect for “local” live streaming.
I suspect that
URLAssetWithURL does some qualification of the string passed to it and then sets some properties to signal that it’s looking at a live streaming source which in turn tell
AVQueuePlayer to expect tracks in
.ts form. It probably sees the HTTP and decides that this is live streaming.
So my question is: how would one go about “fooling” AVFoundation into handling a local
.m3u8 file exactly as it does a remote one?
And the bonus question is: Has anyone (and if so how) been able to make an
AVAsset from a
.ts file so that the asset will return the status of the asset’s tracks (prepare for playback)?
2 Solutions Collect From Internet About “Can AVFoundation be coerced into playing a local .ts file?”
This problem was annoying for us too for a long time. We have finally decided to write a tool to convert a list of ts to an mp4 file. It consists in using TSDemux to demux and concatenate videos/audios and then generate a mp4 file with GPAC.
It does really answer your question, but it may be a way to do what you want to do.
This tool is on Github, feel free to try: https://github.com/Keemotion/TS2MP4
You can actually create AVURLAssets directly from the underlying ts files, and play these directly, very similarly to the way you would play a mov or mp4 file.
There is some overhead for each ts file, so your best bet is to simply cat the files into one large ts file (based on your m3u8’s contents), and play that large file.
There are a couple of gotcha’s: AVCompositions constructed using ts file based AVAssets are memory hungry, so avoid AVCompositions apart from small files. You cannot use ts file based AVAssets in a reference movie.
- Dynamically change MGLPointAnnotation image on Mapbox iOS SDK
- How to convert a String (numeric) in a Int array in Swift
- How do I use UIPageViewController to load separate XIBs?
- UITableView: the proper way to display a separator for the last cell
- Core Data Encryption
- Custom ttf font makes Spritekit's transition slow in SWIFT
- Including/excluding entire groups from targets
- iterate over object class attributes in Swift
- How to create percentage of total width using autolayout?
- ends with (suffix) and contains string search using MATCH in SQLite FTS
- iOS 6 – UIActivityViewController items
- Batch replace copyright comment in XCode
- Healthkit background delivery when app is not running
- Animate `backgroundColor` of a `UIView` that implements `drawRect`
- Xcode9: Fix All In Scope is always disabled