Article

Preparing Movie Capture for Open GOP

Generate independently decodable frames in the HEVC format, or opt out for older devices.

Overview

Beginning in iOS 12, the HEVC video codec supports delivery of open GOP (group of pictures). When open GOP is off, the encoder generates groups of pictures that are independently decodable, with no frame dependencies across sync samples. When enabled, the encoder may use open GOP frame dependency structures to increase compression efficiency or quality. In practice, open GOP HEVC compresses better than closed GOP, allowing for smaller file sizes and better quality for the same file size. In apps built with the iOS 12 SDK, AVCaptureMovieFileOutput uses open GOP by default when compressing using HEVC.

Opt Out of Open GOP for Older Devices

If you don't want to encode using the open GOP strategy, use setOutputSettings(_:for:) to set a dictionary containing AVVideoCodecKey (HEVC) and an AVVideoCompressionPropertiesKey subdictionary. In the subdictionary, set the value of kVTCompressionPropertyKey_AllowOpenGOP to NO. To remove this key:

  1. Query AVCaptureMovieFileOutput for its outputSettings(for:) with a videoConnection.

  2. Create a mutable copy of the returned dictionary.

  3. Remove the kVTCompressionPropertyKey_AllowOpenGOP key from the subdictionary of the copy.

Absence of the key implies that kVTCompressionPropertyKey_AllowOpenGOP is NO. Apps linked against iOS 12 will also see a change to output from recommendedVideoSettingsForAssetWriter(writingTo:) and recommendedVideoSettings(forVideoCodecType:assetWriterOutputFileType:). When the recommended video codec is HEVC, AVCaptureVideoDataOutput will also recommend OpenGOP by including the kVTCompressionPropertyKey_AllowOpenGOP key/value pair set to YES in its AVVideoCompressionPropertiesKey subdictionary.

See Also

Configuring Movies

var movieFragmentInterval: CMTime

The number of seconds of output that are written per fragment.

var metadata: [AVMetadataItem]?

The metadata for the output file.