zoukankan      html  css  js  c++  java
  • IOS从视频中获取截图

    从视频中获取截图:

    NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”];

    mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]];

    MPMoviePlayerController *mp=[mpviemController moviePlayer];

    UIImage *thumbImage=[mp thumbnailImageAtTime:second timeOption:MPMovieTimeOptionNearestKeyFrame];

    NSData *imagedata =UIImagePNGRepresentation(thumbImage);

    [imagedata writeToFile:@"iosxcode4.png" atomically:YES];

     

    第二种方式 直接为UIImage写一个分类:

    +(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;
    }

     

  • 相关阅读:
    学习C#泛型
    css半透明渐变过渡效果
    CSS Grid布局
    CSS writing-mode属性
    单点登录原理与简单实现
    linux磁盘挂载
    Fiddler抓包工具学习
    javascript事件机制之冒泡、捕获、传播、委托
    HTML行内元素、块状元素、行内块状元素的区别
    console.log详细介绍
  • 原文地址:https://www.cnblogs.com/syios/p/4807849.html
Copyright © 2011-2022 走看看