zoukankan      html  css  js  c++  java
  • 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; 
    }

    转:http://blog.sina.com.cn/s/blog_6d01cce301019xym.html


    
    
  • 相关阅读:
    Json -- 语法和示例,javascript 解析Json
    平衡二叉树的实现原理
    递归:汉诺塔
    递归:这帮坑爹的小兔崽子
    函数:递归是神马
    函数:lambda表达式
    函数:内嵌函数和闭包
    函数:我的地盘听我的
    函数:灵活即强大
    函数:Python的乐高积木
  • 原文地址:https://www.cnblogs.com/ygm900/p/3810648.html
Copyright © 2011-2022 走看看