---
title: "startSession(atSourceTime:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avassetwriter/startsession(atsourcetime:)"
---

# startSession(atSourceTime:)

Starts an asset-writing session.

## Declaration

```swift
func startSession(atSourceTime startTime: CMTime)
```

## Parameters

- `startTime`: The starting asset time for the sample-writing session, in the timeline of the source samples.

## Discussion

Discussion You must call this method after you call startWriting(), but before you append sample data to asset writer inputs. Each writing session has a start time that, where allowed by the file format you’re writing, defines the mapping from the timeline of source samples to the timeline of the written file. In the case of the QuickTime movie file format, the first session begins at movie time 0, so a sample you append with timestamp T plays at movie time (T-startTime). The writer adds samples with timestamps earlier than the start time to the output file, but they don’t display during playback. If the earliest sample for an input has a timestamp later than the start time, the system inserts an empty edit to preserve synchronization between tracks of the output asset. To end a session, call endSession(atSourceTime:)or finishWriting(completionHandler:) note: An asset writer doesn’t support multiple sample-writing sessions. It’s an error to call startSession(atSourceTime:) a second time after calling endSession(atSourceTime:).

## See Also

### Managing writing sessions

- [start()](avfoundation/avassetwriter/start().md)
- [startWriting()](avfoundation/avassetwriter/startwriting().md)
- [endSession(atSourceTime:)](avfoundation/avassetwriter/endsession(atsourcetime:).md)
- [finishWriting(completionHandler:)](avfoundation/avassetwriter/finishwriting(completionhandler:).md)
- [cancelWriting()](avfoundation/avassetwriter/cancelwriting().md)
- [finishWriting()](avfoundation/avassetwriter/finishwriting().md)
