• 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; }
  • 相关阅读:
    windows下面安装Python和pip终极教程
    windows下面安装Python和pip终极教程
    JSON格式的服务接口
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/lee4519/p/4342250.html
Copyright © 2020-2023  润新知