@remotion/motion-blur 4.0.539 → 4.0.541

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)));
@@ -44,11 +44,17 @@ const MotionBlurSample = ({ children, width, height, index, count, shutterInFram
44
44
  width,
45
45
  height,
46
46
  isolation: 'isolate',
47
+ // Copied-mode HtmlInCanvas hides the layout canvas, so each drawable
48
+ // sample must remain visible to retain its capture paint record.
49
+ // Issue: https://github.com/remotion-dev/remotion/issues/12656
50
+ // Test: https://github.com/remotion-dev/remotion/blob/5d2ff05db91c1e5a02fc3d01f359638e98807882/packages/it-tests/src/ssr/render-frames.test.ts#L77
51
+ visibility: 'visible',
47
52
  pointerEvents: isRepresentativeSample ? 'auto' : 'none',
48
53
  }, children: isRepresentativeSample ? (content) : ((0, jsx_runtime_1.jsx)(remotion_1.Internals.DisableSequenceRegistrationProvider, { children: content })) }));
49
54
  };
50
55
  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, }) => {
51
56
  const { durationInFrames: compositionDurationInFrames } = (0, remotion_1.useVideoConfig)();
57
+ const accumulationCanvasRef = (0, react_1.useRef)(null);
52
58
  if (!Number.isInteger(samples) || samples < 1 || samples > 64) {
53
59
  throw new TypeError(`"samples" must be an integer between 1 and 64, but got ${String(samples)}`);
54
60
  }
@@ -82,15 +88,32 @@ const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 1
82
88
  captureElements[0] !== element) {
83
89
  throw new Error('Motion blur samples are not ready to paint');
84
90
  }
85
- context.reset();
86
- context.globalCompositeOperation = 'lighter';
87
- context.globalAlpha = 1 / actualSamples;
91
+ if (accumulationCanvasRef.current === null ||
92
+ accumulationCanvasRef.current.width !== canvas.width ||
93
+ accumulationCanvasRef.current.height !== canvas.height) {
94
+ accumulationCanvasRef.current = new OffscreenCanvas(canvas.width, canvas.height);
95
+ }
96
+ const accumulationCanvas = accumulationCanvasRef.current;
97
+ const accumulationSettings = {
98
+ colorSpace: 'srgb',
99
+ colorType: 'float16',
100
+ };
101
+ const accumulationContext = accumulationCanvas.getContext('2d', accumulationSettings);
102
+ if (!accumulationContext) {
103
+ throw new Error('Failed to acquire 2D context for motion blur samples');
104
+ }
105
+ accumulationContext.reset();
106
+ accumulationContext.globalCompositeOperation = 'lighter';
107
+ accumulationContext.globalAlpha = 1 / actualSamples;
88
108
  for (const [index, sampleElement] of captureElements.entries()) {
89
109
  const image = index === 0
90
110
  ? elementImage
91
111
  : layoutCanvas.captureElementImage(sampleElement);
92
112
  try {
113
+ // ElementImage can only be drawn back to its originating canvas.
114
+ context.reset();
93
115
  context.drawElementImage(image, 0, 0);
116
+ accumulationContext.drawImage(canvas, 0, 0);
94
117
  }
95
118
  finally {
96
119
  if (index !== 0) {
@@ -98,6 +121,8 @@ const HtmlInCanvasMotionBlurInner = ({ children, width, height, shutterAngle = 1
98
121
  }
99
122
  }
100
123
  }
124
+ context.reset();
125
+ context.drawImage(accumulationCanvas, 0, 0);
101
126
  }, [actualSamples]);
102
127
  const passThrough = remotion_1.Internals.useHtmlInCanvasUnsupportedMessage() !== null;
103
128
  const sampleElements = Array.from({ length: passThrough ? 0 : actualSamples }, (_, index) => {
@@ -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,
@@ -122,6 +125,7 @@ var MotionBlurSample = ({
122
125
  width,
123
126
  height,
124
127
  isolation: "isolate",
128
+ visibility: "visible",
125
129
  pointerEvents: isRepresentativeSample ? "auto" : "none"
126
130
  },
127
131
  children: isRepresentativeSample ? content : /* @__PURE__ */ jsx2(Internals.DisableSequenceRegistrationProvider, {
@@ -152,6 +156,7 @@ var HtmlInCanvasMotionBlurInner = ({
152
156
  controls
153
157
  }) => {
154
158
  const { durationInFrames: compositionDurationInFrames } = useVideoConfig();
159
+ const accumulationCanvasRef = useRef(null);
155
160
  if (!Number.isInteger(samples) || samples < 1 || samples > 64) {
156
161
  throw new TypeError(`"samples" must be an integer between 1 and 64, but got ${String(samples)}`);
157
162
  }
@@ -180,19 +185,35 @@ var HtmlInCanvasMotionBlurInner = ({
180
185
  if (captureElements.length !== actualSamples || captureElements[0] !== element) {
181
186
  throw new Error("Motion blur samples are not ready to paint");
182
187
  }
183
- context.reset();
184
- context.globalCompositeOperation = "lighter";
185
- context.globalAlpha = 1 / actualSamples;
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;
186
203
  for (const [index, sampleElement] of captureElements.entries()) {
187
204
  const image = index === 0 ? elementImage : layoutCanvas.captureElementImage(sampleElement);
188
205
  try {
206
+ context.reset();
189
207
  context.drawElementImage(image, 0, 0);
208
+ accumulationContext.drawImage(canvas, 0, 0);
190
209
  } finally {
191
210
  if (index !== 0) {
192
211
  image.close();
193
212
  }
194
213
  }
195
214
  }
215
+ context.reset();
216
+ context.drawImage(accumulationCanvas, 0, 0);
196
217
  }, [actualSamples]);
197
218
  const passThrough = Internals.useHtmlInCanvasUnsupportedMessage() !== null;
198
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.539",
6
+ "version": "4.0.541",
7
7
  "description": "Motion blur effect for Remotion",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/remotion-dev/remotion/issues"
22
22
  },
23
23
  "dependencies": {
24
- "remotion": "4.0.539"
24
+ "remotion": "4.0.541"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": ">=16.8.0",
@@ -37,10 +37,10 @@
37
37
  }
38
38
  },
39
39
  "devDependencies": {
40
- "react": "19.2.3",
41
- "react-dom": "19.2.3",
42
- "remotion": "4.0.539",
43
- "@remotion/eslint-config-internal": "4.0.539",
40
+ "react": "19.3.1",
41
+ "react-dom": "19.3.1",
42
+ "remotion": "4.0.541",
43
+ "@remotion/eslint-config-internal": "4.0.541",
44
44
  "eslint": "9.19.0",
45
45
  "typescript": "7.1.0-beta"
46
46
  },