VideoEffects is a simple Swift library for playing and exporting videos with effects. The library supports many possible effects. For instance, you can crop a video into a square aspect ratio, or render a video with color adjustments like brightness, hue and saturation.
The ColorControlsFilter
class allows for adjustments to the color properties of the video. All properties are optional.
let colorControlsFilter = ColorControlsFilter(
brightness: Double
saturation: Double
contrast: Double
exposure: Double
hue: Double
)
The EffectConfig
struct defines the effects applied to a video. For example:
let effects = EffectConfig(
filters: [colorControlsFilter],
aspectRatio: CGSize(width: 1, height: 1),
timeRange: CMTimeRange(start: .zero, end: CMTime(seconds: 3, preferredTimescale: 600)),
layer: layer
)
Effects can be:
filters
: A custom filter to apply to the video. For example, the built-inColorControlsFilter
allows custom values for hue, saturation, brightness, contrast and exposure.aspectRatio
: The aspect ratio as aCGSize
.timeRange
: The time range of a video. Use this to trim the video.layer
: A CALayer to render on top of the video. It can be any CALayer (not associated with a UIView).
All properties are optional. Omitted parameters will leave the video unchanged.
EffectPlayerView
is a wrapper around AVPlayer
that uses a custom compositor to render effects.
let asset = AVAsset(url: url)
// setup effects
let effects = EffectConfig(
filters: [colorControlsFilter],
aspectRatio: CGSize(width: 1, height: 1),
timeRange: CMTimeRange(start: .zero, end: CMTime(seconds: 3, preferredTimescale: 600)),
layer: layer
)
let effectView = EffectPlayerView()
effectView.effects = effects
effectView.asset = asset
let asset = AVAsset(url: url)
// setup effects
let effects = effects = EffectConfig(
filters: [colorControlsFilter],
aspectRatio: CGSize(width: 1, height: 1),
timeRange: CMTimeRange(start: .zero, end: CMTime(seconds: 3, preferredTimescale: 600)),
layer: layer
)
// finally, export the video
let exportConfig = try! ExportConfig.defaultConfig()
export(asset: asset, effects: effects, config: exportConfig) { result in
// result has type Result<URL, Error>
}
Open the workspace VideoEffects.xcworkspace
and run the target VideoEffects-example
.