Skip to navigation

Camera and recording options

Options for the camera source: photo and video modes, capture quality, audio, and the underlying MediaRecorder.

Related guides: Upload sources.

See all options for the full list.

cameraModes Since v1.13.0

Comma-separated list of camera recording modes. Order matters, the first mode will be selected by default.

Available values:

  • photo: photo mode, default
  • video: video mode

Attribute: camera-modes

DOM property: cameraModes

Type: comma separated string

Default: 'photo, video'

defaultCameraMode Since v1.11.0 Deprecated

Note: This option has been deprecated since v1.13.0. Use cameraModes instead. See Path 2: Camera configuration.

The camera mode to select when the camera is opened. Setting it moves that mode to the front of the cameraModes value, and unsetting it later doesn’t move it back. If it has never been set, the first mode from cameraModes is used.

Attribute: default-camera-mode

DOM property: defaultCameraMode

Type: string | null

Available values:

  • photo: photo mode
  • video: video mode

Default: null

Camera settings in the camera screen

cameraAspectRatio, cameraResolution, cameraAudioQuality, and cameraAudioMode each take a single value or a comma-separated list. A list of two or more values adds a picker for that setting to the camera settings, opened with the settings button in the camera’s bottom bar. The picker starts on the first item, except the resolution picker, which starts on the first resolution the camera supports. The user’s pick applies to the open camera without reopening it, lasts only while the camera is open, and resets when the option changes in the config.

The settings also list the available cameras and, in video mode with audio recording on, the microphones, whenever there are two or more of them. These need no configuration.

<uc-config
ctx-name="my-uploader"
pubkey="YOUR_PUBLIC_KEY"
camera-aspect-ratio="1:1, native, 4:3"
camera-resolution="auto, 720p, 4k"
camera-audio-mode="voice, music"
></uc-config>

cameraCapture Since v0.34.0

Type: "user" | "environment" | ""

Attribute: camera-capture

Default: ""

Indicate the value for the capture attribute of the input tag to trigger the native camera dialog.

  • "user": Indicates that the media should be captured using the device’s user-facing camera.
  • "environment": Suggests using the device’s outward-facing camera, which is helpful for capturing images of the environment around the user.
  • "": Indicates that the user agent should determine the most suitable camera to use.

See W3C HTML Media Capture for details.

cameraMirror

Mirrors the camera view, and the photos and videos taken with it.

Type: boolean

Attribute: camera-mirror

DOM property: cameraMirror

Default: false

Available in: regular and inline modes

cameraAspectRatio Since v1.36.0

The shape of camera photos and videos, as "w:h": "1:1", "4:3", "16:9", "9:16", and so on. The ratio is taken literally whatever the device orientation. native or an empty value keeps the camera’s own shape.

Photos and videos are cropped to the largest centered rectangle of the ratio, and the preview shows the same crop. The ratio is also requested from the camera. When the camera can’t deliver it, videos are cropped frame by frame, which costs some CPU while recording.

A comma-separated list lets the user pick in the camera screen, starting on the first item.

Attribute: camera-aspect-ratio

DOM property: cameraAspectRatio

Type: string

Default: ''

Example: '1:1' or '1:1, native, 4:3'

cameraResolution Since v1.36.0

The resolution requested from the camera, for both photo and video.

  • auto: a 1080 px short side in the cameraAspectRatio shape, or 1920×1080 without a ratio.
  • 720p, 1080p, 4k: a short side of 720, 1080, or 2160 px. The long side follows cameraAspectRatio, or 16:9 without a ratio.

The camera picks its closest supported resolution, so the value is a request, not a guarantee.

A comma-separated list lets the user pick in the camera screen, starting on the first item the camera supports. Presets above what the camera reports are left out.

Note: Large resolutions make big video files, which may exceed maxLocalFileSizeBytes.

Attribute: camera-resolution

DOM property: cameraResolution

Type: string

Default: 'auto'

Example: '1080p' or 'auto, 720p, 4k'

cameraPhotoQuality Since v1.36.0

The JPEG quality of camera photos, from 0 to 1.

Attribute: camera-photo-quality

DOM property: cameraPhotoQuality

Type: number

Default: 0.92

cameraVideoFormats Since v1.36.0

