@remotion/studio 4.0.459 → 4.0.461

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.
Files changed (107) hide show
  1. package/dist/Studio.d.ts +0 -1
  2. package/dist/Studio.js +4 -4
  3. package/dist/components/AudioWaveform.js +21 -13
  4. package/dist/components/Checkbox.d.ts +7 -0
  5. package/dist/components/Checkbox.js +38 -24
  6. package/dist/components/Editor.js +10 -9
  7. package/dist/components/ExpandedTracksProvider.d.ts +9 -4
  8. package/dist/components/ExpandedTracksProvider.js +45 -15
  9. package/dist/components/MenuBuildIndicator.js +1 -2
  10. package/dist/components/MenuCompositionName.js +1 -0
  11. package/dist/components/NewComposition/ComboBox.d.ts +1 -0
  12. package/dist/components/NewComposition/ComboBox.js +14 -5
  13. package/dist/components/RenderButton.js +1 -1
  14. package/dist/components/SequencePropsSubscriptionProvider.d.ts +3 -0
  15. package/dist/components/SequencePropsSubscriptionProvider.js +26 -0
  16. package/dist/components/Timeline/SequencePropsObserver.d.ts +1 -0
  17. package/dist/components/Timeline/SequencePropsObserver.js +24 -0
  18. package/dist/components/Timeline/SubscribeToNodePaths.d.ts +7 -0
  19. package/dist/components/Timeline/SubscribeToNodePaths.js +15 -0
  20. package/dist/components/Timeline/Timeline.js +30 -49
  21. package/dist/components/Timeline/TimelineBooleanField.d.ts +4 -4
  22. package/dist/components/Timeline/TimelineBooleanField.js +5 -5
  23. package/dist/components/Timeline/TimelineDragHandler.js +37 -3
  24. package/dist/components/Timeline/TimelineEnumField.d.ts +5 -5
  25. package/dist/components/Timeline/TimelineEnumField.js +23 -15
  26. package/dist/components/Timeline/TimelineExpandArrowButton.d.ts +1 -0
  27. package/dist/components/Timeline/TimelineExpandArrowButton.js +5 -3
  28. package/dist/components/Timeline/TimelineExpandedRow.d.ts +6 -6
  29. package/dist/components/Timeline/TimelineExpandedRow.js +4 -5
  30. package/dist/components/Timeline/TimelineExpandedSection.d.ts +2 -2
  31. package/dist/components/Timeline/TimelineExpandedSection.js +20 -9
  32. package/dist/components/Timeline/TimelineFieldRow.d.ts +2 -3
  33. package/dist/components/Timeline/TimelineFieldRow.js +66 -30
  34. package/dist/components/Timeline/TimelineHeightContainer.d.ts +7 -0
  35. package/dist/components/Timeline/TimelineHeightContainer.js +51 -0
  36. package/dist/components/Timeline/TimelineList.js +1 -1
  37. package/dist/components/Timeline/TimelineListItem.d.ts +2 -0
  38. package/dist/components/Timeline/TimelineListItem.js +33 -18
  39. package/dist/components/Timeline/TimelineNumberField.d.ts +5 -5
  40. package/dist/components/Timeline/TimelineNumberField.js +12 -10
  41. package/dist/components/Timeline/TimelineRotationField.d.ts +5 -5
  42. package/dist/components/Timeline/TimelineRotationField.js +10 -10
  43. package/dist/components/Timeline/TimelineSchemaField.d.ts +4 -6
  44. package/dist/components/Timeline/TimelineSchemaField.js +11 -11
  45. package/dist/components/Timeline/TimelineSequence.js +2 -2
  46. package/dist/components/Timeline/TimelineSlider.js +2 -2
  47. package/dist/components/Timeline/TimelineStack/get-stack.js +17 -31
  48. package/dist/components/Timeline/TimelineStack/index.js +0 -10
  49. package/dist/components/Timeline/TimelineTimeIndicators.js +2 -2
  50. package/dist/components/Timeline/TimelineTracks.d.ts +1 -1
  51. package/dist/components/Timeline/TimelineTracks.js +53 -12
  52. package/dist/components/Timeline/TimelineTranslateField.d.ts +5 -5
  53. package/dist/components/Timeline/TimelineTranslateField.js +19 -37
  54. package/dist/components/Timeline/TimelineVideoInfo.js +25 -140
  55. package/dist/components/Timeline/sequence-props-subscription-store.d.ts +10 -13
  56. package/dist/components/Timeline/sequence-props-subscription-store.js +56 -123
  57. package/dist/components/Timeline/use-sequence-props-subscription.d.ts +6 -6
  58. package/dist/components/Timeline/use-sequence-props-subscription.js +25 -55
  59. package/dist/components/Timeline/use-timeline-height.d.ts +5 -0
  60. package/dist/components/Timeline/use-timeline-height.js +39 -0
  61. package/dist/error-overlay/react-overlay/utils/get-source-map.d.ts +3 -3
  62. package/dist/error-overlay/react-overlay/utils/get-source-map.js +5 -5
  63. package/dist/error-overlay/react-overlay/utils/unmapper.d.ts +0 -6
  64. package/dist/error-overlay/react-overlay/utils/unmapper.js +8 -1
  65. package/dist/esm/{chunk-0njpenna.js → chunk-yzh34sp0.js} +3026 -3446
  66. package/dist/esm/internals.mjs +3026 -3446
  67. package/dist/esm/previewEntry.mjs +3028 -3449
  68. package/dist/esm/renderEntry.mjs +2 -5
  69. package/dist/helpers/calculate-timeline.d.ts +3 -2
  70. package/dist/helpers/calculate-timeline.js +43 -2
  71. package/dist/helpers/get-timeline-sequence-layout.js +3 -3
  72. package/dist/helpers/get-timeline-sequence-sort-key.d.ts +7 -1
  73. package/dist/helpers/timeline-layout.d.ts +19 -9
  74. package/dist/helpers/timeline-layout.js +50 -20
  75. package/dist/icons/Checkmark.d.ts +4 -1
  76. package/dist/icons/Checkmark.js +1 -5
  77. package/dist/icons/caret.d.ts +3 -1
  78. package/dist/icons/caret.js +5 -2
  79. package/dist/internals.d.ts +0 -1
  80. package/dist/previewEntry.js +1 -1
  81. package/dist/renderEntry.js +3 -3
  82. package/package.json +13 -21
  83. package/dist/audio-waveform-worker.d.ts +0 -1
  84. package/dist/audio-waveform-worker.js +0 -102
  85. package/dist/components/audio-waveform-worker-types.d.ts +0 -28
  86. package/dist/components/audio-waveform-worker-types.js +0 -2
  87. package/dist/components/draw-peaks.d.ts +0 -1
  88. package/dist/components/draw-peaks.js +0 -68
  89. package/dist/components/load-waveform-peaks.d.ts +0 -13
  90. package/dist/components/load-waveform-peaks.js +0 -76
  91. package/dist/components/looped-media-timeline.d.ts +0 -6
  92. package/dist/components/looped-media-timeline.js +0 -14
  93. package/dist/components/parse-color.d.ts +0 -1
  94. package/dist/components/parse-color.js +0 -17
  95. package/dist/components/slice-waveform-peaks.d.ts +0 -7
  96. package/dist/components/slice-waveform-peaks.js +0 -15
  97. package/dist/components/waveform-peak-processor.d.ts +0 -23
  98. package/dist/components/waveform-peak-processor.js +0 -77
  99. package/dist/esm/audio-waveform-worker.mjs +0 -354
  100. package/dist/helpers/extract-frames.d.ts +0 -18
  101. package/dist/helpers/extract-frames.js +0 -87
  102. package/dist/helpers/frame-database.d.ts +0 -16
  103. package/dist/helpers/frame-database.js +0 -65
  104. package/dist/helpers/resize-video-frame.d.ts +0 -4
  105. package/dist/helpers/resize-video-frame.js +0 -39
  106. package/dist/make-audio-waveform-worker.d.ts +0 -1
  107. package/dist/make-audio-waveform-worker.js +0 -10
