---
title: "createMetadataSampleBuffer(from:forDuration:)"
framework: AVFoundation
role: symbol
role_heading: Type Method
platforms: [iOS 26.0+, iPadOS 26.0+, Mac Catalyst 26.0+, macOS 26.0+, tvOS 26.0+]
path: "avfoundation/avcapturetimecode/createmetadatasamplebuffer(from:forduration:)"
---

# createMetadataSampleBuffer(from:forDuration:)

Creates a sample buffer containing Timecode Media Description metadata for a specified duration.

## Declaration

```swift
static func createMetadataSampleBuffer(from timecode: AVCaptureTimecode, forDuration duration: CMTime) -> Unmanaged<CMSampleBuffer>?
```

## Parameters

- `timecode`: The doc://com.apple.avfoundation/documentation/AVFoundation/AVCaptureTimecode instance providing the timecode details for the metadata sample.
- `duration`: The duration that the metadata sample buffer should represent.

## Return Value

Return Value A CMSampleBufferRef with encoded Timecode Media Description metadata for the given duration, or nil if sample buffer creation fails.

## Discussion

Discussion Use this function for scenarios where timecode metadata needs to span a custom interval (not just a single frame), such as non-frame-accurate workflows or for describing a segment of media with a consistent timecode.

## See Also

### Timecode generation

- [AVCaptureTimecodeGenerator](avfoundation/avcapturetimecodegenerator.md)
- [AVCaptureTimecodeGeneratorDelegate](avfoundation/avcapturetimecodegeneratordelegate.md)
- [AVCaptureTimecodeGenerator.SynchronizationStatus](avfoundation/avcapturetimecodegenerator/synchronizationstatus.md)
- [AVCaptureTimecode.Source](avfoundation/avcapturetimecode/source.md)
- [AVCaptureTimecode.SourceType](avfoundation/avcapturetimecode/sourcetype-swift.enum.md)
- [AVCaptureTimecode](avfoundation/avcapturetimecode.md)
- [advanced(_:by:)](avfoundation/avcapturetimecode/advanced(_:by:).md)
- [createMetadataSampleBuffer(from:associatedWithPresentationTimeStamp:)](avfoundation/avcapturetimecode/createmetadatasamplebuffer(from:associatedwithpresentationtimestamp:).md)
