@remotion/media 4.0.356 → 4.0.358

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 (61) hide show
  1. package/dist/audio/audio-for-preview.d.ts +30 -0
  2. package/dist/audio/audio-for-preview.js +229 -0
  3. package/dist/audio/audio-for-rendering.js +35 -19
  4. package/dist/audio/audio.js +7 -49
  5. package/dist/audio/props.d.ts +8 -14
  6. package/dist/audio-extraction/audio-cache.d.ts +1 -1
  7. package/dist/audio-extraction/audio-cache.js +5 -1
  8. package/dist/audio-extraction/audio-iterator.d.ts +4 -1
  9. package/dist/audio-extraction/audio-iterator.js +22 -10
  10. package/dist/audio-extraction/audio-manager.d.ts +8 -37
  11. package/dist/audio-extraction/audio-manager.js +35 -8
  12. package/dist/audio-extraction/extract-audio.d.ts +9 -2
  13. package/dist/audio-extraction/extract-audio.js +29 -15
  14. package/dist/caches.d.ts +9 -44
  15. package/dist/convert-audiodata/combine-audiodata.js +2 -23
  16. package/dist/convert-audiodata/convert-audiodata.d.ts +1 -5
  17. package/dist/convert-audiodata/convert-audiodata.js +16 -24
  18. package/dist/esm/index.mjs +2864 -2173
  19. package/dist/extract-frame-and-audio.d.ts +6 -7
  20. package/dist/extract-frame-and-audio.js +28 -19
  21. package/dist/{get-sink-weak.d.ts → get-sink.d.ts} +1 -1
  22. package/dist/get-sink.js +15 -0
  23. package/dist/get-time-in-seconds.d.ts +11 -0
  24. package/dist/get-time-in-seconds.js +25 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/is-network-error.d.ts +6 -0
  28. package/dist/is-network-error.js +17 -0
  29. package/dist/render-timestamp-range.d.ts +1 -0
  30. package/dist/render-timestamp-range.js +9 -0
  31. package/dist/show-in-timeline.d.ts +8 -0
  32. package/dist/show-in-timeline.js +31 -0
  33. package/dist/use-media-in-timeline.d.ts +19 -0
  34. package/dist/use-media-in-timeline.js +103 -0
  35. package/dist/video/media-player.d.ts +34 -7
  36. package/dist/video/media-player.js +164 -63
  37. package/dist/video/props.d.ts +1 -0
  38. package/dist/video/video-for-preview.d.ts +17 -9
  39. package/dist/video/video-for-preview.js +138 -92
  40. package/dist/video/video-for-rendering.d.ts +3 -0
  41. package/dist/video/video-for-rendering.js +58 -25
  42. package/dist/video/video.js +6 -10
  43. package/dist/video-extraction/extract-frame-via-broadcast-channel.d.ts +18 -6
  44. package/dist/video-extraction/extract-frame-via-broadcast-channel.js +21 -7
  45. package/dist/video-extraction/extract-frame.d.ts +20 -2
  46. package/dist/video-extraction/extract-frame.js +41 -9
  47. package/dist/video-extraction/get-frames-since-keyframe.d.ts +5 -3
  48. package/dist/video-extraction/get-frames-since-keyframe.js +7 -4
  49. package/dist/video-extraction/keyframe-bank.d.ts +3 -2
  50. package/dist/video-extraction/keyframe-bank.js +32 -12
  51. package/dist/video-extraction/keyframe-manager.d.ts +3 -8
  52. package/dist/video-extraction/keyframe-manager.js +25 -10
  53. package/package.json +54 -54
  54. package/LICENSE.md +0 -49
  55. package/dist/convert-audiodata/apply-tonefrequency.d.ts +0 -2
  56. package/dist/convert-audiodata/apply-tonefrequency.js +0 -44
  57. package/dist/convert-audiodata/wsola.d.ts +0 -13
  58. package/dist/convert-audiodata/wsola.js +0 -197
  59. package/dist/get-sink-weak.js +0 -23
  60. package/dist/log.d.ts +0 -10
  61. package/dist/log.js +0 -33
