zoukankan      html  css  js  c++  java
  • IOS批量截取视频截图 UIImage mp4 IOS Video


    IOS批量截取视频截图

        //生成截图

        NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Documents"];

        NSLog(@"path %@", path);

        for (int i = 0; i<[mItems count]; i++) {

            NSMutableDictionary *info = (NSMutableDictionary *)mItems[i]; //视频信息

            NSString *mediaPath;

            mediaPath = [[NSBundle mainBundle] pathForResource:[info objectForKey:@"mediaName"]

                                                        ofType:[info objectForKey:@"type"]];

            UIImage *image = [self getImage:mediaPath];

            [UIImageJPEGRepresentation(image, 1) writeToFile:[path stringByAppendingPathComponent:[NSString stringWithFormat:@"file%d.jpg", i]] atomically:YES];

        }


    // 获取指定位置的视频的截屏    

    -(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(20.5, 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;

    }


  • 相关阅读:
    DVB数字电视常见信号指标解释
    傅里叶变换与不确定性
    Sigrity PowerDC是如何计算IR Drop Margin?
    带你了解强大的Cadence家族,你可能只用到了它1/10的工具
    在线原理图绘制网站推荐
    FinFET简介
    SPICE简史
    时域反射计(TDR)原理与应用
    PCB仿真软件与电磁场求解器的算法
    Jersey 2 + Maven + Tomcat + IntelliJ IDEA 搭建RESTful服务
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5371491.html
Copyright © 2011-2022 走看看