Article

Capturing Video in Alternative Formats

Change the format used for capturing movie files.

Overview

Video captured on iPhone 8, iPhone 8 Plus, and iPhone X, and running iOS 11 or later, uses the HEVC format by default. When you use AVFoundation to capture videos, you can change the default format if you know in advance that you need a different format.

If your app shares the captured video using a system share sheet, the video is automatically converted to a format compatible with the destination device, and no more work is needed.

However, if your app saves or shares captured video internally, for applications outside the system share sheet, you must use a video-capture format compatible with all target devices. This article shows you how to change the capture format dynamically, so that videos captured in your app begin in the desired format.

Change the Default Format Used in Capture

Change the default format at capture time by specifying it in the output settings for capturing movie files. Each capture device has a dictionary of settings that you tweak to control properties of the output movie file. For example, to capture video in H.264/MPEG-4 AVC, set the output settings key AVVideoCodecKey to AVVideoCodecTypeH264:

#import <AVFoundation/AVFoundation.h>

AVCaptureMovieFileOutput* movieFileOutput = // Your AVCaptureMovieFileOutput //;
AVCaptureConnection* connection = [movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
    
if ([movieFileOutput.availableVideoCodecTypes containsObject:AVVideoCodecTypeH264]) {
    // Use the H.264 codec to encode the video.
    [movieFileOutput setOutputSettings:@{AVVideoCodecKey: AVVideoCodecTypeH264} forConnection:connection];
}

For a list of supported capture codecs, see AVVideoCodecType and the Related Documentation section.

Convert Previously Captured Movie Files

In addition to saving or sharing captured video using a different default format, you can also convert existing movie file content. For more information, see Exporting Video to Alternative Formats.

See Also

Movie and Video Capture

AVCaptureMovieFileOutput

A capture output that records video and audio to a QuickTime movie file.

AVCaptureVideoDataOutput

A capture output that records video and provides access to video frames for processing.