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

    相册中视频  获取视频地址和截图

    - (void)imagePickerController:(UIImagePickerController *)picker   didFinishPickingMediaWithInfo:(NSDictionary *)info 

    {   

        [picker dismissModalViewControllerAnimated:YES];

        

        NSString *mediaType = [infoobjectForKey:UIImagePickerControllerMediaType];

        if([mediaType isEqualToString:@"public.movie"])

        {

            NSURL *videoURL = [infoobjectForKey:UIImagePickerControllerMediaURL];

            NSLog(@"found a video");

            //获取视频的thumbnail     

            MPMoviePlayerController *player = [[[MPMoviePlayerControlleralloc]initWithContentURL:videoURL] autorelease];

            UIImage  *thumbnail = [playerthumbnailImageAtTime:1.0timeOption:MPMovieTimeOptionNearestKeyFrame];

    player = nil;

            }

    ########################

    +(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:MPMovieTimeOptionNearest[object Object]KeyFrame];  return img; }
  • 相关阅读:
    web版ssh的使用
    Django高级篇三。restful的解析器,认证组件,权限组件
    Django中的缓存(内存,文件,redis)
    Python使用redis
    跨域请求
    python发送邮箱
    登录服务器失败 IP 统计和处理方法
    centos中单进程监控
    编译搭建lnmp+zabbix
    Django+Uwsgi+Nginx项目部署文档
  • 原文地址:https://www.cnblogs.com/lee4519/p/4342250.html
Copyright © 2011-2022 走看看