Skip to main content
VESDK/iOS/Features

Trim

The trim tool of the VideoEditor SDK for iOS allows your users to trim the length of the video.

The trim tool allows your users to trim the length of the video, giving them the option to modify both, the start time of the video as well as the end time.

The tool is implemented in the TrimToolController class and can be configured by modifying the TrimToolControllerOptions as described in the configuration section.

How to enforce a minimum or maximum video length#

To be able to use this feature your subscription must include the trim feature.

As a first step you need to set either minimumDuration, maximumDuration, or both for the TrimToolControllerOptions. Setting these values when the composition tool is enabled limits the length of the overall composition. Setting these values when the trim tool is enabled limits the length of the video clip. For both variables, any value that is ≤ 0.5 seconds will be ignored. If minimumDuration is larger than maximumDuration the maximumDuration will be set to the minimumDuration.

Composition or trim tool#

The composition tool will only be used if it is included in your subscription and if it is included in the menu items or if both the composition and trim tool are not included as menu items. Otherwise, the trim tool is used if it is included in your subscription.

Force trim modes#

Additionally, the forceTrimMode for the VideoEditViewControllerOptions allows configuring the startup behavior of the editor. Possible values are always, ifNeeded, and silent (the default):

  • always will always automatically present the composition tool or the trim tool after opening the editor and force your users to change the length of the video(s).
  • ifNeeded will only present
    • the composition tool, if your initial composition is longer than maximumDuration or shorter than minimumDuration, or
    • the trim tool, if your initial video is longer than maximumDuration.
  • silent will automatically trim the video to the maximumDuration without opening any tool.

Behavior and user alerts for exceptions#

If enabled, the trim length will initially be set to the maximumDuration. If this value is not set, or the video length is shorter than the maximumDuration, it will be set to the full length of the video. The user interface will not allow a trim length that is shorter than minimumDuration or longer than maximumDuration, so users will never be able to generate a video that lies outside these defined limits. However, there are two cases where this behavior can only be achieved with an alert:

  1. If a minimumDuration has been set for the trim tool and the length of the input video is shorter than that, we will present an alert as soon as the editor is opened stating that the video is too short. After confirming that alert, VideoEditViewControllerDelegate.videoEditViewControllerDidFailToGenerateVideo(_:) will be called which should dismiss the editor. The wording of that alert can be changed using the localization system or the behavior can be completely customized with the TrimToolControllerOptions.videoTooShortConfirmationClosure.
  1. If a minimumDuration has been set for the composition tool and the length of the video composition does not yet overstep that length, tapping on the export button will present an alert that notifies the user that they will have to add additional videos to the composition to export the video. After confirming the alert, the composition tool will automatically open. The wording of that alert can be changed using the localization system or the behavior can be completely customized with the CompositionToolControllerOptions.compositionTooShortConfirmationClosure. If you do not allow your users to add additional videos to the composition when CompositionToolControllerOptions.videoClipLibraryMode is set to none, the behavior will be identical as if the trim tool would have been used above.