Programmatic Editing

Images and videos can also be edited programmatically instead of visually. For more information see Session documentation.

For example, setting the primaryFilter of an image to Wilshire:

session.image!.primaryFilter = SessionFilterWilshire()

Applying a Brightness filter to an image:

let brightnessFilter = SessionFilterBrightness()
brightnessFilter.normalizedIntensity = 0.2
session.image!.filters = [brightnessFilter]

Applying a Saturation filter to a whole video:

let saturationFilter = SessionFilterSaturation()
saturationFilter.normalizedIntensity = 0.3
session.video!.filters = [saturationFilter]

Applying a Contrast filter to the first segment of a video:

let segment = session.video!.videoSegments.first!
let contrastFilter = SessionFilterContrast()
contrastFilter.normalizedIntensity = 0.2
segment.filters = [contrastFilter]

Trimming a segment so it starts at one second in, with a duration of two seconds:

let segment = session.video!.videoSegments.first!
segment.trimStartTime = CMTime(seconds: 1, preferredTimescale: segment.duration.timescale)
segment.trimDuration = CMTime(seconds: 2, preferredTimescale: segment.duration.timescale)

Rotating the first segment of a video with preferredTransform:

let segment = session.video!.videoSegments.first!
segment.preferredTransform = .rotated180Degrees(segment.naturalSize)
segment.cropRect = segment.suggestedCropRect()

Increasing the speed of the first segment of a video:

let segment = session.video!.videoSegments.first!
segment.speedMultiplier = 2 // 2x faster

You can present the EditController after making programmatic edits and it will reflect your changes. Additionally, the PreviewController will reflect all programmatic edits in real-time.

After making programmatic edits to a session, you should manually call session.save().