How to get video url from PHAsset in iOS swift ?

func getVideoUrlFromPHAsset(_ asset:PHAsset)->AVURLAsset{

        let semaphore = DispatchSemaphore(value: 0)

        var videoObj:AVURLAsset? = nil

        let options = PHVideoRequestOptions()

        // options.isSynchronous = true

        options.deliveryMode = .highQualityFormat

        

        PHImageManager().requestAVAsset(forVideo:asset, options: options, resultHandler: { (avurlAsset, audioMix, dict) in

            videoObj = avurlAsset as! AVURLAsset

            semaphore.signal()

            

        })

        _ = semaphore.wait(timeout: DispatchTime.distantFuture)

        return videoObj!

        

    }
Back to Top