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];
            });
    //
        }];
        

  • 相关阅读:
    C#编程概念系列内容索引
    Latin1_General_BIN
    C#编程概念系列(一):面向对象编程
    System.Web.HttpException: 为 ChartImg.axd 执行子请求时出错
    Excel导入数据到数据库
    C#编程概念系列(二):应用程序域
    ASP.NET 基础结构
    [博]留作证明是原创样式
    [整]网址搜集
    仅为调博客样式
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5471181.html
Copyright © 2011-2022 走看看