Getting a Thumbnail of a *.Mov Video iOS

Getting a thumbnail of a *.mov video IOS

Here it is... (Picked up from this link- Getting video snapshot for thumbnail)

- (UIImage *)thumbnailImageFromURL:(NSURL *)videoURL {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL: videoURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime requestedTime = CMTimeMake(1, 60); // To create thumbnail image
CGImageRef imgRef = [generator copyCGImageAtTime:requestedTime actualTime:NULL error:&err];
NSLog(@"err = %@, imageRef = %@", err, imgRef);

UIImage *thumbnailImage = [[UIImage alloc] initWithCGImage:imgRef];
CGImageRelease(imgRef); // MUST release explicitly to avoid memory leak

return thumbnailImage;
}

Getting video snapshot for thumbnail

To fix the thumbnail orientation set appliesPreferredTrackTransform to YES in the AVAssetImageGenerator instance. If you add your own video composition, you'll need to include the right transform to rotate the video as wanted.

generate.appliesPreferredTrackTransform = YES;

Remember to release the obtained image reference with CGImageRelease.

To request multiple thumbnails it's better to do asynchronously with generateCGImagesAsynchronouslyForTimes:completionHandler:.

iOS how to insert an inline photo or video thumbnail in a UITextView?

On iOS 7 or later, you can use NSTextAttachment to insert an inline image to UITextView. See this for an example: https://stackoverflow.com/a/20930656/1262685

For the video thumbnail, you'll need to create the thumbnail yourself. Here's one way to do it: https://stackoverflow.com/a/19530997/1262685

How can I fix these compilation errors?

The compiler is telling you, that you cannot use the List.Add() method that expects a string as input, because you're handing it the return of Split() which returns a string[]. To use a string[] as input, use AddRange().



Related Topics



Leave a reply



Submit