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

# AVAssetWriter

An object that writes media data to a container file.

```
class AVAssetWriter
```

## Overview

You use an asset writer to write media to file formats such as the QuickTime movie file format and MPEG-4 file format. An asset writer automatically supports interleaving media data from concurrent tracks for efficient playback and storage. It can reencode media samples it writes to the output file, and may also write collections of metadata to the output file.

> Important:
> An asset writer is a single-use object that writes one output file. Create multiple asset writer instances if your app requires writing multiple output files.

## Topics

### Creating an asset writer

[`init(url:fileType:)`](/documentation/AVFoundation/AVAssetWriter/init(url:fileType:)-xt34)

Returns a new object that writes media data to a container file at the output URL.

[`init(outputURL:fileType:)`](/documentation/AVFoundation/AVAssetWriter/init(outputURL:fileType:))

Creates an object that writes media data to a container file at the output URL.

[`init(contentType:)`](/documentation/AVFoundation/AVAssetWriter/init(contentType:))

Creates an object that outputs segment data in a specified container format.

### Configuring inputs

[`inputs`](/documentation/AVFoundation/AVAssetWriter/inputs)

The inputs an asset writer contains.

[`availableMediaTypes`](/documentation/AVFoundation/AVAssetWriter/availableMediaTypes)

The media types the asset writer supports adding as inputs.

[`canApply(outputSettings:forMediaType:)`](/documentation/AVFoundation/AVAssetWriter/canApply(outputSettings:forMediaType:))

Determines whether the output file format supports the output settings for a specific media type.

[`canAdd(_:)`](/documentation/AVFoundation/AVAssetWriter/canAdd(_:)-6al7j)

Determines whether the asset writer supports adding the input.

[`add(_:)`](/documentation/AVFoundation/AVAssetWriter/add(_:)-4c4d0)

Adds an input to an asset writer.

### Configuring input receivers

[`inputReceiver(for:)`](/documentation/AVFoundation/AVAssetWriter/inputReceiver(for:))

Attaches the input to the writer and returns an input receiver for writing sample buffers.

[`inputCaptionReceiver(for:)`](/documentation/AVFoundation/AVAssetWriter/inputCaptionReceiver(for:))

Attaches the input to the writer and returns an input receiver for writing caption data.

[`inputCaptionReceiverRequestingMultiPass(for:)`](/documentation/AVFoundation/AVAssetWriter/inputCaptionReceiverRequestingMultiPass(for:))

Attaches the input to the writer and returns a tuple with an input receiver for writing caption data, and an associated multi pass controller.

[`inputMetadataReceiver(for:)`](/documentation/AVFoundation/AVAssetWriter/inputMetadataReceiver(for:))

Attaches the input to the writer and returns an input receiver for writing timed metadata group.

[`inputMetadataReceiverRequestingMultiPass(for:)`](/documentation/AVFoundation/AVAssetWriter/inputMetadataReceiverRequestingMultiPass(for:))

Attaches the input to the writer and returns a tuple with an input receiver for writing timed metadata group, and an associated multi pass controller.

[`inputPixelBufferReceiver(for:pixelBufferAttributes:)`](/documentation/AVFoundation/AVAssetWriter/inputPixelBufferReceiver(for:pixelBufferAttributes:))

Attaches the input to the writer and returns an input receiver for writing pixel buffers.

[`inputPixelBufferReceiverRequestingMultiPass(for:pixelBufferAttributes:)`](/documentation/AVFoundation/AVAssetWriter/inputPixelBufferReceiverRequestingMultiPass(for:pixelBufferAttributes:))

Attaches the input to the writer and returns a tuple with an input receiver for writing pixel buffers, and an associated multi pass controller.

[`inputReceiverRequestingMultiPass(for:)`](/documentation/AVFoundation/AVAssetWriter/inputReceiverRequestingMultiPass(for:))

Attaches the input to the writer and returns a tuple with an input receiver for writing sample buffers, and an associated multi pass controller.

[`inputTaggedPixelBufferGroupReceiver(for:pixelBufferAttributes:)`](/documentation/AVFoundation/AVAssetWriter/inputTaggedPixelBufferGroupReceiver(for:pixelBufferAttributes:))

Attaches the input to the writer and returns an input receiver for writing tagged pixel buffers.

[`inputTaggedPixelBufferGroupReceiverRequestingMultiPass(for:pixelBufferAttributes:)`](/documentation/AVFoundation/AVAssetWriter/inputTaggedPixelBufferGroupReceiverRequestingMultiPass(for:pixelBufferAttributes:))

Attaches the input to the writer and returns a tuple with an input receiver for writing tagged pixel buffers, and an associated multi pass controller.

