---
title: "CMSampleBufferCopySampleBufferForRange(allocator:sampleBuffer:sampleRange:sampleBufferOut:)"
framework: coremedia
role: symbol
role_heading: Function
path: "coremedia/cmsamplebuffercopysamplebufferforrange(allocator:samplebuffer:samplerange:samplebufferout:)"
---

# CMSampleBufferCopySampleBufferForRange(allocator:sampleBuffer:sampleRange:sampleBufferOut:)

Creates a sample buffer that contains a range of samples from an existing sample buffer.

## Declaration

```swift
func CMSampleBufferCopySampleBufferForRange(allocator: CFAllocator?, sampleBuffer sbuf: CMSampleBuffer, sampleRange: CFRange, sampleBufferOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus
```

## Parameters

- `allocator`: The allocator to use for allocating the CMSampleBuffer object. Pass kCFAllocatorDefault to use the default allocator.
- `sbuf`: The sample buffer containing the original samples.
- `sampleRange`: The range of samples to copy from sbuf, where sample 0 is the first sample in the sbuf.``
- `sampleBufferOut`: On output, points to the newly created CMSampleBuffer.

## Return Value

Return Value A result code. See Sample Buffer Error Codes.

## Discussion

Discussion note: Samples containing non-interleaved audio aren’t supported.

## See Also

### Copying Sample Buffers

- [CMSampleBufferCreateCopy(allocator:sampleBuffer:sampleBufferOut:)](coremedia/cmsamplebuffercreatecopy(allocator:samplebuffer:samplebufferout:).md)
- [CMSampleBufferCreateCopyWithNewTiming(allocator:sampleBuffer:sampleTimingEntryCount:sampleTimingArray:sampleBufferOut:)](coremedia/cmsamplebuffercreatecopywithnewtiming(allocator:samplebuffer:sampletimingentrycount:sampletimingarray:samplebufferout:).md)
