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)?
- How to crop video into square iOS with AVAssetWriter
- Swift 3 : How to export video with text using AVVideoComposition
- Unable to use AVCapturePhotoOutput to capture photo swift + xcode
- kCVPixelFormatType_420YpCbCr8BiPlanarFullRange frame to UIImage conversion
- Timeline Progress bar for AVPlayer
- Play multiple Audio Files with AVPlayer
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.
- UILabel stops animations
- Best SQLite practices on the iPhone
- “Gift App” from inside the app
- Recommendations for .NET Web Service Format/Protocol for Android, iPhone, etc. integration
- Rotate UIImageView Depending on iPhone Orientation
- iOS re-check location on load from background
- “Missing ” warning in an ARC project
- RxSwift + UITableViewCell how to get cell object in heightForRowAt
- Add Custom Fonts In Xcode 4.1
- UIBarButtonItem Custom view in UINavigationBar
- How to use UIPageControl with iCarousel?
- Protocol can only be used as a generic constraint because it has Self or associatedType requirements
- NSData contentsOfUrl returns nil
- Xcode 4 – “Valid signing identity not found” error on provisioning profiles on a new Macintosh install
- Pick a random element from an array