Contents

CMSampleBuffer

An object that contains zero or more media samples of a uniform media type.

Overview

Sample buffers are Core Foundation objects that the system uses to move media sample data through the media pipeline. An instance of CMSampleBuffer contains zero or more compressed (or uncompressed) samples of a particular media type and contains one of the following:

  • A CMBlockBuffer of one or more media samples

  • A CVImageBuffer, a reference to the format description for the stream of CMSampleBuffers, size and timing information for each of the contained media samples, and both buffer-level and sample-level attachments

A sample buffer can contain both sample-level and buffer-level attachments. Each individual sample in a buffer may provide attachments that include information such as timestamps and video frame dependencies. You read and write sample-level attachments using the CMSampleBufferGetSampleAttachmentsArray(_:createIfNecessary:) function. Buffer-level attachments provide information about the buffer as a whole, such as playback speed and actions to perform upon consuming the buffer. You can read and write buffer-level attachments using the APIs described in CMAttachment and the keys listed under Sample Attachment Keys.

It’s possible for a sample buffer to describe samples it doesn’t yet contain. For example, some media services may have access to sample size, timing, and format information before they read the data. Such services may create sample buffers with that information and insert them into queues early, and attach (or fill) the buffer of media data later, when it becomes ready. Sample buffers have the concept of data-readiness, which means you can test, set, and force them to become ready “now.” It’s also possible for a sample buffer to contain nothing but a special buffer-level attachment that describes a media stream event (for example, “discontinuity: drain and reset decoder before processing the next CMSampleBuffer”).

Topics

Creating Sample Buffers

Copying Sample Buffers

Determining Readiness

Invalidating Sample Buffers

Inspecting Size Information

Inspecting Duration and Timing

Accessing the Format Description

Modifying Sample Buffers

Managing Attachments

Processing Samples

Accessing the Type Identifier

Data Types

Notifications

Errors

Functions

See Also

Sample Processing