Skip to content

Instantly share code, notes, and snippets.

@zapsleep
Created December 10, 2012 08:31
Show Gist options
  • Save zapsleep/4249346 to your computer and use it in GitHub Desktop.
Save zapsleep/4249346 to your computer and use it in GitHub Desktop.
- (CVImageBufferRef)getImageBufferFromURL:(NSURL *)url {
AVAsset *asset = [AVAsset assetWithURL:url];
AVAssetTrack *track = [[asset
tracksWithMediaType:AVMediaTypeVideo]
objectAtIndex:0];
AVAssetReaderTrackOutput
*readerTrack = [AVAssetReaderTrackOutput
assetReaderTrackOutputWithTrack:track
outputSettings:nil];
AVAssetReader *reader = [AVAssetReader assetReaderWithAsset:asset
error:nil];
[reader addOutput:readerTrack];
CMSampleBuffer sample = [readerTrack copyNextSampleBuffer];
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sample);
return imageBuffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment