Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get thumbnail image from .m3u8 formate video url in Swift?

func getThumbnailFrom(path: URL?, withCompletionHandler completion:@escaping ((UIImage)-> Void)){
        var thumbnail = UIImage(named: "name of Dummy Image")

        if let url = path{
            DispatchQueue.global(qos: .background).async {
                do{
                    let asset = AVURLAsset(url: url , options: nil)
                    let imgGenerator = AVAssetImageGenerator(asset: asset)
                    imgGenerator.appliesPreferredTrackTransform = true
                    let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(value: 500,timescale: 30), actualTime: nil)
                    thumbnail = UIImage(cgImage: cgImage)
                    completion(thumbnail!)
                }catch let error{
                      print(error.localizedDescription)
                }
            }
        }
    completion(thumbnail!)
    }

Used it as 

    getThumbnailFrom(path: URL(string: "https://p-events-delivery.akamaized.net/18oijbasfvuhbfsdvoijhbsdfvljkb6/m3u8/hls_vod_mvp.m3u8")!, withCompletionHandler: { (image) in DispatchQueue.main.async(execute: { self.imagePreview.image = image }) })

also try with https://github.com/acotilla91/ACThumbnailGenerator-Swift but in this only demo link is working

Is there any solution?

Thanks in advance.

like image 884
Zalak Parikh Avatar asked Jun 19 '19 06:06

Zalak Parikh


People also ask

Is it possible to generate a thumbnail from a video URL in Android?

In android, we can use the MediaMetadataRetriever to retrieve a thumbnail image of an online video from its url. MediaMetadataRetriever can be used to retrieve frame and metadata from an input media file.


Video Answer


1 Answers

If you are going to use ACThumbnailGenerator-Swift than add NSAppTransportSecurity in Info.plist

like image 133
Vidhi Patel Avatar answered Oct 17 '22 03:10

Vidhi Patel