https://github.com/videoflint/viexportsession
A AVAssetExportSession drop-in replacement with customizable audio&video settings.
https://github.com/videoflint/viexportsession
avfoundation exporter exportsession
Last synced: 11 months ago
JSON representation
A AVAssetExportSession drop-in replacement with customizable audio&video settings.
- Host: GitHub
- URL: https://github.com/videoflint/viexportsession
- Owner: VideoFlint
- License: mit
- Created: 2018-07-28T04:21:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-23T09:23:18.000Z (over 7 years ago)
- Last Synced: 2024-10-28T11:49:40.444Z (over 1 year ago)
- Topics: avfoundation, exporter, exportsession
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 45
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VIExportSession
A `AVAssetExportSession` drop-in replacement with customizable audio&video settings.
You can get more control on video encode and decode, see the detail on `ExportConfiguration.swift`
```Swift
class ExportConfiguration {
var outputURL = URL.temporaryExportURL()
var fileType: AVFileType = .mp4
var shouldOptimizeForNetworkUse = false
var metadata: [AVMetadataItem] = []
}
class VideoConfiguration {
// Video settings see AVVideoSettings.h
var videoInputSetting: [String: Any]?
var videoOutputSetting: [String: Any]?
var videoComposition: AVVideoComposition?
}
class AudioConfiguration {
// Audio settings see AVAudioSettings.h
var audioInputSetting: [String: Any]?
var audioOutputSetting: [String: Any]?
var audioMix: AVAudioMix?
var audioTimePitchAlgorithm: AVAudioTimePitchAlgorithm?
}
```
## Example
```
exportSession.videoConfiguration.videoOutputSetting = {
let frameRate = 30
let bitrate = min(2000000, videoTrack.estimatedDataRate)
let trackDimensions = videoTrack.naturalSize
let compressionSettings: [String: Any] = [
AVVideoAverageNonDroppableFrameRateKey: frameRate,
AVVideoAverageBitRateKey: bitrate,
AVVideoMaxKeyFrameIntervalKey: 30,
AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel
]
var videoSettings: [String : Any] = [
AVVideoWidthKey: trackDimensions.width,
AVVideoHeightKey: trackDimensions.height,
AVVideoCompressionPropertiesKey: compressionSettings
]
if #available(iOS 11.0, *) {
videoSettings[AVVideoCodecKey] = AVVideoCodecType.h264
} else {
videoSettings[AVVideoCodecKey] = AVVideoCodecH264
}
return videoSettings
}()
exportSession.audioConfiguration.audioOutputSetting = {
var stereoChannelLayout = AudioChannelLayout()
memset(&stereoChannelLayout, 0, MemoryLayout.size)
stereoChannelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo
let channelLayoutAsData = Data(bytes: &stereoChannelLayout, count: MemoryLayout.size)
let compressionAudioSettings: [String: Any] = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVEncoderBitRateKey: 128000,
AVSampleRateKey: 44100,
AVChannelLayoutKey: channelLayoutAsData,
AVNumberOfChannelsKey: 2
]
return compressionAudioSettings
}()
```
## Installation
`VIExportSession` only support Swift 4
**Cocoapods**
```
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
# your other pod
# ...
pod 'VIExportSession'
end
```
**Manually**
You can simplely drag `VIExportSession.swift` to you project
## LICENSE
Under MIT