How to generate the Thumbnail of video URL flv format?

后端 未结 1 613
天命终不由人
天命终不由人 2020-12-20 05:54

How can i get the Thumbnail of URL my video url like below

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

I a

相关标签:
1条回答
  • 2020-12-20 06:54

    Use this below code,

    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 #import <AssetsLibrary/AssetsLibrary.h> header file

    the above code is working for me, hope its helpful for you

    0 讨论(0)
提交回复
热议问题