From 4e109b51e735be630308689d494e78c00f375754 Mon Sep 17 00:00:00 2001 From: ForeverSc Date: Sat, 29 Jun 2024 14:14:47 +0800 Subject: [PATCH] docs: add get all packets example --- index.html | 59 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 6c31568..d60c911 100644 --- a/index.html +++ b/index.html @@ -23,6 +23,7 @@

Web-Demuxer

@@ -30,8 +31,10 @@

Web-Demuxer

@@ -41,14 +44,17 @@

Web-Demuxer

Purpose

-

WebCodecs only provide the ability to decode, but not to demux. mp4box.js is cool, but it only supports mp4 demux. Web-Demuxer aims to support as many multimedia formats as possible at once.

+

WebCodecs only provide the ability to decode, but not to demux. mp4box.js is cool, but it only supports mp4 + demux. Web-Demuxer aims to support as many multimedia formats as possible at once.

Features

    -
  • πŸͺ„ Specifically designed for WebCodecs, the API is very friendly for WebCodecs development, you can easily realize the media file demux.
  • +
  • πŸͺ„ Specifically designed for WebCodecs, the API is very friendly for WebCodecs development, you can easily + realize the media file demux.
  • πŸ“¦ One-time support for a variety of media formats, such as mov/mp4/mkv/webm/flv/m4v/wmv/avi, etc.
  • -
  • 🧩 Support for customized packaging, you can adjust the configuration, packaged in a specified format demuxer
  • +
  • 🧩 Support for customized packaging, you can adjust the configuration, packaged in a specified format + demuxer
@@ -69,7 +75,8 @@

Seek Video Frame

Play Video

-

Select a video file and enter the playback start and playback end points (default playback from beginning to end)

+

Select a video file and enter the playback start and playback end points (default playback from beginning + to end)

@@ -81,6 +88,18 @@

Play Video

+
+
+

Get All Video Packets

+

Select a video file and get all video packets, open devtools to see console output

+
+ +
+ + +
+
+
@@ -163,13 +182,39 @@

Play Video

}); }); + document.getElementById('example-get-all-video-packets-btn').addEventListener('click', async () => { + const file = document.getElementById('example-get-all-video-packets-file').files[0]; + + async function getAllPackets(file) { + await demuxer.load(file) + return new Promise((resolve) => { + const videoPackets = [] + const reader = demuxer.readAVPacket().getReader() + + reader.read().then(async function processAVPacket({ done, value }) { + if (done) { + resolve(videoPackets) // all packets read finished + return + } + + videoPackets.push(value) // get one video packet + // and you can generate video chunk for video decoder + // const videoChunk = demuxer.genEncodedVideoChunk(value) + + return reader.read().then(processAVPacket) + }) + }) + } + + console.log('all video packets:', await getAllPackets(file)); + }); + function wait(time) { return new Promise((resolve) => { setTimeout(resolve, time) }); } - })();