How to create thumbnail format FLV for video?

How can I get a thumbnail of the URL of my video, for example below

http://ServerDomain/streams/16476084045/3d4659d8e93bdfbdb3619a4a684c93be.flv 

I am using this code below

  AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:url options:nil]; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset1]; generator.appliesPreferredTrackTransform = YES; //Set the time and size of thumbnail for image NSError *err = NULL; CMTime thumbTime = CMTimeMakeWithSeconds(0,30); CGSize maxSize = CGSizeMake(425,355); generator.maximumSize = maxSize; CGImageRef imgRef = [generator copyCGImageAtTime:thumbTime actualTime:NULL error:&err]; UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imgRef]; cell.videoImage1.image=thumbnail; 

But I am getting lower than error

 Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo={NSUnderlyingError=0x7fe8d3057900 {Error Domain=NSOSStatusErrorDomain Code=-12847 "(null)"}, NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open} 

And I do not use MPMoviePlayer how to get a thumbnail image Please help me. Thank.

+1
ios flv uiimage video-thumbnails
May 20 '16 at 9:45
source share
1 answer

Use this code below,

 AVAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil]; if ([[avAsset tracksWithMediaType:AVMediaTypeVideo] count] > 0) { AVAssetImageGenerator *imageGenerator =[AVAssetImageGenerator assetImageGeneratorWithAsset:avAsset]; Float64 durationSeconds = CMTimeGetSeconds([avAsset duration]); CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600); NSError *error; CMTime actualTime; CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:kCMTimeZero actualTime:&actualTime error:&error]; if (halfWayImage != NULL) { NSString *actualTimeString = (NSString *)CFBridgingRelease(CMTimeCopyDescription(NULL, actualTime)); NSString *requestedTimeString = (NSString *)CFBridgingRelease(CMTimeCopyDescription(NULL, midpoint)); NSLog(@"Got halfWayImage: Asked for %@, got %@", requestedTimeString, actualTimeString); UIImage *img=[UIImage imageWithCGImage:halfWayImage]; self.myimageView.image= img; //img is thumbnail image ; } } 

don't forget the header file #import <AssetsLibrary/AssetsLibrary.h>

The above code works for me, hope it helps you

+2
May 20 '16 at 9:50
source share



All Articles