<!--
{
  "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/AVAssetWritingPlanner",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAssetWritingPlanner"
  },
  "title" : "AVAssetWritingPlanner"
}
-->

# AVAssetWritingPlanner

AVAssetWritingPlanner orchestrates incremental writing of media files.

```
class AVAssetWritingPlanner
```

## Overview

AVAssetWritingPlanner orchestrates an incremental and resumable asset file
writing session. It keeps track of the progress of the incremental segments,
and can resume the writing from the last checkpoint. This is NOT intended for
any real time applications. Also, not all tracks can be written incrementally.
The workflow is as follows:

1. The client creates the planner with a unique directoryForTemporaryFiles.
2. The client tells the planner which tracks are to be written incrementally
   by calling the “planTrack:withSegmentsGeneratedBy:” method, providing a
   callback block that writes one segment per block invocation.
3. The client kicks off the incremental writing session by calling the
   “executePlanWithCompletionHandler” method.
4. The planner will call the writingSegmentCallbackBlock to ask the client to
   write one incremental segment of one track at a time. The client code
   should write one incremental segment according to the
   “AVPlannedSegmentWritingRequest” object passed in to the callback block.
   Clients must call “finish” or “finishWithError” or “finishWithClientState”
   or “cancel” methods on the request object when it finishes the segment
   successfully, or encountered an error, or wants to cancel the writing of
   the segment.
5. At the end of the writing, after all incremental segments are finished,
   the planner calls the completionHandler. The client can use the
   “assemblyComposition” object passed in to the completionHandler to
   assemble the incremental segments into full tracks and export it to a
   final output file. The completionHandler will also be called when there
   is any irrecoverable error.
6. The client is responsible for cleaning all files in the
   directoryForTemporaryFiles after the incremental session is done and the
   final output file is written.

AVAssetWritingPlanner is able to recognize when a plan-in-progress matching
the plan was already saved at directoryForTemporaryFiles, presumably by a
previous invocation of the client, and possibly aborted due to that client
being terminated abruptly, and will assist by resuming the plan at the first
step that wasn’t previously completed.

## Topics

### Creating a planner

[`init(directoryForTemporaryFiles:)`](/documentation/AVFoundation/AVAssetWritingPlanner/init(directoryForTemporaryFiles:))

Creates an instance of AVAssetWritingPlanner given a unique file directory to host all incremental segment files and other intermediate files.

[`-  initWithDirectoryForTemporaryFiles:`](/documentation/AVFoundation/AVAssetWritingPlanner/initWithDirectoryForTemporaryFiles:)

Creates an instance of AVAssetWritingPlanner given a unique file directory to host all incremental segment files and other intermediate files.

### Planning tracks

[`plan(_:segmentHandler:)`](/documentation/AVFoundation/AVAssetWritingPlanner/plan(_:segmentHandler:))

Adds a track plan with manual segment completion control.

[`-  planTrack:withSegmentsGeneratedBy:`](/documentation/AVFoundation/AVAssetWritingPlanner/planTrack:withSegmentsGeneratedBy:)

Adds an AVAssetTrackPlan to this AVAssetWritingPlanner, with a block to be called by the planner to generate each segment of the track.

### Executing the plan

[`executePlan()`](/documentation/AVFoundation/AVAssetWritingPlanner/executePlan())

Starts the incremental segment writing.

[`-  executePlanWithCompletionHandler:`](/documentation/AVFoundation/AVAssetWritingPlanner/executePlanWithCompletionHandler:)

Starts the incremental segment writing.

[`-  executePlanOnQueue:withCompletionHandler:`](/documentation/AVFoundation/AVAssetWritingPlanner/executePlanOnQueue:withCompletionHandler:)

Starts the incremental segment writing on a given dispatch queue

### Getting segment boundary guidance

[`segmentBoundaryGuidelinesForVideo(codecType:encoderSpecification:)`](/documentation/AVFoundation/AVAssetWritingPlanner/segmentBoundaryGuidelinesForVideo(codecType:encoderSpecification:))

Returns segment boundary guidelines that help clients determine how to segment compression video tracks with best results.

[`+  segmentBoundaryGuidelinesForVideoCodecType:videoEncoderSpecification:`](/documentation/AVFoundation/AVAssetWritingPlanner/segmentBoundaryGuidelinesForVideoCodecType:videoEncoderSpecification:)

Returns segment boundary guidelines that help clients determine how to segment compression video tracks with best results.

[`+  segmentBoundaryRecommendationsForVideoAVAssetTrack:minimumSegmentDuration:minimumSegmentFrameCount:`](/documentation/AVFoundation/AVAssetWritingPlanner/segmentBoundaryRecommendations(forVideoTrack:minimumSegmentDuration:minimumSegmentFrameCount:))

Returns segment boundary recommendations for a given source video asset track.

### Getting progress

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

The current progress of the AVAssetWritingPlanner.

### Configuring segment boundaries

[`SegmentBoundaryGuidelines`](/documentation/AVFoundation/AVAssetWritingPlanner/SegmentBoundaryGuidelines)

AVPlannedVideoSegmentBoundaryGuidelines provides guidance on determining planned segment boundaries for a video track in an incremental writing session executed by the AVAssetWritingPlanner.

### Handling segment results

[`SegmentResult`](/documentation/AVFoundation/AVAssetWritingPlanner/SegmentResult)

Result type for manual segment completion control.

## Relationships

### Inherits From

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

### Conforms To

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

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

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

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

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

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

---

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)