### Configuring input groups

[`inputGroups`](/documentation/AVFoundation/AVAssetWriter/inputGroups)

The input groups an asset writer contains.

[`canAdd(_:)`](/documentation/AVFoundation/AVAssetWriter/canAdd(_:)-8s1oh)

Determines whether the asset writer supports adding the input group.

[`add(_:)`](/documentation/AVFoundation/AVAssetWriter/add(_:)-3san4)

Adds an input group to an asset writer.

### Configuring output

[`metadata`](/documentation/AVFoundation/AVAssetWriter/metadata)

An array of metadata items to write to the output file.

[`shouldOptimizeForNetworkUse`](/documentation/AVFoundation/AVAssetWriter/shouldOptimizeForNetworkUse)

A Boolean value that indicates whether to write the output file to make it more suitable for playback over a network.

[`directoryForTemporaryFiles`](/documentation/AVFoundation/AVAssetWriter/directoryForTemporaryFiles)

A directory to contain temporary files that the export process generates.

### Configuring fragment output

[`movieFragmentInterval`](/documentation/AVFoundation/AVAssetWriter/movieFragmentInterval)

The interval at which to write movie fragments.

[`initialMovieFragmentInterval`](/documentation/AVFoundation/AVAssetWriter/initialMovieFragmentInterval)

The interval at which to write the initial movie fragment.

[`initialMovieFragmentSequenceNumber`](/documentation/AVFoundation/AVAssetWriter/initialMovieFragmentSequenceNumber)

The sequence number of the initial movie fragment.

[`producesCombinableFragments`](/documentation/AVFoundation/AVAssetWriter/producesCombinableFragments)

A Boolean value that indicates whether the asset writer outputs movie fragments suitable for combining with others.

[`overallDurationHint`](/documentation/AVFoundation/AVAssetWriter/overallDurationHint)

A hint of the final duration of the output file.

[`movieTimeScale`](/documentation/AVFoundation/AVAssetWriter/movieTimeScale)

The time scale of the movie.

### Managing writing sessions

[`start()`](/documentation/AVFoundation/AVAssetWriter/start())

Prepares the writer to write media data to its output file.

[`startWriting()`](/documentation/AVFoundation/AVAssetWriter/startWriting())

Tells the writer to start writing its output.

[`startSession(atSourceTime:)`](/documentation/AVFoundation/AVAssetWriter/startSession(atSourceTime:))

Starts an asset-writing session.

[`endSession(atSourceTime:)`](/documentation/AVFoundation/AVAssetWriter/endSession(atSourceTime:))

Finishes an asset-writing session.

[`finishWriting(completionHandler:)`](/documentation/AVFoundation/AVAssetWriter/finishWriting(completionHandler:))

Marks all unfinished inputs as finished and completes the writing of the output file.

[`cancelWriting()`](/documentation/AVFoundation/AVAssetWriter/cancelWriting())

Cancels the creation of the output file.

[`finishWriting()`](/documentation/AVFoundation/AVAssetWriter/finishWriting())

Completes the writing of the output file.

### Inspecting writing status

[`status`](/documentation/AVFoundation/AVAssetWriter/status-swift.property)

The status of writing samples to the output file.

[`AVAssetWriter.Status`](/documentation/AVFoundation/AVAssetWriter/Status-swift.enum)

Values that indicate the state of an asset writer.

[`error`](/documentation/AVFoundation/AVAssetWriter/error)

An error object that describes an asset-writing failure.

### Configuring segment writing

[`delegate`](/documentation/AVFoundation/AVAssetWriter/delegate)

A delegate object that responds to asset-writing events.

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

A delegate protocol that defines the methods to implement to respond to asset-writing events.

[`preferredOutputSegmentInterval`](/documentation/AVFoundation/AVAssetWriter/preferredOutputSegmentInterval)

The interval of output segments that you prefer.

[`initialSegmentStartTime`](/documentation/AVFoundation/AVAssetWriter/initialSegmentStartTime)

The start time of the initial segment.

[`outputFileTypeProfile`](/documentation/AVFoundation/AVAssetWriter/outputFileTypeProfile)

A profile for the output file type.

[`flushSegment()`](/documentation/AVFoundation/AVAssetWriter/flushSegment())

Closes the current segment and outputs it to a delegate method.

### Accessing output settings

[`outputURL`](/documentation/AVFoundation/AVAssetWriter/outputURL)

The location of the container file that the writer outputs.

[`outputFileType`](/documentation/AVFoundation/AVAssetWriter/outputFileType)

The type of container file that the writer outputs.



---

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)