gpt4 book ai didi

ios - PHAsset 视频压缩 iOS swift

转载 作者:行者123 更新时间:2023-11-30 12:09:02 65 4
gpt4 key购买 nike

我正在尝试将图像和视频上传到服务器。它工作正常。我面临的问题是从 iPhone 拍摄的图片或录制的视频尺寸太大,上传到服务器需要时间。如何减少视频数据的大小?

if(asset.mediaType == .video)
{
var dataMOV : Data?

manager.requestAVAsset(forVideo: asset, options: option2, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [AnyHashable : Any]?) in
let avURLAsset = asset as? AVURLAsset
do
{
let data = try Data(contentsOf: (avURLAsset?.url)!)
dataMOV = data
print("asset data :%@ ", data)
}
catch
{

}
})
}

最佳答案

从 AssetInfo 中提取 Assets URL 并将其传递给下面的方法

func compressVideo(inputURL: URL, outputURL: URL, handler:@escaping (_ exportSession: AVAssetExportSession?)-> Void) {
let urlAsset = AVURLAsset(url: inputURL, options: nil)
guard let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality) else {
handler(nil)

return
}

exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileTypeQuickTimeMovie
exportSession.shouldOptimizeForNetworkUse = true
exportSession.exportAsynchronously { () -> Void in
handler(exportSession)
}
}

关于ios - PHAsset 视频压缩 iOS swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46292641/

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