Video formats to record in, best first, as a comma-separated list. The first format the browser can record wins. When nothing listed is supported, the browser picks.

Available values:

  • webm: WebM.
  • mp4: MP4, with H.264 and AAC where the browser supports them.
  • A MIME type with a single codec, such as video/webm;codecs=vp9. A codec list doesn’t work here, since its commas would split the list.

For an exact codec list, set mimeType in mediaRecorderOptions. It takes precedence when the browser supports it.

Attribute: camera-video-formats

DOM property: cameraVideoFormats

Type: comma separated string

Default: 'webm, mp4'

Example: 'mp4, webm'

cameraAudioQuality Since v1.36.0

The audio bitrate of video recordings.

  • auto: the browser decides.
  • low: 32 kbps.
  • standard: 96 kbps.
  • high: 192 kbps.

An explicit audioBitsPerSecond or bitsPerSecond in mediaRecorderOptions takes precedence.

A comma-separated list lets the user pick in the camera screen, in video mode with audio recording on, starting on the first item.

Attribute: camera-audio-quality

DOM property: cameraAudioQuality

Type: string

Default: 'auto'

Example: 'high' or 'auto, low, high'

cameraAudioMode Since v1.36.0

How the microphone is set up for video recordings.

  • voice: the browser defaults for speech, usually mono with echo cancellation, noise suppression, and auto gain.
  • music: stereo where the microphone supports it, with that processing off.

audio in cameraConstraints overrides it setting by setting. A change reopens only the microphone, and the camera keeps running. During a recording, the change waits until the recording stops.

A comma-separated list lets the user pick in the camera screen, in video mode with audio recording on, starting on the first item.

Attribute: camera-audio-mode

DOM property: cameraAudioMode

Type: string

Default: 'voice'

Example: 'music' or 'voice, music'

cameraConstraints Since v1.36.0

Works as DOM property only.

Extra getUserMedia constraints for the camera and microphone, as an object or as a function of the active camera mode.

Each property replaces the built-in value of the same name (width, height, frameRate, and so on). The camera and microphone picked in the camera screen always win over deviceId.

The constraints are re-applied when the option changes or, for the function form, when the user switches between photo and video. Video constraints apply to the open camera, and audio constraints reopen only the microphone. Changes made during a recording apply once it stops.

Note: If the camera can’t satisfy the constraints, it opens without them and logs a warning to the console.
const config = document.querySelector('uc-config');
config.cameraConstraints = ({ mode }) => ({
video: mode === 'video' ? { frameRate: { ideal: 60 } } : { facingMode: 'environment' },
});

Attribute: -

DOM property: cameraConstraints

Type: { video?: MediaTrackConstraints; audio?: MediaTrackConstraints } | (({ mode }: { mode: 'photo' | 'video' }) => { video?: MediaTrackConstraints; audio?: MediaTrackConstraints }) | null

Default: null

mediaRecorderOptions Since v1.13.0

Works as DOM property only.

Options passed to the browser’s MediaRecorder for video recordings. A supported mimeType takes precedence over cameraVideoFormats, and audioBitsPerSecond or bitsPerSecond take precedence over cameraAudioQuality.

Attribute: -

DOM property: mediaRecorderOptions

Type: MediaRecorderOptions | null

Default: null

enableAudioRecording Since v1.11.0

Allows to record audio while using the camera in video mode. true by default. To film video without audio, set it to false.

Attribute: enable-audio-recording

DOM property: enableAudioRecording

Type: boolean

Default: true

maxVideoRecordingDuration Since v1.11.0

Maximum video recording duration, in seconds. Recording stops automatically when the limit is reached. null or 0 means no limit.

Attribute: max-video-recording-duration

DOM property: maxVideoRecordingDuration

Type: number

Default: null

enableVideoRecording Since v1.11.0 Deprecated

Note: This option has been deprecated since v1.13.0. Use cameraModes instead.

Setting it to true adds video to cameraModes, and false removes it. It rewrites the cameraModes value, so unsetting it later doesn’t bring the previous modes back. While it has never been set, cameraModes alone decides, and video is available by default.

Attribute: enable-video-recording

DOM property: enableVideoRecording

Type: boolean

Default: not set