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;

}

最新文章

  1. Unity性能优化之 Draw Call原理&lt;转&gt;
  2. JAVA第五次作业
  3. html5+Canvas实现酷炫的小游戏
  4. MVC中的一般权限管理
  5. 【图像处理】【SEED-VPM】6.文件目录结构
  6. 在chrome下的文本框sendkeys,提示element can&#39;t focus--解决方法
  7. Android 开发
  8. sdut 2449走迷宫【最简单的dfs应用】
  9. Linux下mysql备份 恢复
  10. Android开发的第一天
  11. RedHat7配置IdM server
  12. Git安装使用
  13. js中的字符替换
  14. pythonのdjango 信号
  15. fiddler主要图标说明
  16. ie11兼容
  17. 网络编程 —— UPD
  18. 【已解决】ERR_BLOCKED_BY_XSS_AUDITOR:Chrome 在此网页上检测到了异常代码:解决办法
  19. 安卓——Handler延迟跳转
  20. spark的ML和MLLib两个包区别和联系?

热门文章

  1. Windows内核执行体对象管理器的操作过程与分析
  2. Gitlab基本管理&lt;一&gt;
  3. poj1562 Oil Deposits(DFS)
  4. EOJ 3265 七巧板
  5. python并发编程-线程池
  6. 基于springboot实现http响应异常信息国际化
  7. 【3.16高一(第二学期)模拟测试】 T3,T4题解
  8. String 字符串补0
  9. 最小生成树---->prim算法的应用 hdu1863
  10. Cpp下的深拷贝与浅拷贝探究