美文网首页
获取视频第一帧

获取视频第一帧

作者: 回传妙手 | 来源:发表于2023-02-07 12:55 被阅读0次
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                AVURLAsset *asset = [[AVURLAsset alloc]initWithURL:url options:nil];
                AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
                generator.appliesPreferredTrackTransform = YES;
                CMTime time = CMTimeMakeWithSeconds(0.0, 600);// 处理视频内容常见刻度,600是24fps、25fps、30fps的公倍数
                NSError *error = nil;
                CMTime actualTime;
                CGImageRef imageRef = [generator copyCGImageAtTime:time actualTime:&actualTime error:&error];
                UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
                // 存入内存、存入本地
                [[PFMediaTool shareMediaTool].frameKeyMap setObject:resultImage forKey:frameKey];
                [self saveImageToCache:resultImage forKey:frameKey];
                CGImageRelease(imageRef);
                dispatch_async(dispatch_get_main_queue(), ^{
                    completeBlock(resultImage);
                });
            });

相关文章

网友评论

      本文标题:获取视频第一帧

      本文链接:https://www.haomeiwen.com/subject/kqaxkdtx.html