VideoFrame: rotation property

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Dedicated Web Workers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính rotation của giao diện VideoFrame trả về góc xoay của khung hình video.

Giá trị

Một số nguyên đại diện cho góc xoay (0, 90, 180, hoặc 270) tính bằng độ theo chiều kim đồng hồ. Mặc định là 0. Các số tùy ý (bao gồm số âm) được làm tròn đến góc phần tư tiếp theo.

Ví dụ

Phát hiện khi video từ camera bị xoay

Với một luồng khung hình video từ camera, được lấy bằng MediaStreamTrackProcessor, bạn có thể kiểm tra thuộc tính rotation trên các đối tượng VideoFrame để xem liệu các khung hình có bị xoay hay không.

js
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const track = stream.getTracks()[0];

const trackProcessor = new MediaStreamTrackProcessor(track);

const reader = trackProcessor.readable.getReader();
while (true) {
  const result = await reader.read();
  if (result.done) break;
  const frameFromCamera = result.value;
  // Returns 0, 90, 180, or 270 indicating the frame's rotation
  console.log(frameFromCamera.rotation);
}

Thông số kỹ thuật

Thông số kỹ thuật
WebCodecs
# dom-videoframe-rotation

Tương thích trình duyệt