UI-less framework for editing videos

Date: November 4, 2020
Services: Swift, Combine, AVFoundation


The VideoEditor Swift package is the result of a shallow dive into the AVFoundation framework. Born in 2010 and updated for the last time in 2013, the AVFoundation framework is not the easiest to navigate. It is with the help of Bob McCune’s book Learning AV Foundation that I build this tool.


VideoEditor currently only offers a couple of basic features which are found I most video editors:

  • Trimming
  • Cropping (using predefined presets)
  • Updating speed rate
  • Muting
  • Exporting to AVPlayerItem or to URL

On the roadmap are the following features

  • Voice Over
  • Adjust Brightness/Contrast
  • Cropping (custom size)
  • Pip
  • Side by side videos


// Create your video edit
var edit = VideoEdit()
edit.isMuted = true
edit.speedRate = 0.5
edit.croppingPreset = .landscape
edit.trimPositions = (
    CMTime(value: 2, timescale: 1),
    CMTime(value: 6, timescale: 1)

// Edit an asset and feed to an AVPlayer
let editor = VideoEditor()
editor.apply(edit: videoEdit, to: asset)
    .map { result -> AVPlayerItem? in
        let item = AVPlayerItem(asset: result.asset)
        item.videoComposition = result.videoComposition
        return item
    .replaceError(with: nil)
    .sink { [weak self] item in
        self?.player.replaceCurrentItem(with: item)

// Export an edited video to a URL
editor.apply(edit: videoEdit, to: asset)
  .flatMap { result in
      result.export(to: outputUrl)
  .sink { result in
      print("Failed to save edited video at \(outputUrl.path). Error: \(result)")
  } receiveValue: { _ in
      print("Successfully saved edited video at \(outputUrl.path)")

Leave a Reply

Your email address will not be published.