18
votes

I'm implementing an application that contains video player. For some reasons video files are encrypted with AES, and size of these files can be rather big to avoid loading it to RAM as one piece. I'm looking for some way to play it with AVPlayer.

Tried:

1) Custom NSURLProtocol as suggested here http://aptogo.co.uk/2010/07/protecting-resources/ Didn't work, I suggest that AVPlayer uses it's own and mine does not get called.

2) Use AVAsset to chop video in small chunks and then feed them to AVPlayer - failed because there's no API in AVPlayer for that.

Any workaround would be greatly appreciated :)

2
If you have encrypted files, we should at least know the format etc. Have you looked into creating a proxy that does the decryption? What are your expectations/use cases (seeking etc.)?Maarten Bodewes
I can't understand exactly, what did you mean. You offer to create proxy, but for what? In my mind there is following algorithm: 1. Catch encrypted data, that AVPlayer tries to load by url. 2. Decrypt it. 3. Put decrypted data in AVPlayer. Quite possible that it is wrong, because AVPlayer hasn't any Data Provider. But I don't know other way.Asya
You could create a web proxy that connects to the actual content and aim an URL to a local service that decrypts the data. In this way you can decouple the encryption/decryption and playing the video.Maarten Bodewes
Did you have any luck with this? I'm in the same situation, except with audio files... I've implemented a custom NSURLProtocol class, but it never gets called.Mark Beaton
I was going through 'Real-time Video Processing Using AVPlayerItemVideoOutput', maybe could help developer.apple.com/library/ios/samplecode/AVBasicVideoOutput/…Andrius Steponavičius

2 Answers

4
votes

You have 2 options:

  1. If targeting iOS 7 and newer the check out AVAssetResourceLoaderDelegate. It allows you to do what you would with a custom NSURLProtocol but specifically for AVPlayer.

  2. Emulate an HTTP server with support for the Range header and point the AVURLAsset to localhost.

I implemented #2 before and can provide more info if needed.

3
votes

I just downloaded the Apple sample project https://developer.apple.com/library/ios/samplecode/sc1791/Listings/ReadMe_txt.html and it seems to do exactly what you want.

The delegate catch each AVURLAsset's AVAssetResourceLoader calls and makes up a brand new .m3a8 file with a custom decryption key in it.
Then it feeds the player with all .ts file URLs in the m3a8.

The project is a good overview of what it is possible to do with HLS feeds.