取视频的第一帧作为初始页面

来源:互联网 发布:人工智能 视频分析 编辑:程序博客网 时间:2024/06/05 11:02
  NSString *url = [Utils applicationCachesDirectory:self.videourl];
        url = [Utils applicationDocumentsDirectory:self.videourl];
        NSURL *videoURL = [NSURL fileURLWithPath:url];
        NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                         forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
        AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:videoURL options:opts];
        //NSLog(@"视频的路径是:%@", videoURL);
        AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
        generator.appliesPreferredTrackTransform = YES;
        generator.maximumSize = CGSizeMake(360.0f, 480.0f);
        NSError *error = nil;
        
        /*** Returns a CGImage for the asset at or near a specified time. */
        /*** - (CGImageRef)copyCGImageAtTime:(CMTime)requestedTime actualTime:(CMTime *)actualTime error:(NSError **)outError */
        CGImageRef cgImg = [generator copyCGImageAtTime: CMTimeMake(1, 1) actualTime:NULL error:&error];
0 0
原创粉丝点击