Creating thumbnail from local video in swift

前端 未结 7 2239
挽巷
挽巷 2020-12-04 06:59

How to create thumbnail in swift from a local video file ?

For example if the video file path is located here :

file:///Users/Dev/Library/Developer/Co

7条回答
  •  庸人自扰
    2020-12-04 07:34

    Translated with some edits from:

    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
    

提交回复
热议问题