ios – 从swift的本地视频创建缩略图

前端之家收集整理的这篇文章主要介绍了ios – 从swift的本地视频创建缩略图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何从本地视频文件快速创建缩略图

例如,如果视频文件路径位于此处:

文件:///Users/Dev/Library/Developer/CoreSimulator/Devices/F33222DF-D8F0-448B-A127-C5B03C64D0DC/​​data/Containers/Data/Application/4BC62DBF-0108-453C-9324-5BC0E356FE24/tmp/trim.059D11E6 -F0EF-43DB-9E97-CA4F1F95D6B6.MOV

谢谢.

解决方法

翻译自:

First frame of a video using AVFoundation

var err: NSError? = nil
    let asset = AVURLAsset(URL: NSURL(fileURLWithPath: "/that/long/path"),options: nil)
    let imgGenerator = AVAssetImageGenerator(asset: asset)
    let cgImage = imgGenerator.copyCGImageAtTime(CMTimeMake(0,1),actualTime: nil,error: &err)
    // !! check the error before proceeding
    let uiImage = UIImage(CGImage: cgImage)
    let imageView = UIImageView(image: uiImage)
    // lay out this image view,or if it already exists,set its image property to uiImage
原文链接:/iOS/335295.html

猜你在找的iOS相关文章