[英]PHAsset video compression iOS swift
I am trying to upload images and videos to server. 我正在尝试将图像和视频上传到服务器。 it working fine.
它工作正常。 the problem I am facing is the picture captured or video recorded from the iphone having too much size and it takes time to upload to server.
我面临的问题是从iphone捕获的图片或录制的视频尺寸太大,需要花费一些时间才能上传到服务器。 how can i reduce the size of video data ?
如何减少视频数据的大小?
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
{
}
})
}
From AssetInfo, pull the asset URL and pass it to below method 从AssetInfo中,提取资产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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.