@remotion/motion-blur 3.3.83 → 3.3.86

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.
@@ -3,6 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CameraMotionBlur = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const remotion_1 = require("remotion");
6
+ /**
7
+ * If the current frame is 0, then it is rendered with low opacity,
8
+ * and the trailing elements have frame numbers -1, -2, -3, -4, etc.
9
+ * To fix this, we instead reduce the number of samples to not go into negative territory.
10
+ */
11
+ const getNumberOfSamples = ({ shutterFraction, samples, currentFrame, }) => {
12
+ const maxOffset = shutterFraction * samples;
13
+ const maxTimeReverse = currentFrame - maxOffset;
14
+ const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
15
+ return Math.max(1, Math.round(Math.min(factor * samples, samples)));
16
+ };
6
17
  /**
7
18
  * @description Produces natural looking motion blur similar to what would be produced by a film camera.
8
19
  * @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
@@ -29,12 +40,17 @@ const CameraMotionBlur = ({ children, shutterAngle = 180, samples = 10, }) => {
29
40
  throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${JSON.stringify(shutterAngle)}`);
30
41
  }
31
42
  const shutterFraction = shutterAngle / 360;
32
- return ((0, jsx_runtime_1.jsx)(remotion_1.AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(samples).fill(true).map((_, i) => {
43
+ const actualSamples = getNumberOfSamples({
44
+ currentFrame,
45
+ samples,
46
+ shutterFraction,
47
+ });
48
+ return ((0, jsx_runtime_1.jsx)(remotion_1.AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(actualSamples).fill(true).map((_, i) => {
33
49
  const sample = i + 1;
34
- const sampleFrameOffset = shutterFraction * (sample / samples);
50
+ const sampleFrameOffset = shutterFraction * (sample / actualSamples);
35
51
  return ((0, jsx_runtime_1.jsx)(remotion_1.AbsoluteFill, { style: {
36
52
  mixBlendMode: 'plus-lighter',
37
- filter: `opacity(${1 / samples})`,
53
+ filter: `opacity(${1 / actualSamples})`,
38
54
  }, children: (0, jsx_runtime_1.jsx)(remotion_1.Freeze, { frame: currentFrame - sampleFrameOffset, children: children }) }, `frame-${i.toString()}`));
39
55
  }) }));
40
56
  };
@@ -1,6 +1,17 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { useCurrentFrame, AbsoluteFill, Freeze } from 'remotion';
3
3
 
4
+ /**
5
+ * If the current frame is 0, then it is rendered with low opacity,
6
+ * and the trailing elements have frame numbers -1, -2, -3, -4, etc.
7
+ * To fix this, we instead reduce the number of samples to not go into negative territory.
8
+ */
9
+ const getNumberOfSamples = ({ shutterFraction, samples, currentFrame, }) => {
10
+ const maxOffset = shutterFraction * samples;
11
+ const maxTimeReverse = currentFrame - maxOffset;
12
+ const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
13
+ return Math.max(1, Math.round(Math.min(factor * samples, samples)));
14
+ };
4
15
  /**
5
16
  * @description Produces natural looking motion blur similar to what would be produced by a film camera.
6
17
  * @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
@@ -27,12 +38,17 @@ const CameraMotionBlur = ({ children, shutterAngle = 180, samples = 10, }) => {
27
38
  throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${JSON.stringify(shutterAngle)}`);
28
39
  }
29
40
  const shutterFraction = shutterAngle / 360;
30
- return (jsx(AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(samples).fill(true).map((_, i) => {
41
+ const actualSamples = getNumberOfSamples({
42
+ currentFrame,
43
+ samples,
44
+ shutterFraction,
45
+ });
46
+ return (jsx(AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(actualSamples).fill(true).map((_, i) => {
31
47
  const sample = i + 1;
32
- const sampleFrameOffset = shutterFraction * (sample / samples);
48
+ const sampleFrameOffset = shutterFraction * (sample / actualSamples);
33
49
  return (jsx(AbsoluteFill, { style: {
34
50
  mixBlendMode: 'plus-lighter',
35
- filter: `opacity(${1 / samples})`,
51
+ filter: `opacity(${1 / actualSamples})`,
36
52
  }, children: jsx(Freeze, { frame: currentFrame - sampleFrameOffset, children: children }) }, `frame-${i.toString()}`));
37
53
  }) }));
38
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/motion-blur",
3
- "version": "3.3.83",
3
+ "version": "3.3.86",
4
4
  "description": "Motion blur effect for Remotion",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "url": "https://github.com/remotion-dev/remotion/issues"
17
17
  },
18
18
  "dependencies": {
19
- "remotion": "3.3.83"
19
+ "remotion": "3.3.86"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react": ">=16.8.0",
@@ -40,7 +40,7 @@
40
40
  "prettier-plugin-organize-imports": "^2.3.4",
41
41
  "react": "18.0.0",
42
42
  "react-dom": "18.0.0",
43
- "remotion": "3.3.83",
43
+ "remotion": "3.3.86",
44
44
  "rollup": "^2.70.1",
45
45
  "typescript": "^4.7.0"
46
46
  },