- Notifications
You must be signed in to change notification settings - Fork7
iOS - Fine tuned video compression in Swift 4
License
NotificationsYou must be signed in to change notification settings
testfairy-blog/VideoCompressionTutorial
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
iOS - Fine tuned video compression in Swift 4. Code materials forthis blog post.
Check out other branches for different versions of Swift.
- iOS 9+
- No dependencies
- Single file, single function
- Compression in background thread
- Cancelable
- Configurable a/v bitrate, video resolution, audio sample rate and many other fine tuning operations
- Proper orientation correction for back/front camera
- Low performance compression duringBackground Execution, even when device is locked. (
Application.beginBackgroundTaskmust be called explicitly)
Copythis file to your project.
// Get source videoletvideoToCompress= //any valid URL pointing device storage// Declare destination path and remove anything exists in itlet destinationPath=URL(fileURLWithPath:NSTemporaryDirectory()).appendingPathComponent("compressed.mp4")try?FileManager.default.removeItem(at: destinationPath)// Compressletcancelable=compressh264VideoInBackground( videoToCompress: videoToCompress, destinationPath: destinationPath, size:nil, // nil preserves original, //size: (width: 1280, height: 720) compressionTransform:.keepSame, compressionConfig:.defaultConfig, completionHandler:{[weak self] pathin // use path}, errorHandler:{ einprint("Error:", e)}, cancelHandler:{print("Canceled.")})// To cancel compression, set cancel flag to true and wait for handler invokecancelable.cancel=true
About
iOS - Fine tuned video compression in Swift 4
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published