Convert an existing movie file to a different format.
To convert existing movie files to a format that makes them compatible with other devices, you must generate a new movie file based on the contents of the existing file. You can't change the format of the saved video in place; you must create a second file of the desired format.
This article assumes that you've already saved the movie file in a different format. If your app is saving a movie directly from video capture, it's more efficient to change the default format during capture by following the steps in Capturing Video in Alternative Formats.
Export the New Video into the Desired Format
Convert the movie file by exporting the asset into the desired file type. Pick the type you want for the final video from the list of
AVFile presets that AVFoundation provides. You'll use that type to configure an
AVAsset object, which then manages the export process from your existing type.
For example, to convert a movie file to H.264/MPEG-4 AVC, use an existing preset that encodes to H.264, such as
AVAsset, and set the output file type to
Next, make sure the movie asset can be converted. Certain assets may not be convertible under the preset conditions, so perform a check to ensure compatibility between the two formats.
Once you've determined compatibility, tell
AVAsset to perform the conversion with the configured preset. Creating a large movie file can be a time-consuming operation, so export the movie asynchronously with
export. This method provides a completion block for you to handle the results after the session has finished creating the new movie file.