<!--
{
  "availability" : [
    "iOS: 4.1.0 - 27.0.0",
    "iPadOS: 4.1.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.7.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVAssetWriterInput/requestMediaDataWhenReady(on:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAssetWriterInput(im)requestMediaDataWhenReadyOnQueue:usingBlock:"
  },
  "title" : "requestMediaDataWhenReady(on:using:)"
}
-->

# requestMediaDataWhenReady(on:using:)

Tells the input to request media data, at its convenience, to write to the output file.

```
func requestMediaDataWhenReady(on queue: dispatch_queue_t, using block: @escaping @Sendable () -> Void)
```

## Parameters

`queue`

The queue on which the system invokes the callback.

`block`

A callback that the input invokes to retrieve additional media data.

## Discussion

Use this method when working with pull-style buffer sources, such as an [`AVAssetReaderOutput`](/documentation/AVFoundation/AVAssetReaderOutput). The callback you provide appends media data to the input until its [`isReadyForMoreMediaData`](/documentation/AVFoundation/AVAssetWriterInput/isReadyForMoreMediaData) property becomes <doc://com.apple.documentation/documentation/Swift/false>, or when there’s no more media data to process (at which point you may mark the input as finished by calling its [`markAsFinished()`](/documentation/AVFoundation/AVAssetWriterInput/markAsFinished()) method). If you don’t mark the input as finished, after the input processes the media data and becomes ready for more, it invokes the callback again to append more data. The example below shows a typical callback implementation.

```swift
let serialQueue = DispatchQueue(label: "RequestMedia")
assetWriterInput?.requestMediaDataWhenReady(on: serialQueue) { [weak self] in
    guard let self = self,
          let assetWriterInput = self.assetWriterInput else { return }
    while self.assetWriterInput!.isReadyForMoreMediaData {
        // Copy the next sample buffer from your source media.
        guard let nextSampleBuffer = copyNextSampleBufferToWrite() else {
            // Mark the input as finished.
            self.assetWriterInput!.markAsFinished()
            break
        }
        // Append the sample buffer to the input.
        self.assetWriterInput!.append(nextSampleBuffer)
    }      
}
```

When working with push-style sources, such as an [`AVCaptureAudioDataOutput`](/documentation/AVFoundation/AVCaptureAudioDataOutput) or [`AVCaptureVideoDataOutput`](/documentation/AVFoundation/AVCaptureVideoDataOutput), append buffers directly to the asset writer input when you receive them using its [`append(_:)`](/documentation/AVFoundation/AVAssetWriterInput/append(_:)) method. Using this method helps avoid having to queue up buffers in between the buffer source and the asset writer input.

---

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)