Reputation: 315
I have several videos uploaded on Amazon S3 bucket. I want to display the videos in a list format in an iOS application along with the thumbnail.
Suppose the url is https://testurlatamzons3/mybucket/somefile.mp4 and I want to get the thumbnail from the URL without actually downloading or streaming the file.
I have seen certain examples and I am able to download the UIImage and display it on the UIImageView. The example I found was here But for a 350MB file on amazon s3, it takes around 1.9mb of data transfer just to get the thumbnail. Is there a more optimized or a different approach to getting the thumbnails for the mp4/mov files hosted on Amazon S3
Regards,
Nirav
Upvotes: 0
Views: 1285
Reputation: 986
you could get thumbnails using AVFoundation with any time, any size you want:
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:yourVideoUrl options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;
CMTime thumbTime = CMTimeMakeWithSeconds(5,30);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime,
CGImageRef im,
CMTime actualTime,
AVAssetImageGeneratorResult result,
NSError *error){
NSLog(@"make sure generator is used in this block and it'll work %@", generator);
};
generator.maximumSize = CGSizeMake(320, 180);
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
Upvotes: 3
Reputation:
I guess you have two options:
To have some API which does what you want and returns the URL of the thumbnail image to your application
To download just a small part of the video and grab a frame from it but this depends on the format of your video, maybe this could help for MP4 videos
https://github.com/ohminteractive/OHMTagLib
Upvotes: 0