Skip to content

Instantly share code, notes, and snippets.

@timrisi
Created August 1, 2013 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timrisi/6135761 to your computer and use it in GitHub Desktop.
Save timrisi/6135761 to your computer and use it in GitHub Desktop.
AVFoundation
//Xamarin Code
NSUrl url = new NSUrl (NSBundle.MainBundle.PathForResource ("IMG_1254", "MOV"), false);
AVUrlAsset asset = new AVUrlAsset (url, new AVUrlAssetOptions ());
NSError error;
AVAssetReader assetReader = new AVAssetReader (asset, out error);
AVAssetTrack videoTrack = asset.Tracks [0];
NSString key = CVPixelBuffer.PixelFormatTypeKey;
NSString value = new NSString (CVPixelFormatType.CV32BGRA.ToString ());
NSDictionary videoSettings = NSDictionary.FromObjectAndKey (value, key);
AVAssetReaderTrackOutput trackOutput = new AVAssetReaderTrackOutput (videoTrack, videoSettings);
assetReader.AddOutput (trackOutput);
assetReader.StartReading ();
//Objective-c Code
NSURL *url = [[NSURL alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"IMG_1254" ofType:@"MOV"]];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[[NSBundle mainBundle] URLForResource:@"IMG_1254" withExtension:@"MOV"] options:nil];
NSError *error;
AVAssetReader *assetReader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
AVAssetTrack *videoTrack = [[asset tracks] objectAtIndex:0];
NSString *key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber *value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
AVAssetReaderTrackOutput *trackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:videoTrack outputSettings:videoSettings];
[assetReader addOutput:trackOutput];
[assetReader startReading];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment