Created
August 1, 2013 22:02
-
-
Save timrisi/6135761 to your computer and use it in GitHub Desktop.
AVFoundation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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