搜索
您的当前位置:首页iOS获取视频的略缩图

iOS获取视频的略缩图

来源:飒榕旅游知识分享网

/**

  • 获取视频的缩略图方法
  • @param filePath 视频的本地路径
  • @return 视频截图
    */
  • (UIImage *)getScreenShotImageFromVideoPath:(NSString *)filePath{

    UIImage *shotImage;
    //视频路径URL
    NSURL *fileURL = [NSURL fileURLWithPath:filePath];

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:fileURL 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];

    shotImage = [[UIImage alloc] initWithCGImage:image];

    CGImageRelease(image);

    return shotImage;

}

因篇幅问题不能全部显示,请点此查看更多更全内容

Top