@remotion/motion-blur 4.0.540 → 4.0.542
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.
|
@@ -10,6 +10,11 @@ const remotion_1 = require("remotion");
|
|
|
10
10
|
*/
|
|
11
11
|
const getNumberOfSamples = ({ shutterFraction, samples, currentFrame, }) => {
|
|
12
12
|
const maxOffset = shutterFraction * samples;
|
|
13
|
+
// A shutter angle of 0 means no blur at all, which makes maxOffset 0 and
|
|
14
|
+
// the division below produce NaN. Render a single sample instead.
|
|
15
|
+
if (maxOffset === 0) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
13
18
|
const maxTimeReverse = currentFrame - maxOffset;
|
|
14
19
|
const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
|
|
15
20
|
return Math.max(1, Math.round(Math.min(factor * samples, samples)));
|
|
@@ -6,7 +6,6 @@ const react_1 = require("react");
|
|
|
6
6
|
const remotion_1 = require("remotion");
|
|
7
7
|
const htmlInCanvasMotionBlurSchema = {
|
|
8
8
|
...remotion_1.Interactive.baseSchema,
|
|
9
|
-
...remotion_1.Interactive.premountSchema,
|
|
10
9
|
shutterAngle: {
|
|
11
10
|
type: 'number',
|
|
12
11
|
min: 0,
|
|
@@ -54,6 +53,8 @@ const MotionBlurSample = ({ children, width, height, index, count, shutterInFram
|
|
|
54
53
|
};
|
|
55
54
|
const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 180, samples = 8, disabled = false, from, durationInFrames, trimBefore, playbackRate, loop, freeze, hidden, name, premountFor, postmountFor, showInTimeline, styleWhilePremounted, styleWhilePostmounted, controls, }) => {
|
|
56
55
|
const { durationInFrames: compositionDurationInFrames } = (0, remotion_1.useVideoConfig)();
|
|
56
|
+
const videoEnabled = remotion_1.Internals.useVideoEnabled();
|
|
57
|
+
const accumulationCanvasRef = (0, react_1.useRef)(null);
|
|
57
58
|
if (!Number.isInteger(samples) || samples < 1 || samples > 64) {
|
|
58
59
|
throw new TypeError(`"samples" must be an integer between 1 and 64, but got ${String(samples)}`);
|
|
59
60
|
}
|
|
@@ -64,7 +65,8 @@ const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 1
|
|
|
64
65
|
throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${String(shutterAngle)}`);
|
|
65
66
|
}
|
|
66
67
|
// Keep the first sample mounted when blur is disabled so the canvas stays visible.
|
|
67
|
-
|
|
68
|
+
// Audio-only frames mount the children once so their audio is captured once.
|
|
69
|
+
const actualSamples = disabled || shutterAngle === 0 || !videoEnabled ? 1 : samples;
|
|
68
70
|
const shutterInFrames = (shutterAngle / 360) * (playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1);
|
|
69
71
|
const firstFrame = trimBefore !== null && trimBefore !== void 0 ? trimBefore : 0;
|
|
70
72
|
const visibleDuration = Math.max(0, Math.min(remotion_1.Internals.resolveSequenceDuration({
|
|
@@ -87,15 +89,32 @@ const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 1
|
|
|
87
89
|
captureElements[0] !== element) {
|
|
88
90
|
throw new Error('Motion blur samples are not ready to paint');
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
if (accumulationCanvasRef.current === null ||
|
|
93
|
+
accumulationCanvasRef.current.width !== canvas.width ||
|
|
94
|
+
accumulationCanvasRef.current.height !== canvas.height) {
|
|
95
|
+
accumulationCanvasRef.current = new OffscreenCanvas(canvas.width, canvas.height);
|
|
96
|
+
}
|
|
97
|
+
const accumulationCanvas = accumulationCanvasRef.current;
|
|
98
|
+
const accumulationSettings = {
|
|
99
|
+
colorSpace: 'srgb',
|
|
100
|
+
colorType: 'float16',
|
|
101
|
+
};
|
|
102
|
+
const accumulationContext = accumulationCanvas.getContext('2d', accumulationSettings);
|
|
103
|
+
if (!accumulationContext) {
|
|
104
|
+
throw new Error('Failed to acquire 2D context for motion blur samples');
|
|
105
|
+
}
|
|
106
|
+
accumulationContext.reset();
|
|
107
|
+
accumulationContext.globalCompositeOperation = 'lighter';
|
|
108
|
+
accumulationContext.globalAlpha = 1 / actualSamples;
|
|
93
109
|
for (const [index, sampleElement] of captureElements.entries()) {
|
|
94
110
|
const image = index === 0
|
|
95
111
|
? elementImage
|
|
96
112
|
: layoutCanvas.captureElementImage(sampleElement);
|
|
97
113
|
try {
|
|
114
|
+
// ElementImage can only be drawn back to its originating canvas.
|
|
115
|
+
context.reset();
|
|
98
116
|
context.drawElementImage(image, 0, 0);
|
|
117
|
+
accumulationContext.drawImage(canvas, 0, 0);
|
|
99
118
|
}
|
|
100
119
|
finally {
|
|
101
120
|
if (index !== 0) {
|
|
@@ -103,6 +122,8 @@ const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 1
|
|
|
103
122
|
}
|
|
104
123
|
}
|
|
105
124
|
}
|
|
125
|
+
context.reset();
|
|
126
|
+
context.drawImage(accumulationCanvas, 0, 0);
|
|
106
127
|
}, [actualSamples]);
|
|
107
128
|
const passThrough = remotion_1.Internals.useHtmlInCanvasUnsupportedMessage() !== null;
|
|
108
129
|
const sampleElements = Array.from({ length: passThrough ? 0 : actualSamples }, (_, index) => {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -7,6 +7,9 @@ var getNumberOfSamples = ({
|
|
|
7
7
|
currentFrame
|
|
8
8
|
}) => {
|
|
9
9
|
const maxOffset = shutterFraction * samples;
|
|
10
|
+
if (maxOffset === 0) {
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
10
13
|
const maxTimeReverse = currentFrame - maxOffset;
|
|
11
14
|
const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
|
|
12
15
|
return Math.max(1, Math.round(Math.min(factor * samples, samples)));
|
|
@@ -57,7 +60,7 @@ var CameraMotionBlur = ({
|
|
|
57
60
|
});
|
|
58
61
|
};
|
|
59
62
|
// src/HtmlInCanvasMotionBlur.tsx
|
|
60
|
-
import { useCallback } from "react";
|
|
63
|
+
import { useCallback, useRef } from "react";
|
|
61
64
|
import {
|
|
62
65
|
Freeze as Freeze2,
|
|
63
66
|
HtmlInCanvas,
|
|
@@ -69,7 +72,6 @@ import {
|
|
|
69
72
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
70
73
|
var htmlInCanvasMotionBlurSchema = {
|
|
71
74
|
...Interactive.baseSchema,
|
|
72
|
-
...Interactive.premountSchema,
|
|
73
75
|
shutterAngle: {
|
|
74
76
|
type: "number",
|
|
75
77
|
min: 0,
|
|
@@ -153,13 +155,15 @@ var HtmlInCanvasMotionBlurInner = ({
|
|
|
153
155
|
controls
|
|
154
156
|
}) => {
|
|
155
157
|
const { durationInFrames: compositionDurationInFrames } = useVideoConfig();
|
|
158
|
+
const videoEnabled = Internals.useVideoEnabled();
|
|
159
|
+
const accumulationCanvasRef = useRef(null);
|
|
156
160
|
if (!Number.isInteger(samples) || samples < 1 || samples > 64) {
|
|
157
161
|
throw new TypeError(`"samples" must be an integer between 1 and 64, but got ${String(samples)}`);
|
|
158
162
|
}
|
|
159
163
|
if (typeof shutterAngle !== "number" || !Number.isFinite(shutterAngle) || shutterAngle < 0 || shutterAngle > 360) {
|
|
160
164
|
throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${String(shutterAngle)}`);
|
|
161
165
|
}
|
|
162
|
-
const actualSamples = disabled || shutterAngle === 0 ? 1 : samples;
|
|
166
|
+
const actualSamples = disabled || shutterAngle === 0 || !videoEnabled ? 1 : samples;
|
|
163
167
|
const shutterInFrames = shutterAngle / 360 * (playbackRate ?? 1);
|
|
164
168
|
const firstFrame = trimBefore ?? 0;
|
|
165
169
|
const visibleDuration = Math.max(0, Math.min(Internals.resolveSequenceDuration({
|
|
@@ -181,19 +185,35 @@ var HtmlInCanvasMotionBlurInner = ({
|
|
|
181
185
|
if (captureElements.length !== actualSamples || captureElements[0] !== element) {
|
|
182
186
|
throw new Error("Motion blur samples are not ready to paint");
|
|
183
187
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
if (accumulationCanvasRef.current === null || accumulationCanvasRef.current.width !== canvas.width || accumulationCanvasRef.current.height !== canvas.height) {
|
|
189
|
+
accumulationCanvasRef.current = new OffscreenCanvas(canvas.width, canvas.height);
|
|
190
|
+
}
|
|
191
|
+
const accumulationCanvas = accumulationCanvasRef.current;
|
|
192
|
+
const accumulationSettings = {
|
|
193
|
+
colorSpace: "srgb",
|
|
194
|
+
colorType: "float16"
|
|
195
|
+
};
|
|
196
|
+
const accumulationContext = accumulationCanvas.getContext("2d", accumulationSettings);
|
|
197
|
+
if (!accumulationContext) {
|
|
198
|
+
throw new Error("Failed to acquire 2D context for motion blur samples");
|
|
199
|
+
}
|
|
200
|
+
accumulationContext.reset();
|
|
201
|
+
accumulationContext.globalCompositeOperation = "lighter";
|
|
202
|
+
accumulationContext.globalAlpha = 1 / actualSamples;
|
|
187
203
|
for (const [index, sampleElement] of captureElements.entries()) {
|
|
188
204
|
const image = index === 0 ? elementImage : layoutCanvas.captureElementImage(sampleElement);
|
|
189
205
|
try {
|
|
206
|
+
context.reset();
|
|
190
207
|
context.drawElementImage(image, 0, 0);
|
|
208
|
+
accumulationContext.drawImage(canvas, 0, 0);
|
|
191
209
|
} finally {
|
|
192
210
|
if (index !== 0) {
|
|
193
211
|
image.close();
|
|
194
212
|
}
|
|
195
213
|
}
|
|
196
214
|
}
|
|
215
|
+
context.reset();
|
|
216
|
+
context.drawImage(accumulationCanvas, 0, 0);
|
|
197
217
|
}, [actualSamples]);
|
|
198
218
|
const passThrough = Internals.useHtmlInCanvasUnsupportedMessage() !== null;
|
|
199
219
|
const sampleElements = Array.from({ length: passThrough ? 0 : actualSamples }, (_, index) => {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/motion-blur"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/motion-blur",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.542",
|
|
7
7
|
"description": "Motion blur effect for Remotion",
|
|
8
8
|
"main": "dist/cjs/index.js",
|
|
9
9
|
"types": "dist/cjs/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"formatting": "oxfmt src --check",
|
|
13
13
|
"format": "oxfmt src",
|
|
14
14
|
"lint": "eslint src",
|
|
15
|
-
"make": "
|
|
15
|
+
"make": "node ../.monorepo/tsrs.cjs -d && bun --env-file=../.env.bundle bundle.ts"
|
|
16
16
|
},
|
|
17
17
|
"author": "Matt McGillivray, Ilija Boshkov <ilija@codechem.com>, Jonny Burger <jonny@remotion.dev>",
|
|
18
18
|
"contributors": [],
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"remotion": "4.0.
|
|
24
|
+
"remotion": "4.0.542"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.8.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"react": "19.3.1",
|
|
41
41
|
"react-dom": "19.3.1",
|
|
42
|
-
"remotion": "4.0.
|
|
43
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
42
|
+
"remotion": "4.0.542",
|
|
43
|
+
"@remotion/eslint-config-internal": "4.0.542",
|
|
44
44
|
"eslint": "9.19.0",
|
|
45
45
|
"typescript": "7.1.0-beta"
|
|
46
46
|
},
|