@@ -1 +0,0 @@
1
- export declare const drawBars: (canvas: HTMLCanvasElement | OffscreenCanvas, peaks: Float32Array<ArrayBufferLike>, color: string, volume: number, width: number) => void;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawBars = void 0;
4
- const parse_color_1 = require("./parse-color");
5
- const CLIPPING_COLOR = '#FF7F50';
6
- const drawBars = (canvas, peaks, color, volume, width) => {
7
- const ctx = canvas.getContext('2d');
8
- if (!ctx) {
9
- throw new Error('Failed to get canvas context');
10
- }
11
- const { height } = canvas;
12
- const w = canvas.width;
13
- // Skip drawing when the target canvas has not been laid out yet.
14
- // `createImageData(0, h)` / `(w, 0)` throws a DOMException, which
15
- // surfaces in Studio's console for compositions with many audio
16
- // sequences — some segments are 0 px wide at certain zoom levels.
17
- if (w === 0 || height === 0) {
18
- return;
19
- }
20
- ctx.clearRect(0, 0, w, height);
21
- if (volume === 0)
22
- return;
23
- const [r, g, b, a] = (0, parse_color_1.parseColor)(color);
24
- const [cr, cg, cb, ca] = (0, parse_color_1.parseColor)(CLIPPING_COLOR);
25
- const imageData = ctx.createImageData(w, height);
26
- const { data } = imageData;
27
- const numBars = width;
28
- for (let barIndex = 0; barIndex < numBars; barIndex++) {
29
- const x = barIndex;
30
- if (x >= w)
31
- break;
32
- const peakIndex = Math.floor((barIndex / numBars) * peaks.length);
33
- const peak = peaks[peakIndex] || 0;
34
- const scaledPeak = peak * volume;
35
- const halfBar = Math.max(0, Math.min(height / 2, (scaledPeak * height) / 2));
36
- if (halfBar === 0)
37
- continue;
38
- const mid = height / 2;
39
- const barY = Math.round(mid - halfBar);
40
- const barEnd = Math.round(mid + halfBar);
41
- const isClipping = scaledPeak > 1;
42
- const clipTopEnd = isClipping ? Math.min(barY + 2, barEnd) : barY;
43
- const clipBotStart = isClipping ? Math.max(barEnd - 2, barY) : barEnd;
44
- for (let y = barY; y < clipTopEnd; y++) {
45
- const idx = (y * w + x) * 4;
46
- data[idx] = cr;
47
- data[idx + 1] = cg;
48
- data[idx + 2] = cb;
49
- data[idx + 3] = ca;
50
- }
51
- for (let y = clipTopEnd; y < clipBotStart; y++) {
52
- const idx = (y * w + x) * 4;
53
- data[idx] = r;
54
- data[idx + 1] = g;
55
- data[idx + 2] = b;
56
- data[idx + 3] = a;
57
- }
58
- for (let y = clipBotStart; y < barEnd; y++) {
59
- const idx = (y * w + x) * 4;
60
- data[idx] = cr;
61
- data[idx + 1] = cg;
62
- data[idx + 2] = cb;
63
- data[idx + 3] = ca;
64
- }
65
- }
66
- ctx.putImageData(imageData, 0, 0);
67
- };
68
- exports.drawBars = drawBars;
@@ -1,13 +0,0 @@
1
- declare const TARGET_SAMPLE_RATE = 100;
2
- export { TARGET_SAMPLE_RATE };
3
- type Progress = {
4
- readonly peaks: Float32Array;
5
- readonly completedPeaks: number;
6
- readonly totalPeaks: number;
7
- readonly final: boolean;
8
- };
9
- type LoadWaveformPeaksOptions = {
10
- readonly onProgress?: (progress: Progress) => void;
11
- readonly progressIntervalInMs?: number;
12
- };
13
- export declare function loadWaveformPeaks(url: string, signal: AbortSignal, options?: LoadWaveformPeaksOptions): Promise<Float32Array>;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TARGET_SAMPLE_RATE = void 0;
4
- exports.loadWaveformPeaks = loadWaveformPeaks;
5
- const mediabunny_1 = require("mediabunny");
6
- const waveform_peak_processor_1 = require("./waveform-peak-processor");
7
- const TARGET_SAMPLE_RATE = 100;
8
- exports.TARGET_SAMPLE_RATE = TARGET_SAMPLE_RATE;
9
- const DEFAULT_PROGRESS_INTERVAL_IN_MS = 50;
10
- const peaksCache = new Map();
11
- async function loadWaveformPeaks(url, signal, options) {
12
- var _a, _b;
13
- const cached = peaksCache.get(url);
14
- if (cached) {
15
- (0, waveform_peak_processor_1.emitWaveformProgress)({
16
- peaks: cached,
17
- completedPeaks: cached.length,
18
- totalPeaks: cached.length,
19
- final: true,
20
- onProgress: options === null || options === void 0 ? void 0 : options.onProgress,
21
- });
22
- return cached;
23
- }
24
- const input = new mediabunny_1.Input({
25
- formats: mediabunny_1.ALL_FORMATS,
26
- source: new mediabunny_1.UrlSource(url),
27
- });
28
- try {
29
- const audioTrack = await input.getPrimaryAudioTrack();
30
- if (!audioTrack) {
31
- return new Float32Array(0);
32
- }
33
- if (await audioTrack.isLive()) {
34
- throw new Error('Live streams are not currently supported by Remotion. Sorry! Source: ' +
35
- url);
36
- }
37
- if (await audioTrack.isRelativeToUnixEpoch()) {
38
- throw new Error('Streams with UNIX timestamps are not currently supported by Remotion. Sorry! Source: ' +
39
- url);
40
- }
41
- const sampleRate = await audioTrack.getSampleRate();
42
- const durationInSeconds = (_a = (await audioTrack.getDurationFromMetadata({ skipLiveWait: true }))) !== null && _a !== void 0 ? _a : (await audioTrack.computeDuration({ skipLiveWait: true }));
43
- const totalPeaks = Math.ceil(durationInSeconds * TARGET_SAMPLE_RATE);
44
- const samplesPerPeak = Math.max(1, Math.floor(sampleRate / TARGET_SAMPLE_RATE));
45
- const sink = new mediabunny_1.AudioSampleSink(audioTrack);
46
- const processor = (0, waveform_peak_processor_1.createWaveformPeakProcessor)({
47
- totalPeaks,
48
- samplesPerPeak,
49
- onProgress: options === null || options === void 0 ? void 0 : options.onProgress,
50
- progressIntervalInMs: (_b = options === null || options === void 0 ? void 0 : options.progressIntervalInMs) !== null && _b !== void 0 ? _b : DEFAULT_PROGRESS_INTERVAL_IN_MS,
51
- now: () => Date.now(),
52
- });
53
- for await (const sample of sink.samples()) {
54
- if (signal.aborted) {
55
- sample.close();
56
- return new Float32Array(0);
57
- }
58
- const bytesNeeded = sample.allocationSize({
59
- format: 'f32',
60
- planeIndex: 0,
61
- });
62
- const floats = new Float32Array(bytesNeeded / 4);
63
- sample.copyTo(floats, { format: 'f32', planeIndex: 0 });
64
- const channels = Math.max(1, sample.numberOfChannels);
65
- sample.close();
66
- processor.processSampleChunk(floats, channels);
67
- }
68
- processor.finalize();
69
- const { peaks } = processor;
70
- peaksCache.set(url, peaks);
71
- return peaks;
72
- }
73
- finally {
74
- input.dispose();
75
- }
76
- }
@@ -1,6 +0,0 @@
1
- import type { LoopDisplay } from 'remotion';
2
- export declare const shouldTileLoopDisplay: (loopDisplay: LoopDisplay | undefined) => loopDisplay is LoopDisplay;
3
- export declare const getLoopDisplayWidth: ({ visualizationWidth, loopDisplay, }: {
4
- visualizationWidth: number;
5
- loopDisplay: LoopDisplay | undefined;
6
- }) => number;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLoopDisplayWidth = exports.shouldTileLoopDisplay = void 0;
4
- const shouldTileLoopDisplay = (loopDisplay) => {
5
- return loopDisplay !== undefined && loopDisplay.numberOfTimes > 1;
6
- };
7
- exports.shouldTileLoopDisplay = shouldTileLoopDisplay;
8
- const getLoopDisplayWidth = ({ visualizationWidth, loopDisplay, }) => {
9
- if (!(0, exports.shouldTileLoopDisplay)(loopDisplay)) {
10
- return visualizationWidth;
11
- }
12
- return visualizationWidth / loopDisplay.numberOfTimes;
13
- };
14
- exports.getLoopDisplayWidth = getLoopDisplayWidth;
@@ -1 +0,0 @@
1
- export declare const parseColor: (color: string) => [number, number, number, number];
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseColor = void 0;
4
- const colorCache = new Map();
5
- const parseColor = (color) => {
6
- const cached = colorCache.get(color);
7
- if (cached)
8
- return cached;
9
- const ctx = new OffscreenCanvas(1, 1).getContext('2d');
10
- ctx.fillStyle = color;
11
- ctx.fillRect(0, 0, 1, 1);
12
- const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
13
- const result = [r, g, b, a];
14
- colorCache.set(color, result);
15
- return result;
16
- };
17
- exports.parseColor = parseColor;
@@ -1,7 +0,0 @@
1
- export declare const sliceWaveformPeaks: ({ durationInFrames, fps, peaks, playbackRate, startFrom, }: {
2
- readonly peaks: Float32Array<ArrayBufferLike>;
3
- readonly startFrom: number;
4
- readonly durationInFrames: number;
5
- readonly fps: number;
6
- readonly playbackRate: number;
7
- }) => Float32Array<ArrayBufferLike>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sliceWaveformPeaks = void 0;
4
- const load_waveform_peaks_1 = require("./load-waveform-peaks");
5
- const sliceWaveformPeaks = ({ durationInFrames, fps, peaks, playbackRate, startFrom, }) => {
6
- if (peaks.length === 0) {
7
- return peaks;
8
- }
9
- const startTimeInSeconds = startFrom / fps;
10
- const durationInSeconds = (durationInFrames / fps) * playbackRate;
11
- const startPeakIndex = Math.floor(startTimeInSeconds * load_waveform_peaks_1.TARGET_SAMPLE_RATE);
12
- const endPeakIndex = Math.ceil((startTimeInSeconds + durationInSeconds) * load_waveform_peaks_1.TARGET_SAMPLE_RATE);
13
- return peaks.subarray(Math.max(0, startPeakIndex), Math.min(peaks.length, endPeakIndex));
14
- };
15
- exports.sliceWaveformPeaks = sliceWaveformPeaks;
@@ -1,23 +0,0 @@
1
- type Progress = {
2
- readonly peaks: Float32Array;
3
- readonly completedPeaks: number;
4
- readonly totalPeaks: number;
5
- readonly final: boolean;
6
- };
7
- type WaveformPeakProcessorOptions = {
8
- readonly totalPeaks: number;
9
- readonly samplesPerPeak: number;
10
- readonly onProgress?: (progress: Progress) => void;
11
- readonly progressIntervalInMs: number;
12
- readonly now: () => number;
13
- };
14
- type WaveformPeakProcessor = {
15
- readonly peaks: Float32Array;
16
- processSampleChunk: (floats: Float32Array, channels: number) => void;
17
- finalize: () => void;
18
- };
19
- export declare const emitWaveformProgress: ({ completedPeaks, final, onProgress, peaks, totalPeaks, }: Progress & {
20
- readonly onProgress?: ((progress: Progress) => void) | undefined;
21
- }) => void;
22
- export declare const createWaveformPeakProcessor: ({ totalPeaks, samplesPerPeak, onProgress, progressIntervalInMs, now, }: WaveformPeakProcessorOptions) => WaveformPeakProcessor;
23
- export {};
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWaveformPeakProcessor = exports.emitWaveformProgress = void 0;
4
- const emitWaveformProgress = ({ completedPeaks, final, onProgress, peaks, totalPeaks, }) => {
5
- onProgress === null || onProgress === void 0 ? void 0 : onProgress({
6
- peaks,
7
- completedPeaks,
8
- totalPeaks,
9
- final,
10
- });
11
- };
12
- exports.emitWaveformProgress = emitWaveformProgress;
13
- const createWaveformPeakProcessor = ({ totalPeaks, samplesPerPeak, onProgress, progressIntervalInMs, now, }) => {
14
- const peaks = new Float32Array(totalPeaks);
15
- let peakIndex = 0;
16
- let peakMax = 0;
17
- let sampleInPeak = 0;
18
- let lastProgressAt = 0;
19
- let lastProgressPeak = 0;
20
- const emitProgress = (force) => {
21
- const timestamp = now();
22
- if (!force && peakIndex === lastProgressPeak && sampleInPeak === 0) {
23
- return;
24
- }
25
- if (!force && timestamp - lastProgressAt < progressIntervalInMs) {
26
- return;
27
- }
28
- lastProgressAt = timestamp;
29
- lastProgressPeak = peakIndex;
30
- (0, exports.emitWaveformProgress)({
31
- peaks,
32
- completedPeaks: peakIndex,
33
- totalPeaks,
34
- final: force,
35
- onProgress,
36
- });
37
- };
38
- return {
39
- peaks,
40
- processSampleChunk: (floats, channels) => {
41
- var _a;
42
- const frameCount = Math.floor(floats.length / Math.max(1, channels));
43
- for (let frame = 0; frame < frameCount; frame++) {
44
- // `f32` copies are interleaved, so timing advances per frame.
45
- let framePeak = 0;
46
- for (let channel = 0; channel < channels; channel++) {
47
- const sampleIndex = frame * channels + channel;
48
- const abs = Math.abs((_a = floats[sampleIndex]) !== null && _a !== void 0 ? _a : 0);
49
- if (abs > framePeak) {
50
- framePeak = abs;
51
- }
52
- }
53
- if (framePeak > peakMax) {
54
- peakMax = framePeak;
55
- }
56
- sampleInPeak++;
57
- if (sampleInPeak >= samplesPerPeak) {
58
- if (peakIndex < totalPeaks) {
59
- peaks[peakIndex] = peakMax;
60
- }
61
- peakIndex++;
62
- peakMax = 0;
63
- sampleInPeak = 0;
64
- }
65
- }
66
- emitProgress(false);
67
- },
68
- finalize: () => {
69
- if (sampleInPeak > 0 && peakIndex < totalPeaks) {
70
- peaks[peakIndex] = peakMax;
71
- peakIndex++;
72
- }
73
- emitProgress(true);
74
- },
75
- };
76
- };
77
- exports.createWaveformPeakProcessor = createWaveformPeakProcessor;
@@ -1,354 +0,0 @@
1
- // src/components/parse-color.ts
2
- var colorCache = new Map;
3
- var parseColor = (color) => {
4
- const cached = colorCache.get(color);
5
- if (cached)
6
- return cached;
7
- const ctx = new OffscreenCanvas(1, 1).getContext("2d");
8
- ctx.fillStyle = color;
9
- ctx.fillRect(0, 0, 1, 1);
10
- const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
11
- const result = [r, g, b, a];
12
- colorCache.set(color, result);
13
- return result;
14
- };
15
-
16
- // src/components/draw-peaks.ts
17
- var CLIPPING_COLOR = "#FF7F50";
18
- var drawBars = (canvas, peaks, color, volume, width) => {
19
- const ctx = canvas.getContext("2d");
20
- if (!ctx) {
21
- throw new Error("Failed to get canvas context");
22
- }
23
- const { height } = canvas;
24
- const w = canvas.width;
25
- if (w === 0 || height === 0) {
26
- return;
27
- }
28
- ctx.clearRect(0, 0, w, height);
29
- if (volume === 0)
30
- return;
31
- const [r, g, b, a] = parseColor(color);
32
- const [cr, cg, cb, ca] = parseColor(CLIPPING_COLOR);
33
- const imageData = ctx.createImageData(w, height);
34
- const { data } = imageData;
35
- const numBars = width;
36
- for (let barIndex = 0;barIndex < numBars; barIndex++) {
37
- const x = barIndex;
38
- if (x >= w)
39
- break;
40
- const peakIndex = Math.floor(barIndex / numBars * peaks.length);
41
- const peak = peaks[peakIndex] || 0;
42
- const scaledPeak = peak * volume;
43
- const halfBar = Math.max(0, Math.min(height / 2, scaledPeak * height / 2));
44
- if (halfBar === 0)
45
- continue;
46
- const mid = height / 2;
47
- const barY = Math.round(mid - halfBar);
48
- const barEnd = Math.round(mid + halfBar);
49
- const isClipping = scaledPeak > 1;
50
- const clipTopEnd = isClipping ? Math.min(barY + 2, barEnd) : barY;
51
- const clipBotStart = isClipping ? Math.max(barEnd - 2, barY) : barEnd;
52
- for (let y = barY;y < clipTopEnd; y++) {
53
- const idx = (y * w + x) * 4;
54
- data[idx] = cr;
55
- data[idx + 1] = cg;
56
- data[idx + 2] = cb;
57
- data[idx + 3] = ca;
58
- }
59
- for (let y = clipTopEnd;y < clipBotStart; y++) {
60
- const idx = (y * w + x) * 4;
61
- data[idx] = r;
62
- data[idx + 1] = g;
63
- data[idx + 2] = b;
64
- data[idx + 3] = a;
65
- }
66
- for (let y = clipBotStart;y < barEnd; y++) {
67
- const idx = (y * w + x) * 4;
68
- data[idx] = cr;
69
- data[idx + 1] = cg;
70
- data[idx + 2] = cb;
71
- data[idx + 3] = ca;
72
- }
73
- }
74
- ctx.putImageData(imageData, 0, 0);
75
- };
76
-
77
- // src/components/load-waveform-peaks.ts
78
- import { ALL_FORMATS, AudioSampleSink, Input, UrlSource } from "mediabunny";
79
-
80
- // src/components/waveform-peak-processor.ts
81
- var emitWaveformProgress = ({
82
- completedPeaks,
83
- final,
84
- onProgress,
85
- peaks,
86
- totalPeaks
87
- }) => {
88
- onProgress?.({
89
- peaks,
90
- completedPeaks,
91
- totalPeaks,
92
- final
93
- });
94
- };
95
- var createWaveformPeakProcessor = ({
96
- totalPeaks,
97
- samplesPerPeak,
98
- onProgress,
99
- progressIntervalInMs,
100
- now
101
- }) => {
102
- const peaks = new Float32Array(totalPeaks);
103
- let peakIndex = 0;
104
- let peakMax = 0;
105
- let sampleInPeak = 0;
106
- let lastProgressAt = 0;
107
- let lastProgressPeak = 0;
108
- const emitProgress = (force) => {
109
- const timestamp = now();
110
- if (!force && peakIndex === lastProgressPeak && sampleInPeak === 0) {
111
- return;
112
- }
113
- if (!force && timestamp - lastProgressAt < progressIntervalInMs) {
114
- return;
115
- }
116
- lastProgressAt = timestamp;
117
- lastProgressPeak = peakIndex;
118
- emitWaveformProgress({
119
- peaks,
120
- completedPeaks: peakIndex,
121
- totalPeaks,
122
- final: force,
123
- onProgress
124
- });
125
- };
126
- return {
127
- peaks,
128
- processSampleChunk: (floats, channels) => {
129
- const frameCount = Math.floor(floats.length / Math.max(1, channels));
130
- for (let frame = 0;frame < frameCount; frame++) {
131
- let framePeak = 0;
132
- for (let channel = 0;channel < channels; channel++) {
133
- const sampleIndex = frame * channels + channel;
134
- const abs = Math.abs(floats[sampleIndex] ?? 0);
135
- if (abs > framePeak) {
136
- framePeak = abs;
137
- }
138
- }
139
- if (framePeak > peakMax) {
140
- peakMax = framePeak;
141
- }
142
- sampleInPeak++;
143
- if (sampleInPeak >= samplesPerPeak) {
144
- if (peakIndex < totalPeaks) {
145
- peaks[peakIndex] = peakMax;
146
- }
147
- peakIndex++;
148
- peakMax = 0;
149
- sampleInPeak = 0;
150
- }
151
- }
152
- emitProgress(false);
153
- },
154
- finalize: () => {
155
- if (sampleInPeak > 0 && peakIndex < totalPeaks) {
156
- peaks[peakIndex] = peakMax;
157
- peakIndex++;
158
- }
159
- emitProgress(true);
160
- }
161
- };
162
- };
163
-
164
- // src/components/load-waveform-peaks.ts
165
- var TARGET_SAMPLE_RATE = 100;
166
- var DEFAULT_PROGRESS_INTERVAL_IN_MS = 50;
167
- var peaksCache = new Map;
168
- async function loadWaveformPeaks(url, signal, options) {
169
- const cached = peaksCache.get(url);
170
- if (cached) {
171
- emitWaveformProgress({
172
- peaks: cached,
173
- completedPeaks: cached.length,
174
- totalPeaks: cached.length,
175
- final: true,
176
- onProgress: options?.onProgress
177
- });
178
- return cached;
179
- }
180
- const input = new Input({
181
- formats: ALL_FORMATS,
182
- source: new UrlSource(url)
183
- });
184
- try {
185
- const audioTrack = await input.getPrimaryAudioTrack();
186
- if (!audioTrack) {
187
- return new Float32Array(0);
188
- }
189
- if (await audioTrack.isLive()) {
190
- throw new Error("Live streams are not currently supported by Remotion. Sorry! Source: " + url);
191
- }
192
- if (await audioTrack.isRelativeToUnixEpoch()) {
193
- throw new Error("Streams with UNIX timestamps are not currently supported by Remotion. Sorry! Source: " + url);
194
- }
195
- const sampleRate = await audioTrack.getSampleRate();
196
- const durationInSeconds = await audioTrack.getDurationFromMetadata({ skipLiveWait: true }) ?? await audioTrack.computeDuration({ skipLiveWait: true });
197
- const totalPeaks = Math.ceil(durationInSeconds * TARGET_SAMPLE_RATE);
198
- const samplesPerPeak = Math.max(1, Math.floor(sampleRate / TARGET_SAMPLE_RATE));
199
- const sink = new AudioSampleSink(audioTrack);
200
- const processor = createWaveformPeakProcessor({
201
- totalPeaks,
202
- samplesPerPeak,
203
- onProgress: options?.onProgress,
204
- progressIntervalInMs: options?.progressIntervalInMs ?? DEFAULT_PROGRESS_INTERVAL_IN_MS,
205
- now: () => Date.now()
206
- });
207
- for await (const sample of sink.samples()) {
208
- if (signal.aborted) {
209
- sample.close();
210
- return new Float32Array(0);
211
- }
212
- const bytesNeeded = sample.allocationSize({
213
- format: "f32",
214
- planeIndex: 0
215
- });
216
- const floats = new Float32Array(bytesNeeded / 4);
217
- sample.copyTo(floats, { format: "f32", planeIndex: 0 });
218
- const channels = Math.max(1, sample.numberOfChannels);
219
- sample.close();
220
- processor.processSampleChunk(floats, channels);
221
- }
222
- processor.finalize();
223
- const { peaks } = processor;
224
- peaksCache.set(url, peaks);
225
- return peaks;
226
- } finally {
227
- input.dispose();
228
- }
229
- }
230
-
231
- // src/components/looped-media-timeline.ts
232
- var shouldTileLoopDisplay = (loopDisplay) => {
233
- return loopDisplay !== undefined && loopDisplay.numberOfTimes > 1;
234
- };
235
- var getLoopDisplayWidth = ({
236
- visualizationWidth,
237
- loopDisplay
238
- }) => {
239
- if (!shouldTileLoopDisplay(loopDisplay)) {
240
- return visualizationWidth;
241
- }
242
- return visualizationWidth / loopDisplay.numberOfTimes;
243
- };
244
-
245
- // src/components/slice-waveform-peaks.ts
246
- var sliceWaveformPeaks = ({
247
- durationInFrames,
248
- fps,
249
- peaks,
250
- playbackRate,
251
- startFrom
252
- }) => {
253
- if (peaks.length === 0) {
254
- return peaks;
255
- }
256
- const startTimeInSeconds = startFrom / fps;
257
- const durationInSeconds = durationInFrames / fps * playbackRate;
258
- const startPeakIndex = Math.floor(startTimeInSeconds * TARGET_SAMPLE_RATE);
259
- const endPeakIndex = Math.ceil((startTimeInSeconds + durationInSeconds) * TARGET_SAMPLE_RATE);
260
- return peaks.subarray(Math.max(0, startPeakIndex), Math.min(peaks.length, endPeakIndex));
261
- };
262
-
263
- // src/audio-waveform-worker.ts
264
- var canvas = null;
265
- var currentController = null;
266
- var latestRequestId = 0;
267
- var postError = (requestId, error) => {
268
- const message = error instanceof Error ? error.message : "Failed to render waveform";
269
- const payload = {
270
- type: "error",
271
- requestId,
272
- message
273
- };
274
- self.postMessage(payload);
275
- };
276
- var drawPartialWaveform = (message, peaks) => {
277
- if (!canvas) {
278
- return;
279
- }
280
- const portionPeaks = sliceWaveformPeaks({
281
- durationInFrames: shouldTileLoopDisplay(message.loopDisplay) ? message.loopDisplay.durationInFrames : message.durationInFrames,
282
- fps: message.fps,
283
- peaks,
284
- playbackRate: message.playbackRate,
285
- startFrom: message.startFrom
286
- });
287
- if (!shouldTileLoopDisplay(message.loopDisplay)) {
288
- drawBars(canvas, portionPeaks, "rgba(255, 255, 255, 0.6)", message.volume, message.width);
289
- return;
290
- }
291
- const loopWidth = getLoopDisplayWidth({
292
- visualizationWidth: message.width,
293
- loopDisplay: message.loopDisplay
294
- });
295
- const targetCanvas = new OffscreenCanvas(Math.max(1, Math.ceil(loopWidth)), message.height);
296
- drawBars(targetCanvas, portionPeaks, "rgba(255, 255, 255, 0.6)", message.volume, targetCanvas.width);
297
- const ctx = canvas.getContext("2d");
298
- if (!ctx) {
299
- throw new Error("Failed to get canvas context");
300
- }
301
- const pattern = ctx.createPattern(targetCanvas, "repeat-x");
302
- if (!pattern) {
303
- return;
304
- }
305
- pattern.setTransform(new DOMMatrix().scaleSelf(loopWidth / targetCanvas.width, 1));
306
- ctx.clearRect(0, 0, message.width, message.height);
307
- ctx.fillStyle = pattern;
308
- ctx.fillRect(0, 0, message.width, message.height);
309
- };
310
- var renderWaveform = async (message) => {
311
- if (!canvas) {
312
- postError(message.requestId, new Error("Waveform canvas not initialized"));
313
- return;
314
- }
315
- const controller = new AbortController;
316
- currentController?.abort();
317
- currentController = controller;
318
- latestRequestId = message.requestId;
319
- try {
320
- canvas.width = message.width;
321
- canvas.height = message.height;
322
- const peaks = await loadWaveformPeaks(message.src, controller.signal, {
323
- onProgress: ({ peaks: nextPeaks }) => {
324
- if (controller.signal.aborted || latestRequestId !== message.requestId) {
325
- return;
326
- }
327
- drawPartialWaveform(message, nextPeaks);
328
- }
329
- });
330
- if (controller.signal.aborted || latestRequestId !== message.requestId) {
331
- return;
332
- }
333
- drawPartialWaveform(message, peaks);
334
- } catch (error) {
335
- if (controller.signal.aborted || latestRequestId !== message.requestId) {
336
- return;
337
- }
338
- postError(message.requestId, error);
339
- }
340
- };
341
- self.addEventListener("message", (event) => {
342
- const message = event.data;
343
- if (message.type === "init") {
344
- canvas = message.canvas;
345
- return;
346
- }
347
- if (message.type === "dispose") {
348
- currentController?.abort();
349
- currentController = null;
350
- canvas = null;
351
- return;
352
- }
353
- renderWaveform(message);
354
- });