zoukankan      html  css  js  c++  java
  • 视频截图代码

    //  创建视频资源对象
        AVAsset *asset = [AVAsset assetWithURL:self.mpc.contentURL];
        
    //  视频图片生成器对象
        AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
        
        
    //  截图
    //  value 第几帧
    //  timescale 每秒播放多少帧
    //    CMTime time = CMTimeMake(<#int64_t value#>, int32_t timescale)
    //  currentPlaybackTime 当前视频播放时间,单位是s
        
    //    asset.duration  视频的持续时间
       
        CMTime time =  CMTimeMakeWithSeconds(self.mpc.currentPlaybackTime,asset.duration.timescale);
        
        NSValue *timeValue = [NSValue valueWithCMTime:time];
        
        [generator generateCGImagesAsynchronouslyForTimes:@[timeValue] completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {
            
    //      当不是在主线程中更新UIImageView 图片的时候,会有一个时间延迟
    //        NSLog(@"%@",[NSThread currentThread]);
            NSLog(@"截取图片成功了");
    //      异步任务: 不阻塞当前线程的任务
            
    //        dispatch_sync(dispatch_get_main_queue(), ^{
    //            
    //            self.imageView.image = [UIImage imageWithCGImage:image];
    //        });
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                  self.imageView.image = [UIImage imageWithCGImage:image];
            });
    //
        }];
        

  • 相关阅读:
    pythone 请求响应字典
    python strip()
    python,datetime
    How Flask Routing Works
    python __file__ 与argv[0]
    Python的zip函数
    Python中的__new__()方法与实例化
    python,dict的setdefault方法
    python yield
    python with用法
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5471181.html
Copyright © 2011-2022 走看看