程序员必知:导出相册视频

简介: 程序员必知:导出相册视频

慢动作视频, 特殊处理

1, exportSession

let option = PHVideoRequestOptions()

option.isNetworkAccessAllowed = true

option.deliveryMode = .highQualityFormat

PHCachingImageManager.default().requestExportSession(forVideo: asset, options: option, exportPreset: AVAssetExportPresetHighestQuality) { (exportSession, info) in

guard let exportSession = exportSession else {

single(.error(KimPhotoHelperError.sourceNotFound))

return

}

exportSession.outputURL = videoPath

exportSession.outputFileType = .mp4

exportSession.exportAsynchronously {

switch exportSession.status {

case .completed:

single(.success((videoPath.relativePath, size)))

case .failed:

print(exportSession.error)

single(.error(KimPhotoHelperError.sourceNotFound))

default:

break

}

}

}//代码效果参考:http://www.ezhiqi.com/zx/art_6832.html

2, PHAssetResourceManager

let resourceManager = PHAssetResourceManager.default()

let option = PHAssetResourceRequestOptions()

option.isNetworkAccessAllowed = true

resourceManager.writeData(for: assetRescource, toFile: videoPath, options: option) { (error) in

guard let error = error else {

//single(.error(e))

exportSession(asset)

return

}

single(.success((videoPath.relativePath, size)))

}

3, 先 requestDatqa -> 再 writeData

let resourceManager = PHAssetResourceManager.default()

let option = PHAssetResourceRequestOptions()

option.isNetworkAccessAllowed = true

var videoData = Data()

resourceManager.requestData(for: assetRescource, options: option, dataReceivedHandler: { (data) in

videoData.append(data)

}) { (error) in

if let error = error {

print(error)

exportSession(asset)

// single(.error(KimPhotoHelperError.sourceNotFound))

} else {

do {

try videoData.write(to: videoPath)

} catch {

}

single(.success((videoPath.relativePath, size)))

}

}

4, 导出慢动作视频 AVCompostion 类型

func ConvertAvcompositionToAvasset(avComp: AVComposition, completion:@escaping (_ avasset: AVAsset) -> Void){

let exporter = AVAssetExportSession(asset: avComp, presetName: AVAssetExportPresetHighestQuality)

let randNum:Int = Int(arc4random())

//Generating Export Path

let exportPath: NSString = NSTemporaryDirectory().appendingFormat("(randNum)"+"video.mov") as NSString

let exportUrl: NSURL = NSURL.fileURL(withPath: exportPath as String) as NSURL

//SettingUp Export Path as URL

exporter?.outputURL = exportUrl as URL

exporter?.outputFileType = AVFileTypeQuickTimeMovie

exporter?.shouldOptimizeForNetworkUse = true

exporter?.exportAsynchronously(completionHandler: {() -> Void in

DispatchQueue.main.async(execute: {() -> Void in

if exporter?.status == .completed {

let URL: URL? = exporter?.outputURL

let Avasset:AVAsset = AVAsset(url: URL!)

completion(Avasset)

}

else if exporter?.status == .failed{

print("Failed")

}

})

}) }

相关文章
|
存储 PHP 数据安全/隐私保护
Ueditor结合七牛云存储上传图片、附件和图片在线管理的实现和最新更新
最新下载地址: https://github.com/widuu/qiniu_ueditor_1.4.3 Ueditor七牛云存储版本 注意事项 老版本请查看 : https://github.com/widuu/qiniu_ueditor_1.
3056 0
|
8月前
|
JavaScript 前端开发
前端js上传照片实现可预览功能
前端js上传照片实现可预览功能
36 0
uniapp保存图片到相册demo效果(整理)
uniapp保存图片到相册demo效果(整理)
|
11月前
|
小程序
微信小程序如何实现多图上传及预览删除
微信小程序如何实现多图上传及预览删除
|
12月前
|
Web App开发 JSON 前端开发
猿大师办公助手可实现微软Office Word文档在线安全预览,并且禁止编辑、拷贝、截屏、录屏、保存、导出、打印等!
现在,随着数字化进程渗透到到各行各业,数据安全已经成为了数字化革命中的重要组成部分,而在线Office成在OA、ERP、文档系统中得到了广泛的应用,为我国的信息化事业也做出了巨大贡献。随着操作系统、浏览器及Office软件的不断升级和更新换代,加上国家对信息化、数字化系统要求的不断提升,一些厂家的WebOffice控件产品不断被淘汰出局,而现存的几个产品也存在以下几个问题
353 0
|
iOS开发 开发者 索引
批量上传iOS应用程序截图的实用技巧
提交iOS应用程序截图到iTunes Connect是一项非常繁琐的任务,因为你必须上传多达数十张屏幕截图,这是一个重复而枯燥的过程。但是,我们有一个好消息要告诉开发者们,现在有一个工具可以帮助你批量上传,方便快捷。
|
消息中间件 JavaScript 小程序
ngBoot 我随手封装了一个万能的导出excel工具,传什么都能导出 下
ngBoot 我随手封装了一个万能的导出excel工具,传什么都能导出 下
|
JavaScript 小程序 Java
ngBoot 我随手封装了一个万能的导出excel工具,传什么都能导出 上
ngBoot 我随手封装了一个万能的导出excel工具,传什么都能导出 上
|
JavaScript 小程序 前端开发
微信小程序生成海报图片导出相册
小程序内通过静态模板和样式绘制 canvas ,导出图片,可用于生成分享图等场景
559 1
微信小程序生成海报图片导出相册
|
程序员
程序员PS技能(四):程序员创建PSD文件、展示简单PSD设计流程,上传PSD至蓝湖,并下载Demo切图
程序员PS技能(四):程序员创建PSD文件、展示简单PSD设计流程,上传PSD至蓝湖,并下载Demo切图
程序员PS技能(四):程序员创建PSD文件、展示简单PSD设计流程,上传PSD至蓝湖,并下载Demo切图