<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVPlannedSegmentWritingRequest",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVPlannedSegmentWritingRequest"
  },
  "title" : "AVPlannedSegmentWritingRequest"
}
-->

# AVPlannedSegmentWritingRequest

AVPlannedSegmentWritingRequest encompasses a request from the AVAssetWritingPlanner to the client code to write one incremental track segment.

```
class AVPlannedSegmentWritingRequest
```

## Overview

The client should respond to this request by writing the specified time range of data to a movie file at the specified segmentFileOutputURL, with start PTS zero. The client’s writing work may be completed asynchronously. If it completes successfully, clients must call the `-finish` or `-finishWithClientState` method on the request object. If writing the segment fails, clients must call the `-finishWithError:` method on the request object. If segment writing needs to be stopped before reaching the end of the segment, clients must call `-cancel`.

## Topics

### Inspecting the request

[`timeRange`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/timeRange)

The PTS range for this segment.

[`segmentFileOutputURL`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/segmentFileOutputURL)

The URL of the file where this incremental segment should be written to.

[`progress`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/progress)

The current progress for the track identified by assemblyTrackID.

[`assemblyTrackID`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/assemblyTrackID)

The trackID identifies which track should be written to this segment file. This is the same track ID in the AVAssetTrackPlan object. This is also the trackID the AVAssetWritingPlanner uses to build the assembled AVComposition before it calls the completion handler.

### Managing client state

[`clientStateToRestore`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/clientStateToRestore)

The client state persisted from the previous segment, if any. Specifically, this is the NSData provided to the previous segment’s finishWithClientState: method. The client is responsible to restore its client state before writing the current segment. For example, clients such as compositors with a temporal element may need some processing history of previous samples in order to generate an output sample at time N. This will be nil for algorithms that are stateless.

[`-  finishWithClientState:`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/finishWithClientState:)

Clients must call this method after all writing activities for the intermediate segment file have successfully completed. If called with nil, this is equivalent to calling finish.

### Finishing the request

[`-  finish`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/finish)

Clients must call this method after all writing activities for the intermediate segment file have successfully completed.

[`-  finishWithError:`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/finishWithError:)

Clients must call this method if a non-recoverable error occurs while generating the segment file. The completionHandler of AVAssetWritingPlanner will be called with an error whose code is AVErrorAssetWritingPlannerClientWritingError, and the error provided here will be available in the NSUnderlyingErrorKey of the userInfo dictionary. If called with nil, this is equivalent to calling finish.

[`-  cancel`](/documentation/AVFoundation/AVPlannedSegmentWritingRequest/cancel)

Clients should call this if the current segment is to be cancelled, but the export is still expected to be resumed at a later time. For example, this could happen if the export is running in the background and the expiration handler is called due to changes in system conditions.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

### Inherited By

[`AVPlannedVideoSegmentWritingRequest`](/documentation/AVFoundation/AVPlannedVideoSegmentWritingRequest)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)