I’ve been able to use AVFoundation’s AVAssetReader class to upload video frames into an OpenGL ES texture. It has a caveat, however, in that it fails when used with an AVURLAsset that points to remote media. This failure isn’t well documented, and I’m wondering if there’s any way around the shortcoming.
I’ve been able to use AVFoundation’s AVAssetReader class to upload video frames into an
Share
There’s some API that was released with iOS 6 that I’ve been able to use to make the process a breeze. It doesn’t use
AVAssetReaderat all, and instead relies on a class calledAVPlayerItemVideoOutput. An instance of this class can be added to anyAVPlayerIteminstance via a new-addOutput:method.Unlike the
AVAssetReader, this class will work fine forAVPlayerItems that are backed by a remoteAVURLAsset, and also has the benefit of allowing for a more sophisticated playback interface that supports non-linear playback via-copyPixelBufferForItemTime:itemTimeForDisplay:(instead of ofAVAssetReader‘s severely limiting-copyNextSampleBuffermethod.SAMPLE CODE
Once you’ve got your buffer, you can upload it to OpenGL however you want. I recommend the horribly documented
CVOpenGLESTextureCacheCreateTextureFromImage()function, because you’ll get hardware acceleration on all the newer devices, which is much faster thanglTexSubImage2D(). See Apple’s GLCameraRipple and RosyWriter demos for examples.