Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 AVURLAsset and/or 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 AVPlayer/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)?

TIA!

like image 519
Tawpie Avatar asked Apr 12 '11 22:04

Tawpie


People also ask

How do I play a TS stream video file?

If you have a TS file on your computer, you can open it with a number of media players. VLC should be your first choice since it's completely free and can open these files on Mac, Windows, and Linux. MPEG Streamclip is another option, and the Movies & TV Windows app might work too.

How do I open TS files with VLC?

For example, to open a TS file with VLC media player: Select Media/File → Open File…. Navigate to the folder containing the TS file. Select the TS file and either click Open or double-click the file to open it.


1 Answers

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

like image 70
smad Avatar answered Oct 01 '22 14:10

smad