--- url: "https://web.dev/articles/camera-pan-tilt-zoom" titulek: "Control camera pan, tilt, and zoom | Articles | web.dev" h1: "Control camera pan, tilt, and zoom Stay organized with collections Save and categorize content based on your preferences." popis: "Pan, tilt, and zoom features on cameras are finally controllable on the web." jazyk: "en" kanonicka: "https://web.dev/articles/camera-pan-tilt-zoom" drobecky: ["Articles", "Control camera pan, tilt, and zoom"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:55:50" znaku: 9046 slov: 1069 kodovani: "iso-8859-2" sha256: "a45e72add772b83a976515a44fd0f9dec272b030f34eadee78a9e4b3accff30e" --- Control camera pan, tilt, and zoom Stay organized with collections Save and categorize content based on your preferences. Pan, tilt, and zoom features on cameras are finally controllable on the web. François Beaufort Room-scale video conferencing solutions deploy cameras with pan, tilt, and zoom (PTZ) capabilities so that software can point the camera at meeting participants. Starting in Chrome 87, the pan, tilt, and zoom features on cameras are available to websites using media track constraints in `MediaDevices.getUserMedia()` and `MediaStreamTrack.applyConstraints()`. Using the API Feature detection Feature detection for hardware is different from what you're probably used to. The presence of `"pan"`, `"tilt"`, and `"zoom"` constraint names in `navigator.mediaDevices.getSupportedConstraints()` tells you that the browser supports the API to control camera PTZ, but not whether the camera hardware supports it. As of Chrome 87, controlling camera PTZ is supported on desktop, while Android still supports zoom only. `const supports = navigator.mediaDevices.getSupportedConstraints(); if (supports.pan && supports.tilt && supports.zoom) { // Browser supports camera PTZ. }` Request camera PTZ access A website is allowed to control camera PTZ only if the user has explicitly granted the camera with PTZ permission through a prompt. To request camera PTZ access, call `navigator.mediaDevices.getUserMedia()` with the PTZ constraints as shown below. This will prompt the user to grant both regular camera and camera with PTZ permissions. Camera PTZ user prompt. The returned promise resolves with a [`MediaStream`](https://developer.mozilla.org/docs/Web/API/MediaStream) object used to show the camera video stream to the user. If the camera does not support PTZ, the user is given a regular camera prompt. `try { // User is prompted to grant both camera and PTZ access in a single call. // If camera doesn't support PTZ, it falls back to a regular camera prompt. const stream = await navigator.mediaDevices.getUserMedia({ // Website asks to control camera PTZ as well without altering the // current pan, tilt, and zoom settings. video: { pan: true, tilt: true, zoom: true } }); // Show camera video stream to user. document.querySelector("video").srcObject = stream; } catch (error) { // User denies prompt or matching media is not available. console.log(error); }` A previously-granted camera permission, specifically one without PTZ access, does not automatically gain PTZ access if it becomes available. This is true even when the camera itself supports PTZ. The permission must be requested again. Fortunately, you can use the [Permissions API](https://developer.mozilla.org/docs/Web/API/Permissions_API) to query and monitor the status of PTZ permission. `try { const panTiltZoomPermissionStatus = await navigator.permissions.query({ name: "camera", panTiltZoom: true }); if (panTiltZoomPermissionStatus.state == "granted") { // User has granted access to the website to control camera PTZ. } panTiltZoomPermissionStatus.addEventListener("change", () => { // User has changed PTZ permission status. }); } catch (error) { console.log(error); }` To know whether a Chromium-based browser supports PTZ for a camera, go to the internal `about://media-internals` page and check out the "Pan-Tilt-Zoom" column in the "Video Capture" tab; "pan tilt" and "zoom" respectively mean the camera supports the "PanTilt (Absolute)" and "Zoom (Absolute)" [UVC controls](https://www.usb.org/document-library/video-class-v15-document-set). The "PanTilt (Relative)" and "Zoom (Relative)" UVC controls are not supported in Chromium-based browsers. Internal page to debug PTZ camera support. Control camera PTZ Manipulate camera PTZ capabilities and settings using the preview `MediaStreamTrack` from the `stream` object obtained earlier. `MediaStreamTrack.getCapabilities()` returns a dictionary with the supported capabilities and the ranges or allowed values. Correspondingly, `MediaStreamTrack.getSettings()` returns the current settings. Pan, tilt, and zoom capabilities and settings are available only if supported by the camera and the user has granted PTZ permission to the camera. Controlling Camera PTZ. Call `videoTrack.applyConstraints()` with the appropriate [PTZ advanced constraints](https://bugs.chromium.org/p/chromium/issues/detail?id=1126045) to control camera pan, tilt, and zoom as shown in the example. The returned promise resolves if successful. It rejects if either: The camera with PTZ permission is not granted. The camera hardware does not support the PTZ constraint. The page is not visible to the user. Use the [Page Visibility API](https://developer.mozilla.org/docs/Web/API/Page_Visibility_API) to detect page visibility changes. `// Get video track capabilities and settings. const [videoTrack] = stream.getVideoTracks(); const capabilities = videoTrack.getCapabilities(); const settings = videoTrack.getSettings(); // Let the user control the camera pan motion if the camera supports it // and PTZ access is granted. if ("pan" in settings) { const input = document.querySelector("input[type=range]"); input.min = capabilities.pan.min; input.max = capabilities.pan.max; input.step = capabilities.pan.step; input.value = settings.pan; input.addEventListener("input", async () => { await videoTrack.applyConstraints({ advanced: [{ pan: input.value }] }); }); } if ("tilt" in settings) { // similar for tilt... } if ("zoom" in settings) { // similar for zoom... }` It's also possible to configure camera pan, tilt, and zoom by calling `navigator.mediaDevices.getUserMedia()` with some camera PTZ ideal constraint values. This is handy when camera PTZ capabilities are known in advance. Note that [mandatory constraints](https://developer.mozilla.org/en-US/docs/Web/API/Media_Capture_and_Streams_API/Constraints#specifying_a_range_of_values) (min, max, exact) are not allowed here. `const stream = await navigator.mediaDevices.getUserMedia({ // Website asks to reset known camera pan. video: { pan: 0, deviceId: { exact: "myCameraDeviceId" } } });` Playground You can play with the API by running the [demo](https://chrome.dev/f/ptz). Security Considerations The spec authors have designed and implemented this API using the core including user control, transparency, and ergonomics. The ability to use this API is primarily gated by the same permission model as the [Media Capture and Streams API](https://w3c.github.io/mediacapture-main). In response to a user prompt, the website is allowed to control camera PTZ only when the page is visible to the user. Browser compatibility MediaStream API Browser Support 55 12 15 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaStream) Permissions API Browser Support 43 79 46 16 [Source](https://developer.mozilla.org/docs/Web/API/Permissions) Page Visibility API Browser Support 33 12 18 7 [Source](https://developer.mozilla.org/docs/Web/API/Document/visibilityState) `MediaDevices.getUserMedia()` Browser Support 53 12 36 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia) `MediaDevices.getSupportedConstraints()` Browser Support 53 12 44 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaDevices/getSupportedConstraints) `MediaStreamTrack.applyConstraints()` Browser Support 59 12 43 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaStreamTrack/applyConstraints) `MediaStreamTrack.getCapabilities()` Browser Support 59 12 132 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaStreamTrack/getCapabilities) `MediaStreamTrack.getSettings()` Browser Support 59 12 50 11 [Source](https://developer.mozilla.org/docs/Web/API/MediaStreamTrack/getSettings) Helpful links [PTZ Explainer](https://github.com/w3c/mediacapture-image/blob/master/ptz-explainer.md) [Specification draft](https://w3c.github.io/mediacapture-image/) [GitHub repository](https://github.com/w3c/mediacapture-image) [ChromeStatus entry](https://www.chromestatus.com/feature/5570717087170560) [Chrome tracking bug](https://bugs.chromium.org/p/chromium/issues/detail?id=934063) Acknowledgements This article was reviewed by [Joe Medley](https://github.com/jpmedley) and [Thomas Steiner](https://github.com/tomayac). Thanks to [Rijubrata Bhaumik](https://github.com/riju) and [Eero Häkkinen](https://github.com/eehakkin) at Intel for their work on the spec and the implementation. Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2020-10-05 UTC.