Docs
API Docs

Serialization

Our serialization functionality empowers you to save the current operations that have been applied to the video. It also allows you to recover such settings the next time the editor is opened again. The settings will be stored in a plain JSON file. For details on the JSON structure you can download our schema.

Saving the current settings

When the editor is about to be closed, the according delegate method will be called. In that method, you can retrieve the serialized settings by calling the serializedSettings method on the VideoEditViewController class and save these to a file. Here is some example code to get you started:

func videoEditViewController(_ videoEditViewController: VideoEditViewController, didFinishWithVideoAt url: URL?) {
  if let data = videoEditViewController.serializedSettings {
    do {
      try data.write(to: dataFileURL, options: .atomic)
    } catch {
      print(error)
    }
  }

  dismiss(animated: true, completion: nil)
}

Restoring a settings file

To set the initial editor settings, you can deserialize a Data object containing a previously serialized settings file using the Deserializer class. A settings file contains the serialized PhotoEditModel. After a successful deserialization, the model is returned in a DeserializationResult object and may be used to fully restore the previous editing state. This can be done by using the deserialized model to initialize and present a new VideoEditViewController instance:

let video = Video(url: Bundle.main.url(forResource: "example", withExtension: "mp4")!)
let deserializationResult = Deserializer.deserialize(data: data, imageDimensions: video.size)
if let model = deserializationResult.model {
  let videoEditViewController = VideoEditViewController(videoAsset: video, configuration: Configuration(), menuItems: PhotoEditMenuItem.defaultItems, photoEditModel: model)

  present(videoEditViewController, animated: true, completion: nil)
}

Note that you have to pass the video’s dimensions to the deserializer, because that ensures that all dimensions and positions are matched as expected.