Skip to content

Creates a thumbnail from a video in Swift 4. In this test case we take a video from the camera roll.

Notifications You must be signed in to change notification settings

davidseek/Thumbnail-From-Video-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

In this test project we create a thumbnail image from a video taken from the camera roll. This project will only work on physical devices.

Important: you need to set the team signing to your iTunes account in order to run the project on your device.

Code Example

The most important code for this project is:

func getThumbnailFrom(path: URL) -> UIImage? {

    do {

        let asset = AVURLAsset(url: path , options: nil)
        let imgGenerator = AVAssetImageGenerator(asset: asset)
        imgGenerator.appliesPreferredTrackTransform = true
        let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(0, 1), actualTime: nil)
        let thumbnail = UIImage(cgImage: cgImage)

        return thumbnail

    } catch let error {

        print("*** Error generating thumbnail: \(error.localizedDescription)")
        return nil

    }

}

Also important is to set the following values in the Info.plist file:

Privacy - Camera Usage Description Privacy - Photo Library Additions Usage Description Privacy - Microphone Usage Description

In this project it is already done. But if you want to use those in your project, you will need to set them.

License

MIT

About

Creates a thumbnail from a video in Swift 4. In this test case we take a video from the camera roll.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages