<!--
{
  "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/endSession(atSourceTime:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAssetWriter(im)endSessionAtSourceTime:"
  },
  "title" : "endSession(atSourceTime:)"
}
-->

# endSession(atSourceTime:)

Finishes an asset-writing session.

```
func endSession(atSourceTime endTime: CMTime)
```

## Parameters

`endTime`

The ending asset time for the session, in the timeline of the source samples.

## Discussion

Call this method to complete a session that you started with [`startSession(atSourceTime:)`](/documentation/AVFoundation/AVAssetWriter/startSession(atSourceTime:)).

The end time defines the moment on the timeline of source samples at which the session ends. In the case of the QuickTime movie file format, each sample-writing session’s start and end time pair corresponds to a period of movie time into which a writer inserts samples. The writer adds samples with timestamps that are later than the session end time to the written file but they aren’t presented during playback. For example, if the first session has duration `D1 = endTime - startTime`, the writer inserts it into the written file at time `0` through `D1`; the second session would insert into the written file at time `D1` through `D1 + D2`, and so on. It’s legal to have a session with no samples; this causes the creation of an empty edit of the prescribed duration.

If you don’t explicitly call this method, the system invokes it automatically when you call [`finishWriting(completionHandler:)`](/documentation/AVFoundation/AVAssetWriter/finishWriting(completionHandler:)). In that case, the session’s effective end time is the timestamp of the last sample you append.

> Note:
> An asset writer doesn’t support multiple sample-writing sessions. It’s an error to call ``doc://com.apple.avfoundation/documentation/AVFoundation/AVAssetWriter/startSession(atSourceTime:)`` a second time after calling ``doc://com.apple.avfoundation/documentation/AVFoundation/AVAssetWriter/endSession(atSourceTime:)``.

---

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)