2

I am writing a mac app that can download videos from different sources to the local hard disk. Works great so far, but I'd like to allow the user to play those videos while they are being downloaded. Looking through the documentation for QTKit I couldn't find any method that would allow me to feed the movie data piecewise to a QTMovie object.

Is there a way I can achieve that with QTKit, AVFoundation or some other system framework? I'd really like to avoid bringing in ffmpeg or another third party library for that.

Sven
  • 22,475
  • 4
  • 52
  • 71
  • This would depend on the format of the movie file. Some formats are designed to be streamed, others cannot be. – Rob Keniger Apr 25 '12 at 12:35
  • @Rob, I know that some formats cannot be streamed. Most movies I want to download should be in a streamable format. For the ones that are not I'll disable the play-while-downloading functions. I'm not asking for a way to do the impossible (i.e. stream movies in unstreamable formats) – Sven Apr 25 '12 at 13:24

2 Answers2

3

The problem lies with how QuickTime movies work. They're not stream based files, so feeding the information a chunk at a time is usually not useful. Instead, they're atom based files, and the atoms are allowed to come in any order.
Depending on how a QuickTime movie was created, the "moov" atom (which provides vital information and is required for interpreting the media data) can be (and often is) at the end of the file. If it's at the end, then it's impossible to play the movie until it is completely downloaded. If the moov data is at the beginning (for example if someone saved the movie using the "Prepare for Internet" option), then QuickTime will be able to start playing the file immediately.

Only formats like MPG transport streams are designed for streaming or "progressive downloading."

Ken Aspeslagh
  • 11,484
  • 2
  • 36
  • 42
  • For more information about how progressive playback work, you should read [Progressive playback: An atom story](http://fabiensanglard.net/mobile_progressive_playback/index.php). – 0xced Apr 26 '12 at 05:57
  • Thanks, but this doesn't help. Most movie files should be prepared for streaming so that is not an issue. What I need is an API to play those. – Sven Apr 29 '12 at 08:03
2

You should probably use the AV Foundation framework instead of QTKit. The first thing you want to do is read the AV Foundation Programming Guide. Although the guide heavily refers to iOS, AV Foundation features are available on OS X since 10.7.

0xced
  • 25,219
  • 10
  • 103
  • 255
  • Thanks for the hint, didn't know that AVFoundation was available on the Mac too. But this doesn't seem to have the needed functions either. – Sven Apr 24 '12 at 19:01
  • Sven, if you scroll half way down the page linked, there's section link “Playback” which, explains how to control the playback of assets using AVPlayer object, as well as how to display video using an AVPlayerLayer object. Is that not what you need?? Don't know about the ability of those classes to read from a file/asset currently being downloaded. – Only You Apr 25 '12 at 03:49
  • 1
    Oh, playing a movie from the local file system or from a stream URL is not a problem. I need information on how to play a movie while it is downloading. Ideally I need something I pass in `NSData` objects as I receive them from the network. – Sven Apr 25 '12 at 13:28