webcodecs-utils 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -486,6 +486,17 @@ function En(t) {
486
486
  }
487
487
  return e;
488
488
  }
489
+ async function R1(t) {
490
+ if (t.kind !== "audio")
491
+ throw new Error("Track must be an audio track");
492
+ const e = t.getSettings();
493
+ if (e.sampleRate)
494
+ return e.sampleRate;
495
+ const i = new AudioContext(), n = new MediaStreamAudioSourceNode(i, {
496
+ mediaStream: new MediaStream([t])
497
+ }), c = i.sampleRate;
498
+ return n.disconnect(), await i.close(), c;
499
+ }
489
500
  function bi(t) {
490
501
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
491
502
  }
@@ -9779,7 +9790,7 @@ cn(dn, "MPEGDecoderWebWorker");
9779
9790
  globalThis.MPEGMode = Nn;
9780
9791
  globalThis.Lame = ia;
9781
9792
  globalThis.BitStream = Or;
9782
- class R1 {
9793
+ class T1 {
9783
9794
  /**
9784
9795
  * Create a new MP3Encoder.
9785
9796
  *
@@ -9845,7 +9856,7 @@ class R1 {
9845
9856
  return this.encodedData.reduce((e, i) => e + i.length, 0);
9846
9857
  }
9847
9858
  }
9848
- class T1 {
9859
+ class W1 {
9849
9860
  /**
9850
9861
  * Create a new MP3Decoder.
9851
9862
  *
@@ -10078,7 +10089,7 @@ function ba(t, e, i, n, c) {
10078
10089
  o.start(), r().catch(S);
10079
10090
  });
10080
10091
  }
10081
- class W1 {
10092
+ class L1 {
10082
10093
  /**
10083
10094
  * Create a new MP4Demuxer instance.
10084
10095
  * @param file - The MP4 file to demux
@@ -10150,7 +10161,7 @@ class W1 {
10150
10161
  return this.mp4Data.info;
10151
10162
  }
10152
10163
  }
10153
- class L1 {
10164
+ class x1 {
10154
10165
  /**
10155
10166
  * Create a new InMemoryStorage instance
10156
10167
  * @param chunkSize Size of each chunk in bytes (default: 10MB)
@@ -10238,25 +10249,29 @@ class mn {
10238
10249
  throw new Error(`Unsupported track kind: ${e.kind}`);
10239
10250
  }
10240
10251
  createVideoStream(e, i) {
10241
- let n, c;
10242
- const o = i.frameRate ?? 30;
10252
+ let n, c, o;
10253
+ const m = i.frameRate ?? 30;
10243
10254
  return new ReadableStream({
10244
10255
  async start() {
10245
10256
  n = document.createElement("video"), n.srcObject = new MediaStream([e]), await Promise.all([
10246
10257
  n.play(),
10247
- new Promise((m) => {
10248
- n.onloadedmetadata = m;
10258
+ new Promise((h) => {
10259
+ n.onloadedmetadata = h;
10249
10260
  })
10250
10261
  ]), c = performance.now();
10251
10262
  },
10252
- async pull(m) {
10263
+ async pull(h) {
10253
10264
  for (; ; ) {
10254
- const h = performance.now();
10255
- if (h - c < 1e3 / o) {
10256
- await new Promise((S) => requestAnimationFrame(S));
10265
+ const S = performance.now();
10266
+ if (S - c < 1e3 / m) {
10267
+ await new Promise((G) => requestAnimationFrame(G));
10257
10268
  continue;
10258
10269
  }
10259
- c = h, m.enqueue(new VideoFrame(n, { timestamp: c * 1e3 }));
10270
+ const T = o ?? Math.round((S - c) * 1e3);
10271
+ o = T, c = S, h.enqueue(new VideoFrame(n, {
10272
+ timestamp: c * 1e3,
10273
+ duration: T
10274
+ }));
10260
10275
  break;
10261
10276
  }
10262
10277
  }
@@ -10302,7 +10317,7 @@ class mn {
10302
10317
  }
10303
10318
  }
10304
10319
  self.MediaStreamTrackProcessor || (self.MediaStreamTrackProcessor = mn);
10305
- const x1 = self.MediaStreamTrackProcessor || mn;
10320
+ const H1 = self.MediaStreamTrackProcessor || mn;
10306
10321
  var ya = Object.defineProperty, fa = (t, e, i) => e in t ? ya(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, oi = (t, e, i) => (fa(t, typeof e != "symbol" ? e + "" : e, i), i), I0 = /* @__PURE__ */ ((t) => (t[t.AVMEDIA_TYPE_UNKNOWN = -1] = "AVMEDIA_TYPE_UNKNOWN", t[t.AVMEDIA_TYPE_VIDEO = 0] = "AVMEDIA_TYPE_VIDEO", t[t.AVMEDIA_TYPE_AUDIO = 1] = "AVMEDIA_TYPE_AUDIO", t[t.AVMEDIA_TYPE_DATA = 2] = "AVMEDIA_TYPE_DATA", t[t.AVMEDIA_TYPE_SUBTITLE = 3] = "AVMEDIA_TYPE_SUBTITLE", t[t.AVMEDIA_TYPE_ATTACHMENT = 4] = "AVMEDIA_TYPE_ATTACHMENT", t[t.AVMEDIA_TYPE_NB = 5] = "AVMEDIA_TYPE_NB", t))(I0 || {}), di = /* @__PURE__ */ ((t) => (t[t.AVSEEK_FLAG_BACKWARD = 1] = "AVSEEK_FLAG_BACKWARD", t[t.AVSEEK_FLAG_BYTE = 2] = "AVSEEK_FLAG_BYTE", t[t.AVSEEK_FLAG_ANY = 4] = "AVSEEK_FLAG_ANY", t[t.AVSEEK_FLAG_FRAME = 8] = "AVSEEK_FLAG_FRAME", t))(di || {}), rt = /* @__PURE__ */ ((t) => (t.WasmWorkerLoaded = "WasmWorkerLoaded", t.WASMRuntimeInitialized = "WASMRuntimeInitialized", t.LoadWASM = "LoadWASM", t.GetAVPacket = "GetAVPacket", t.GetAVPackets = "GetAVPackets", t.GetAVStream = "GetAVStream", t.GetAVStreams = "GetAVStreams", t.GetMediaInfo = "GetMediaInfo", t.ReadAVPacket = "ReadAVPacket", t.AVPacketStream = "AVPacketStream", t.ReadNextAVPacket = "ReadNextAVPacket", t.StopReadAVPacket = "StopReadAVPacket", t.SetAVLogLevel = "SetAVLogLevel", t))(rt || {});
10307
10322
  const un = "video", Za = "audio", Xa = "subtitle", ws = {
10308
10323
  VIDEO: un
@@ -10611,7 +10626,7 @@ function Zi() {
10611
10626
  "⚠️ Demo/Learning Function: This utility is intended for demos and learning purposes only. For production use, please use a proper demuxing library like MediaBunny (https://mediabunny.dev/) or web-demuxer (https://github.com/bilibili/web-demuxer) directly."
10612
10627
  ), ks = !0);
10613
10628
  }
10614
- async function H1(t) {
10629
+ async function Y1(t) {
10615
10630
  Zi();
10616
10631
  const e = new fi({
10617
10632
  wasmFilePath: "https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm"
@@ -10625,7 +10640,7 @@ async function H1(t) {
10625
10640
  });
10626
10641
  });
10627
10642
  }
10628
- async function Y1(t) {
10643
+ async function w1(t) {
10629
10644
  Zi();
10630
10645
  const e = new fi({
10631
10646
  wasmFilePath: "https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm"
@@ -10648,7 +10663,7 @@ async function Y1(t) {
10648
10663
  config: m
10649
10664
  };
10650
10665
  }
10651
- async function w1(t) {
10666
+ async function K1(t) {
10652
10667
  Zi();
10653
10668
  const e = new fi({
10654
10669
  wasmFilePath: "https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm"
@@ -10672,7 +10687,7 @@ async function w1(t) {
10672
10687
  config: m
10673
10688
  };
10674
10689
  }
10675
- async function K1(t) {
10690
+ async function M1(t) {
10676
10691
  Zi();
10677
10692
  const e = new fi({
10678
10693
  wasmFilePath: "https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm"
@@ -13809,7 +13824,7 @@ class _1 {
13809
13824
  })();
13810
13825
  }
13811
13826
  }
13812
- class M1 {
13827
+ class k1 {
13813
13828
  /**
13814
13829
  * Create a new ExampleMuxer.
13815
13830
  *
@@ -13846,18 +13861,19 @@ class M1 {
13846
13861
  }
13847
13862
  }
13848
13863
  export {
13849
- M1 as ExampleMuxer,
13864
+ k1 as ExampleMuxer,
13850
13865
  V1 as GPUFrameRenderer,
13851
- L1 as InMemoryStorage,
13852
- T1 as MP3Decoder,
13853
- R1 as MP3Encoder,
13854
- W1 as MP4Demuxer,
13855
- x1 as MediaStreamTrackProcessor,
13856
- Y1 as demuxAudio,
13857
- w1 as demuxVideo,
13866
+ x1 as InMemoryStorage,
13867
+ W1 as MP3Decoder,
13868
+ T1 as MP3Encoder,
13869
+ L1 as MP4Demuxer,
13870
+ H1 as MediaStreamTrackProcessor,
13871
+ w1 as demuxAudio,
13872
+ K1 as demuxVideo,
13858
13873
  En as extractChannels,
13859
- K1 as getAudioChunks,
13874
+ M1 as getAudioChunks,
13860
13875
  v1 as getBitrate,
13861
13876
  I1 as getCodecString,
13862
- H1 as getVideoChunks
13877
+ R1 as getSampleRate,
13878
+ Y1 as getVideoChunks
13863
13879
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcodecs-utils",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Utility functions for working with WebCodecs API",
5
5
  "homepage": "https://webcodecsfundamentals.org",
6
6
  "repository": {