@bendyline/squisq-video-react 2.5.28 → 2.5.30

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.
@@ -6,7 +6,7 @@ import {
6
6
  QTFF,
7
7
  VideoSampleSink,
8
8
  WEBM
9
- } from "./chunk-EJ3DVPFF.js";
9
+ } from "./chunk-MOIVICAD.js";
10
10
  export {
11
11
  BlobSource,
12
12
  Input,
@@ -0,0 +1,129 @@
1
+ import {
2
+ ADTS,
3
+ AudioSampleSink,
4
+ BlobSource,
5
+ FLAC,
6
+ Input,
7
+ MATROSKA,
8
+ MP3,
9
+ MP4,
10
+ OGG,
11
+ QTFF,
12
+ WAVE,
13
+ WEBM
14
+ } from "./chunk-MOIVICAD.js";
15
+
16
+ // src/mediaEdit/mediaAudioSource.ts
17
+ import {
18
+ MEDIA_FX_SAMPLE_RATE,
19
+ createResampler
20
+ } from "@bendyline/squisq/mediaEdit";
21
+ var MEDIA_INPUT_FORMATS = [MP4, QTFF, WEBM, MATROSKA, WAVE, MP3, OGG, FLAC, ADTS];
22
+ async function probeMediaDuration(blob) {
23
+ const input = new Input({ source: new BlobSource(blob), formats: MEDIA_INPUT_FORMATS });
24
+ try {
25
+ return await input.computeDuration();
26
+ } finally {
27
+ input.dispose();
28
+ }
29
+ }
30
+ async function openMediaAudio(blob, options = {}) {
31
+ const input = new Input({ source: new BlobSource(blob), formats: MEDIA_INPUT_FORMATS });
32
+ const track = await input.getPrimaryAudioTrack();
33
+ if (!track) {
34
+ input.dispose();
35
+ return null;
36
+ }
37
+ const trackDurationSec = await track.computeDuration();
38
+ const sourceRate = track.sampleRate;
39
+ const channels = Math.min(2, Math.max(1, track.numberOfChannels));
40
+ const startSec = Math.max(0, options.startSec ?? 0);
41
+ const endSec = Math.max(startSec, Math.min(options.endSec ?? trackDurationSec, trackDurationSec));
42
+ const durationSec = endSec - startSec;
43
+ const frames = Math.round(durationSec * MEDIA_FX_SAMPLE_RATE);
44
+ const sourceFrames = Math.round(durationSec * sourceRate);
45
+ async function* open() {
46
+ const sink = new AudioSampleSink(track);
47
+ const resamplers = Array.from(
48
+ { length: channels },
49
+ () => createResampler(sourceRate, MEDIA_FX_SAMPLE_RATE)
50
+ );
51
+ let placed = 0;
52
+ let emitted = 0;
53
+ const feed = (planes) => {
54
+ const out = resamplers.map((r, c) => r.process(planes[c]));
55
+ const room2 = frames - emitted;
56
+ const take = Math.min(out[0].length, room2);
57
+ if (take <= 0) return null;
58
+ emitted += take;
59
+ return out.map((ch) => ch.length === take ? ch : ch.subarray(0, take));
60
+ };
61
+ for await (const sample of sink.samples(startSec, endSec)) {
62
+ try {
63
+ const at = Math.round((sample.timestamp - startSec) * sourceRate);
64
+ let planes = Array.from({ length: channels }, (_, c) => {
65
+ const plane = new Float32Array(sample.numberOfFrames);
66
+ sample.copyTo(plane, {
67
+ planeIndex: Math.min(c, sample.numberOfChannels - 1),
68
+ format: "f32-planar"
69
+ });
70
+ return plane;
71
+ });
72
+ if (at > placed) {
73
+ const gap = Math.min(at - placed, sourceFrames - placed);
74
+ if (gap > 0) {
75
+ const out2 = feed(Array.from({ length: channels }, () => new Float32Array(gap)));
76
+ placed += gap;
77
+ if (out2) yield out2;
78
+ }
79
+ }
80
+ const overlap = placed - at;
81
+ if (overlap > 0) planes = planes.map((p) => p.subarray(Math.min(overlap, p.length)));
82
+ const room2 = sourceFrames - placed;
83
+ if (room2 <= 0) break;
84
+ if (planes[0].length > room2) planes = planes.map((p) => p.subarray(0, room2));
85
+ if (planes[0].length === 0) continue;
86
+ placed += planes[0].length;
87
+ const out = feed(planes);
88
+ if (out) yield out;
89
+ } finally {
90
+ sample.close();
91
+ }
92
+ }
93
+ if (placed < sourceFrames) {
94
+ const out = feed(
95
+ Array.from({ length: channels }, () => new Float32Array(sourceFrames - placed))
96
+ );
97
+ if (out) yield out;
98
+ }
99
+ const tail = resamplers.map((r) => r.flush());
100
+ const room = frames - emitted;
101
+ if (room > 0) {
102
+ const padded = tail.map((ch) => {
103
+ const full = new Float32Array(room);
104
+ full.set(ch.subarray(0, room));
105
+ return full;
106
+ });
107
+ emitted += room;
108
+ yield padded;
109
+ }
110
+ }
111
+ return {
112
+ sampleRate: MEDIA_FX_SAMPLE_RATE,
113
+ channels,
114
+ frames,
115
+ durationSec,
116
+ trackDurationSec,
117
+ sourceSampleRate: sourceRate,
118
+ open,
119
+ // The same Input has already indexed the file for the audio track.
120
+ mediaDuration: async () => Math.max(trackDurationSec, await input.computeDuration()),
121
+ dispose: () => input.dispose()
122
+ };
123
+ }
124
+
125
+ export {
126
+ MEDIA_INPUT_FORMATS,
127
+ probeMediaDuration,
128
+ openMediaAudio
129
+ };