Trim
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. Please note that defining either of these parameters with high precision (below 0.1 s) may not give accurate results for exported videos due to the FPS values of the input files and the encoding process itself.
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):
alwayswill 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).ifNeededwill only present- the composition tool, if your initial composition is longer than
maximumDurationor shorter thanminimumDuration, or - the trim tool, if your initial video is longer than
maximumDuration.
- the composition tool, if your initial composition is longer than
silentwill automatically trim the video to themaximumDurationwithout 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:
- If a
minimumDurationhas 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 theTrimToolControllerOptions.videoTooShortConfirmationClosure. - If a
minimumDurationhas 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 theCompositionToolControllerOptions.compositionTooShortConfirmationClosure. If you do not allow your users to add additional videos to the composition whenCompositionToolControllerOptions.videoClipLibraryModeis set tonone, the behavior will be identical as if the trim tool would have been used above.