VideoDecoder: phương thức decode()

Limited availability

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

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Dedicated Web Workers.

Phương thức decode() của giao diện VideoDecoder thêm một thông điệp điều khiển vào hàng đợi để giải mã một đoạn video nhất định.

Cú pháp

js
decode(chunk)

Tham số

chunk

Một đối tượng EncodedVideoChunk biểu thị một đoạn video đã được mã hóa.

Giá trị trả về

Không có (undefined).

Ngoại lệ

InvalidStateError DOMException

Ném ra nếu state không phải là configured.

DataError DOMException

Ném ra nếu chunk không thể được giải mã do phụ thuộc vào các khung khác để giải mã.

Ví dụ

Ví dụ sau đây minh họa cách sử dụng phương thức decode() để giải mã các đối tượng EncodedVideoChunk được tạo từ dữ liệu video đã mã hóa.

js
const responses = await downloadVideoChunksFromServer(timestamp);
for (const response of responses) {
  const chunk = new EncodedVideoChunk({
    timestamp: response.timestamp,
    type: response.key ? "key" : "delta",
    data: new Uint8Array(response.body),
  });
  decoder.decode(chunk);
}

Thông số kỹ thuật

Specification
WebCodecs
# dom-videodecoder-decode

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