# createFrameWriter

URL: https://www.caprid.com/docs/reference/typescript/caprid/relay/media/functions/createframewriter/

```ts
function createFrameWriter<F>(track, options?): FrameWriter<F>;
```

Defined in: [relay-sdks/ts/src/frame-writer.ts:127](https://github.com/caprids/relay-sdks/blob/main/ts/src/frame-writer.ts#L127)

Map encoded frames onto a registered track's groups (spec/behavior.md, "Media publishing").

A frame the relay has no subscription for is `'skipped'` at once, because an encoder loop cannot block on the write
deadline; publishing resumes at the next keyframe. When the backlog is full the transport has fallen behind:
keyframe grouping drops the backlog and the open group, frame grouping drops the oldest frame. Under keyframe grouping
the writer watches the track's demand from now until it closes, and says when it needs a keyframe.

```ts
const writer = createFrameWriter(track, { onKeyframeNeeded: () => (forceKeyframe = true) });
// in the VideoEncoder output callback, without awaiting:
void writer.write(chunkToLocFrame(chunk, { videoConfig })).then(count);
```

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-f"></a> `F` *extends* [`Frame`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/frame/) | [`Frame`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/frame/) |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `track` | [`RelayTrackWriter`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaytrackwriter/) |
| `options?` | [`FrameWriterOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/framewriteroptions/)\<`F`\> |

## Returns

[`FrameWriter`](https://www.caprid.com/docs/reference/typescript/caprid/relay/media/interfaces/framewriter/)\<`F`\>
