Last active
October 28, 2015 03:59
-
-
Save tuchangwei/5fa9872b395db1346e26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
视频读取 | |
==== | |
NSFileManager.defaultManager().createFileAtPath(videoPath, contents: nil, attributes: nil) | |
if let fileHander = NSFileHandle(forWritingAtPath: videoPath) { | |
let BufferSize = 1024*1024 | |
let buffer = calloc(BufferSize, sizeof(UInt8)) | |
let bufferPtr8: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer) | |
var offset = Int64(0) | |
var bytesRead = 0 | |
repeat { | |
bytesRead = representation.getBytes(bufferPtr8, fromOffset: offset, length: BufferSize, error: nil) | |
let data = NSData(bytesNoCopy: bufferPtr8, length: bytesRead, freeWhenDone: false) | |
fileHander.writeData(data) | |
offset += bytesRead | |
} while(bytesRead > 0) | |
free(bufferPtr8) | |
===== | |
视频压缩 | |
==== | |
let urlAsset = AVURLAsset(URL: representation.url()) | |
let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality) | |
exportSession?.outputURL = NSURL(fileURLWithPath: videoPath) | |
exportSession?.outputFileType = AVFileTypeQuickTimeMovie | |
exportSession?.exportAsynchronouslyWithCompletionHandler({ () -> Void in | |
if exportSession?.status == .Completed { | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment