Skip to content

Instantly share code, notes, and snippets.

@autresphere
Created April 30, 2013 14:29
Show Gist options
  • Save autresphere/5489099 to your computer and use it in GitHub Desktop.
Save autresphere/5489099 to your computer and use it in GitHub Desktop.
Retrieves the size of a video from its path.
+ (CGSize)sizeOfVideoAtPath:(NSString *)path
{
NSURL *url;
AVAsset *asset;
NSArray *tracks;
url = [NSURL fileURLWithPath:path];
asset = [[AVURLAsset alloc] initWithURL:url options:nil];
tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if(tracks != nil)
{
AVAssetTrack *track;
if([tracks count] > 0)
{
track = tracks[0];
if(track != nil)
{
return track.naturalSize;
}
}
else
{
NSLog(@"Warning: Unable to retrieve video natural size on %@", path);
}
}
return CGSizeZero;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment