I'm trying to get the first frame of a video using the classes in AVFoundation. But it appears to not be getting an image at all.
My code currently looks like this
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoPath] options:nil];
AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
[videoFrame setImage:image];
The value of video path is /var/mobile/Applications/02F42CBF-D8BD-4155-85F2-8CF1E55B5023/Documents/videos/1334300431637030.mp4
which is definitely a video, since I can play it with MPMoviePlayerViewController
. I'm not sure what I'm doing wrong but any suggestions would be helpful.
Thanks.
I solved it. Apparently using [NSURL fileURLWithPath:videoPath]
instead of [NSURL URLWithString:videoPath]
makes all the difference.