From Camera Roll
VideoEditor SDK supports importing videos from the camera roll.
Instantiate image picker#
To that end, we first instantiate a UIImagePickerController
. We are opting for this class over PHPickerViewController
, because the latter does not reliably work for some .mp4
files encoded with non-ffmpeg codecs.
We have reported this issue to Apple.
We further set the current class as the controller's delegate to handle cancellation. Since we only want videos from the camera roll, we set sourceType
and mediaType
correspondingly.
Prevent re-encoding#
We want to prevent reencoding the video when UIImagePickerController
passes it to the delegate methods, so we set the videoExportPreset
property to passthrough
Initialize the editor#
The imagePickerController
delegate is invoked when the user picked a video and the video's mediaURL
is passed to it via the info dictionary.
We can now dismiss the image picker and create a Video
from the videoURL
which is in turn passed as videoAsset
to the VideoEditViewController
to instantiate the video editor.
Again, setting the current class as the delegate of the VideoEditViewController
allows us to implement export, cancellation and error handling there.