gpt4 book ai didi

ios - 无法在iOS Swift中从Firebase视频URL生成视频缩略图?

转载 作者:行者123 更新时间:2023-12-01 19:42:16 25 4
gpt4 key购买 nike

我正在使用以下方法从远程服务器URL生成视频缩略图。如果我的网址不是Firebase网址,例如。

https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4

然后我就可以生成缩略图,但是如果我的网址是firebase网址,如下所示

https://firebasestorage.googleapis.com/v0/b/shaberi-a249e.appspot.com/o/message-videos%2F8EDAC3FC-D754-4165-990A-97F6ECE120A6.mp4?alt=media&token=b3271370-a408-467d-abbc-7df2beef45c7

这样就不会生成视频缩略图。

获取视频缩略图的方法

 func createThumbnailOfVideoFromRemoteUrl(url: String) -> UIImage? {

let asset = AVAsset(url: URL(string: url)!)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
//Can set this to improve performance if target size is known before hand
//assetImgGenerate.maximumSize = CGSize(width,height)
let time = CMTimeMakeWithSeconds(1.0, 100)
do {
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let thumbnail = UIImage(cgImage: img)
return thumbnail
} catch {
print(error.localizedDescription)
return nil
}
}

请让我知道是什么问题?

最佳答案

请尝试以下代码,它对我有用。

func createThumbnailOfVideoFromRemoteUrl(url: String) {

if let asset = AVAsset(url: URL(string: url)!) as? AVAsset {
//let durationSeconds = CMTimeGetSeconds(asset.duration)
let generator = AVAssetImageGenerator(asset: asset)

generator.appliesPreferredTrackTransform = true

let time = CMTimeMakeWithSeconds(3.0, preferredTimescale: 600)
//var thumbnailImage: CGImage

generator.generateCGImagesAsynchronously(forTimes: [NSValue(time: time)]) { (time, thumbnail, cmtime, result, error) in
if (thumbnail != nil) {
DispatchQueue.main.async {
self.profileImgView.image = UIImage(cgImage: thumbnail!)
}
}
}
}
}


self.createThumbnailOfVideoFromRemoteUrl(url: "https://firebasestorage.googleapis.com/v0/b/shaberi-a249e.appspot.com/o/message-videos%2F8EDAC3FC-D754-4165-990A-97F6ECE120A6.mp4?alt=media&token=b3271370-a408-467d-abbc-7df2beef45c7")

enter image description here

关于ios - 无法在iOS Swift中从Firebase视频URL生成视频缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53626268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com