<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVSampleBufferGenerator/makeSampleBuffer(for:addTo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVSampleBufferGenerator(im)createSampleBufferForRequest:addingToBatch:error:"
  },
  "title" : "makeSampleBuffer(for:addTo:)"
}
-->

# makeSampleBuffer(for:addTo:)

Creates a sample buffer and attempts to defer I/O for its data.

```
func makeSampleBuffer(for request: AVSampleBufferRequest, addTo batch: AVSampleBufferGeneratorBatch) throws -> CMSampleBuffer
```

## Parameters

`request`

A sample buffer creation request.

`batch`

A batch object to contain the output sample buffer. You must create this object by calling [`makeBatch()`](/documentation/AVFoundation/AVSampleBufferGenerator/makeBatch()) on the same instance of [`AVSampleBufferGenerator`](/documentation/AVFoundation/AVSampleBufferGenerator) or an error occurs.

## Return Value

A sample buffer.

## Discussion

Call the [`makeDataReady(completionHandler:)`](/documentation/AVFoundation/AVSampleBufferGeneratorBatch/makeDataReady(completionHandler:)) on [`AVSampleBufferGeneratorBatch`](/documentation/AVFoundation/AVSampleBufferGeneratorBatch) once to commence I/O and load sample data for all <doc://com.apple.documentation/documentation/CoreMedia/CMSampleBuffer> objects in a batch. After loading commences, any subsequent calls to [`makeSampleBuffer(for:addTo:)`](/documentation/AVFoundation/AVSampleBufferGenerator/makeSampleBuffer(for:addTo:)) throw an exception.

The generator may defer I/O to fetch sample data depending on the source of the sample data and the generator’s timebase

The request may fail based on generator configuration or file format.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)