package/LICENSE.md DELETED
@@ -1,49 +0,0 @@
1
- # Remotion License
2
-
3
- In Remotion 5.0, the license will slightly change. [View the changes here](https://github.com/remotion-dev/remotion/pull/3750).
4
-
5
- ---
6
-
7
- Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion to create videos for free (even commercial), while a company license is required for for-profit organizations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
8
-
9
- - [Free License](#free-license)
10
- - [Company License](#company-license)
11
-
12
- ## Free License
13
-
14
- Copyright © 2025 [Remotion](https://www.remotion.dev)
15
-
16
- ### Eligibility
17
-
18
- You are eligible to use Remotion for free if you are:
19
-
20
- - an individual
21
- - a for-profit organization with up to 3 employees
22
- - a non-profit or not-for-profit organization
23
- - evaluating whether Remotion is a good fit, and are not yet using it in a commercial way
24
-
25
- ### Allowed use cases
26
-
27
- Permission is hereby granted, free of charge, to any person eligible for the "Free License", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to Remotion.
28
-
29
- ### Disallowed use cases
30
-
31
- It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, or sublicensing your own derivate of Remotion.
32
-
33
- ### Warranty notice
34
-
35
- The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
36
-
37
- ### Support
38
-
39
- Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
40
-
41
- ## Company License
42
-
43
- You are required to obtain a Company License to use Remotion if you are not within the group of entities eligible for a Free License. This license will enable you to use Remotion for the allowed use cases specified in the Free License, and give you access to prioritized support (read the [Support Policy](https://www.remotion.dev/docs/support)).
44
-
45
- Visit [remotion.pro](https://www.remotion.pro/license) for pricing and to buy a license.
46
-
47
- ### FAQs
48
-
49
- Are you not sure whether you need a Company License because of an edge case? Here are some [frequently asked questions](https://www.remotion.pro/faq).
@@ -1,2 +0,0 @@
1
- import { type PcmS16AudioData } from './convert-audiodata';
2
- export declare const applyToneFrequency: (audioData: PcmS16AudioData, toneFrequency: number) => PcmS16AudioData;
@@ -1,44 +0,0 @@
1
- import { FORMAT } from './convert-audiodata';
2
- import { resampleAudioData, TARGET_SAMPLE_RATE } from './resample-audiodata';
3
- import { wsolaInt16Interleaved } from './wsola';
4
- export const applyToneFrequency = (audioData, toneFrequency) => {
5
- // In FFmpeg, we apply toneFrequency as follows:
6
- // `asetrate=${DEFAULT_SAMPLE_RATE}*${toneFrequency},aresample=${DEFAULT_SAMPLE_RATE},atempo=1/${toneFrequency}`
7
- // So there are 2 steps:
8
- // 1. Change the assumed sample rate
9
- // 2. Resample to 48Khz
10
- // 3. Apply playback rate
11
- const step1 = {
12
- ...audioData,
13
- sampleRate: audioData.sampleRate * toneFrequency,
14
- };
15
- const newNumberOfFrames = Math.round(audioData.numberOfFrames * (TARGET_SAMPLE_RATE / step1.sampleRate));
16
- const step2Data = new Int16Array(newNumberOfFrames * audioData.numberOfChannels);
17
- const chunkSize = audioData.numberOfFrames / newNumberOfFrames;
18
- resampleAudioData({
19
- srcNumberOfChannels: step1.numberOfChannels,
20
- sourceChannels: step1.data,
21
- destination: step2Data,
22
- targetFrames: newNumberOfFrames,
23
- chunkSize,
24
- });
25
- const step2AudioData = {
26
- data: step2Data,
27
- format: FORMAT,
28
- numberOfChannels: step1.numberOfChannels,
29
- numberOfFrames: newNumberOfFrames,
30
- sampleRate: TARGET_SAMPLE_RATE,
31
- timestamp: audioData.timestamp,
32
- };
33
- const step3Data = wsolaInt16Interleaved(step2AudioData.data, step2AudioData.numberOfChannels, toneFrequency);
34
- // Target per-channel length and interleave
35
- const targetPerChan = Math.max(1, Math.round(step2AudioData.numberOfFrames * toneFrequency));
36
- const targetTotal = targetPerChan * step2AudioData.numberOfChannels;
37
- return {
38
- data: step3Data,
39
- numberOfChannels: step2AudioData.numberOfChannels,
40
- numberOfFrames: targetTotal,
41
- sampleRate: TARGET_SAMPLE_RATE,
42
- timestamp: audioData.timestamp,
43
- };
44
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * WSOLA time-scale modification for interleaved Int16 PCM (multi-channel).
3
- * - Preserves pitch approximately while changing tempo by factor f.
4
- * - Works for N interleaved channels.
5
- * - Mitigates head/tail fade-out via overlap-weight normalization and boundary reinforcement.
6
- *
7
- * @param input Interleaved Int16 PCM (e.g., LRLRLR... for stereo)
8
- * @param channels Number of channels (>=1)
9
- * @param f Tempo factor: >1 = faster/shorter, <1 = slower/longer
10
- * @param opts Optional tuning parameters
11
- * @returns Interleaved Int16Array with length ≈ round(input.length * f)
12
- */
13
- export declare function wsolaInt16Interleaved(input: Int16Array, channels: number, f: number): Int16Array;
@@ -1,197 +0,0 @@
1
- function clamp16(x) {
2
- const y = Math.round(x);
3
- return y < -32768 ? -32768 : y > 32767 ? 32767 : y;
4
- }
5
- /**
6
- * WSOLA time-scale modification for interleaved Int16 PCM (multi-channel).
7
- * - Preserves pitch approximately while changing tempo by factor f.
8
- * - Works for N interleaved channels.
9
- * - Mitigates head/tail fade-out via overlap-weight normalization and boundary reinforcement.
10
- *
11
- * @param input Interleaved Int16 PCM (e.g., LRLRLR... for stereo)
12
- * @param channels Number of channels (>=1)
13
- * @param f Tempo factor: >1 = faster/shorter, <1 = slower/longer
14
- * @param opts Optional tuning parameters
15
- * @returns Interleaved Int16Array with length ≈ round(input.length * f)
16
- */
17
- export function wsolaInt16Interleaved(input, channels, f) {
18
- if (!Number.isFinite(f) || f <= 0)
19
- throw new Error('f must be a positive finite number');
20
- if (!Number.isInteger(channels) || channels <= 0)
21
- throw new Error('channels must be a positive integer');
22
- const n = input.length;
23
- if (n === 0)
24
- return new Int16Array(0);
25
- if (n % channels !== 0)
26
- throw new Error('input length must be a multiple of channels');
27
- // Parameters and sensible defaults
28
- const sampleRate = 48000;
29
- const frameMs = 30; // 20–40 ms typical
30
- const overlapRatio = 0.5;
31
- const searchMs = 15; // +/- 8 ms local search
32
- const winKind = 'hann';
33
- const headReinf = 3;
34
- const tailReinf = 3;
35
- // Work per-channel
36
- const samplesPerChannel = (n / channels) | 0;
37
- // Frame and hop sizing
38
- const frameSize = Math.max(128, Math.floor((sampleRate * frameMs) / 1000));
39
- const overlap = Math.floor(frameSize * overlapRatio);
40
- const anaHop = Math.max(1, frameSize - overlap);
41
- const synHop = Math.max(1, Math.round(anaHop * f));
42
- // Search radius in samples
43
- const searchRadius = Math.max(0, Math.floor((sampleRate * searchMs) / 1000));
44
- // Window
45
- const win = new Float32Array(frameSize);
46
- for (let i = 0; i < frameSize; i++) {
47
- const x = (Math.PI * 2 * i) / (frameSize - 1);
48
- win[i] =
49
- winKind === 'hann' ? 0.5 * (1 - Math.cos(x)) : 0.54 - 0.46 * Math.cos(x); // Hamming
50
- }
51
- // Estimate output length per channel and allocate with extra headroom
52
- const estFrames = Math.max(1, Math.ceil(Math.max(0, samplesPerChannel - frameSize) / anaHop) + 1);
53
- const estLen = Math.max(0, frameSize + synHop * (estFrames - 1));
54
- const extraHead = frameSize * (headReinf + 1);
55
- const extraTail = frameSize * (tailReinf + 2);
56
- const outLenAlloc = estLen + searchRadius + extraHead + extraTail;
57
- const out = Array.from({ length: channels }, () => new Float32Array(outLenAlloc));
58
- const outWeight = new Float32Array(outLenAlloc);
59
- // Temporary buffers
60
- const chanFrames = Array.from({ length: channels }, () => new Float32Array(frameSize));
61
- const guideFrame = new Float32Array(frameSize);
62
- // Helpers
63
- function readChannelFrame(chan, start, dst) {
64
- let srcIndex = start * channels + chan;
65
- for (let i = 0; i < frameSize; i++) {
66
- const pos = start + i;
67
- dst[i] = pos >= 0 && pos < samplesPerChannel ? input[srcIndex] : 0;
68
- srcIndex += channels;
69
- }
70
- }
71
- function readGuideFrame(start) {
72
- for (let i = 0; i < frameSize; i++) {
73
- const pos = start + i;
74
- if (pos >= 0 && pos < samplesPerChannel) {
75
- let sum = 0;
76
- const base = pos * channels;
77
- for (let c = 0; c < channels; c++)
78
- sum += input[base + c];
79
- guideFrame[i] = sum / channels;
80
- }
81
- else {
82
- guideFrame[i] = 0;
83
- }
84
- }
85
- }
86
- // Find best local alignment around outPos using normalized cross-correlation
87
- function bestAlignment(outPoss) {
88
- let bestShift = 0;
89
- let bestScore = -Infinity;
90
- for (let shift = -searchRadius; shift <= searchRadius; shift++) {
91
- const pos = outPoss + shift - overlap;
92
- let score = 0;
93
- let normA = 0;
94
- let normB = 0;
95
- for (let i = 0; i < overlap; i++) {
96
- const idx = pos + i;
97
- const outVal = idx >= 0 && idx < outLenAlloc ? out[0][idx] : 0; // channel 0 proxy
98
- const frmVal = guideFrame[i];
99
- score += outVal * frmVal;
100
- normA += outVal * outVal;
101
- normB += frmVal * frmVal;
102
- }
103
- const denom = Math.sqrt((normA || 1e-9) * (normB || 1e-9));
104
- const corr = score / denom;
105
- if (corr > bestScore) {
106
- bestScore = corr;
107
- bestShift = shift;
108
- }
109
- }
110
- return bestShift;
111
- }
112
- // Overlap-add a frame for all channels at writeStart with windowing
113
- function olaAllChannels(writeStart) {
114
- for (let c = 0; c < channels; c++) {
115
- for (let i = 0; i < frameSize; i++) {
116
- const idx = writeStart + i;
117
- if (idx >= 0 && idx < outLenAlloc) {
118
- const w = win[i];
119
- out[c][idx] += chanFrames[c][i] * w;
120
- if (c === 0)
121
- outWeight[idx] += w; // track weights once
122
- }
123
- }
124
- }
125
- }
126
- // 1) Seed: place the first frame at t=0
127
- readGuideFrame(0);
128
- for (let c = 0; c < channels; c++)
129
- readChannelFrame(c, 0, chanFrames[c]);
130
- olaAllChannels(0);
131
- // 2) Head reinforcement: place extra frames whose writeStart <= 0
132
- for (let h = 0; h < headReinf; h++) {
133
- // Option 1: reuse the first analysis position to strengthen early region
134
- const headIn = Math.min(anaHop * h, Math.max(0, samplesPerChannel - frameSize));
135
- readGuideFrame(headIn);
136
- for (let c = 0; c < channels; c++)
137
- readChannelFrame(c, headIn, chanFrames[c]);
138
- // Align around outPos=0 so we bias writeStart near/before 0
139
- const shift = bestAlignment(0);
140
- const writeStart = shift - overlap; // likely negative; ok, we clamp on write
141
- olaAllChannels(writeStart);
142
- }
143
- // 3) Main WSOLA loop
144
- let inPos = anaHop; // next analysis position (we already seeded at 0)
145
- let outPos = synHop; // next synthesis position
146
- while (inPos < samplesPerChannel - 1) {
147
- readGuideFrame(inPos);
148
- for (let c = 0; c < channels; c++)
149
- readChannelFrame(c, inPos, chanFrames[c]);
150
- const shift = bestAlignment(outPos);
151
- const writeStart = outPos + shift - overlap;
152
- olaAllChannels(writeStart);
153
- inPos += anaHop;
154
- outPos += synHop;
155
- // Safety: if we're very close to capacity, break to handle tail separately
156
- if (outPos > outLenAlloc - (frameSize + searchRadius + 8))
157
- break;
158
- }
159
- // 4) Tail reinforcement: ensure the end gets full coverage
160
- // Place a few extra frames around the last outPos using the last available input frames.
161
- for (let t = 0; t < tailReinf; t++) {
162
- const tailIn = Math.max(0, Math.min(samplesPerChannel - frameSize, inPos - anaHop * t));
163
- readGuideFrame(tailIn);
164
- for (let c = 0; c < channels; c++)
165
- readChannelFrame(c, tailIn, chanFrames[c]);
166
- const shift = bestAlignment(outPos);
167
- const writeStart = outPos + shift - overlap;
168
- olaAllChannels(writeStart);
169
- outPos += synHop;
170
- }
171
- // 5) Normalize by accumulated weights BEFORE trimming
172
- for (let i = 0; i < outLenAlloc; i++) {
173
- const w = outWeight[i];
174
- if (w > 1e-9) {
175
- const inv = 1 / w;
176
- for (let c = 0; c < channels; c++)
177
- out[c][i] *= inv;
178
- }
179
- else {
180
- for (let c = 0; c < channels; c++)
181
- out[c][i] = 0;
182
- }
183
- }
184
- // 6) Produce final interleaved Int16Array with length ≈ round(n * f)
185
- const targetPerChan = Math.max(1, Math.round(samplesPerChannel * f));
186
- const targetTotal = targetPerChan * channels;
187
- const result = new Int16Array(targetTotal);
188
- // Interleave and clamp/round
189
- for (let i = 0; i < targetPerChan; i++) {
190
- for (let c = 0; c < channels; c++) {
191
- const v = i < out[c].length ? out[c][i] : 0;
192
- const y = clamp16(v);
193
- result[i * channels + c] = y;
194
- }
195
- }
196
- return result;
197
- }
@@ -1,23 +0,0 @@
1
- import { Internals } from 'remotion';
2
- import { getSinks } from './video-extraction/get-frames-since-keyframe';
3
- export const sinkPromises = {};
4
- export const getSinkWeak = async (src, logLevel) => {
5
- let promise = sinkPromises[src];
6
- if (!promise) {
7
- promise = getSinks(src);
8
- sinkPromises[src] = promise;
9
- }
10
- let awaited = await promise;
11
- let deferredValue = awaited.deref();
12
- if (!deferredValue) {
13
- Internals.Log.verbose({
14
- logLevel,
15
- tag: '@remotion/media',
16
- }, `Sink for ${src} was garbage collected, creating new sink`);
17
- promise = getSinks(src);
18
- sinkPromises[src] = promise;
19
- awaited = await promise;
20
- deferredValue = awaited.deref();
21
- }
22
- return deferredValue;
23
- };
package/dist/log.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare const logLevels: readonly ["trace", "verbose", "info", "warn", "error"];
2
- export type LogLevel = (typeof logLevels)[number];
3
- export declare const isEqualOrBelowLogLevel: (currentLevel: LogLevel, level: LogLevel) => boolean;
4
- export declare const Log: {
5
- trace: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
6
- verbose: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
7
- info: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
8
- warn: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
9
- error: (message?: any, ...optionalParams: any[]) => void;
10
- };
package/dist/log.js DELETED
@@ -1,33 +0,0 @@
1
- /* eslint-disable no-console */
2
- export const logLevels = ['trace', 'verbose', 'info', 'warn', 'error'];
3
- const getNumberForLogLevel = (level) => {
4
- return logLevels.indexOf(level);
5
- };
6
- export const isEqualOrBelowLogLevel = (currentLevel, level) => {
7
- return getNumberForLogLevel(currentLevel) <= getNumberForLogLevel(level);
8
- };
9
- export const Log = {
10
- trace: (logLevel, ...args) => {
11
- if (isEqualOrBelowLogLevel(logLevel, 'trace')) {
12
- return console.log(...args);
13
- }
14
- },
15
- verbose: (logLevel, ...args) => {
16
- if (isEqualOrBelowLogLevel(logLevel, 'verbose')) {
17
- return console.log(...args);
18
- }
19
- },
20
- info: (logLevel, ...args) => {
21
- if (isEqualOrBelowLogLevel(logLevel, 'info')) {
22
- return console.log(...args);
23
- }
24
- },
25
- warn: (logLevel, ...args) => {
26
- if (isEqualOrBelowLogLevel(logLevel, 'warn')) {
27
- return console.warn(...args);
28
- }
29
- },
30
- error: (...args) => {
31
- return console.error(...args);
32
- },
33
- };