---
title: "webcamMedia"
description: "The user's camera, live in the layer."
group: "paint"
groupTitle: "Painting"
categoryId: "media"
categorySlug: "media"
categoryTitle: "Media"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/media.ts#L174"
---

# webcamMedia

The user's camera, live in the layer.

```ts
webcamMedia(opts: MediaFitSlots & {
    /** The selfie-mirror boolean prop. */
    mirror: PropRef
    /** The `getUserMedia` constraints to request the camera with. */
    constraints: MediaStreamConstraints
    /** The key the definition's `naturalSizeKey: {fixed}` uses (a webcam has no URL). */
    naturalSizeKey: string
    onError?: (
  error: unknown,
  info: {url: string | null; stage: 'acquire' | 'autoplay'},
) => void
}): MediaSurfaceHalf
```

Import `media` from `shaders/std` and use `media.webcamMedia`.

Asks for camera permission with your `constraints`. `mirror` is a boolean prop for a selfie flip that updates instantly. This word also accepts `fit: 'none'` to show the feed at its native pixel size. Set `naturalSizeKey: {fixed: '<key>'}` on the definition and pass the same key here. `onError` receives permission denials and playback failures.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `opts` | `MediaFitSlots & {
    /** The selfie-mirror boolean prop. */
    mirror: PropRef
    /** The `getUserMedia` constraints to request the camera with. */
    constraints: MediaStreamConstraints
    /** The key the definition's `naturalSizeKey: {fixed}` uses (a webcam has no URL). */
    naturalSizeKey: string
    onError?: (error: unknown, info: {url: string \| null; stage: 'acquire' \| 'autoplay'}) => void
}` |  |

## Example

```ts
...webcamMedia({fit: p('objectFit'), mirror: p('mirror'), decode: 'srgb-linear-alpha-cut', constraints: {video: {facingMode: 'user'}}, naturalSizeKey: 'webcam'})
```

## See also

- [`videoMedia`](/docs/primitives/media/videomedia) — A video from a URL prop, playing in the layer.
- [`imageMedia`](/docs/primitives/media/imagemedia) — An image from a URL prop, fitted into the layer.

## Used by

[WebcamTexture](/docs/components/webcamtexture)