zoukankan      html  css  js  c++  java
  • iOS 获取本地视频的缩略图

    iOS 获取本地视频的缩略图

    (2012-10-10 20:06:27)
    标签:

    视频

    缩略图

    本地

    杂谈

    分类: ios

    +(UIImage *)getImage:(NSString *)videoURL

    {

        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil];

        AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];

        gen.appliesPreferredTrackTransform = YES;

        CMTime time = CMTimeMakeWithSeconds(0.0, 600);

        NSError *error = nil;

        CMTime actualTime;    

        CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];

        UIImage *thumb = [[UIImage alloc] initWithCGImage:image];

        CGImageRelease(image);

        return thumb;

     

    }

    需要添加AVFoundation和CoreMedia.framework

    另外一种那个方法

     

     

    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
                                           initWithContentURL:videoURL];
    moviePlayer.shouldAutoplay = NO; 
    
    UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time
                         timeOption:MPMovieTimeOptionNearestKeyFrame];
    
    //这个也一样
    

    +(UIImage *)fFirstVideoFrame:(NSString *)path
    {
        MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
                                       initWithContentURL:[NSURL fileURLWithPath:path]];
        UIImage *img = [mp thumbnailImageAtTime:0.0
                                     timeOption:MPMovieTimeOptionNearestKeyFrame];
        [mp stop];
        [mp release];
        return img;
    }
  • 相关阅读:
    bzoj1731 [Usaco2005 dec]Layout 排队布局
    loj10087 Intervals
    差分约束小结
    bzoj1112 [POI2008]砖块Klo
    bzoj3524 [POI2014]Couriers
    poj2752 Seek the Name, Seek the Fame
    1027C Minimum Value Rectangle
    bzoj2212 [POI2011]Tree Rotations
    bzoj3747 [POI2015]Kinoman
    628D Magic Numbers
  • 原文地址:https://www.cnblogs.com/transcendent/p/4835282.html
Copyright © 2011-2022 走看看