remotion 3.3.91 → 3.3.92

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.
@@ -4,6 +4,7 @@ import type { SpringConfig } from './spring-utils.js';
4
4
  * @see [Documentation](https://www.remotion.dev/docs/spring)
5
5
  * @param {number} frame The current time value. Most of the time you want to pass in the return value of useCurrentFrame.
6
6
  * @param {number} fps The framerate at which the animation runs. Pass in the value obtained by `useVideoConfig()`.
7
+ * @param {?boolean} reverse Whether the animation plays in reverse or not. Default `false`.
7
8
  * @param {?Object} config optional object that allows you to customize the physical properties of the animation.
8
9
  * @param {number} [config.mass=1] The weight of the spring. If you reduce the mass, the animation becomes faster!
9
10
  * @param {number} [config.damping=10] How hard the animation decelerates.
@@ -15,7 +16,7 @@ import type { SpringConfig } from './spring-utils.js';
15
16
  * @param {?number} [config.durationThreshold] How close to the end the animation is considered to be done. Default `0.005`
16
17
  * @param {?number} [config.delay] Delay the animation for this amount of frames. Default `0`
17
18
  */
18
- export declare function spring({ frame: passedFrame, fps, config, from, to, durationInFrames, durationRestThreshold, delay, }: {
19
+ export declare function spring({ frame: passedFrame, fps, config, from, to, durationInFrames: passedDurationInFrames, durationRestThreshold, delay, reverse, }: {
19
20
  frame: number;
20
21
  fps: number;
21
22
  config?: Partial<SpringConfig>;
@@ -24,6 +25,7 @@ export declare function spring({ frame: passedFrame, fps, config, from, to, dura
24
25
  durationInFrames?: number;
25
26
  durationRestThreshold?: number;
26
27
  delay?: number;
28
+ reverse?: boolean;
27
29
  }): number;
28
30
  export { measureSpring } from './measure-spring.js';
29
31
  export { SpringConfig } from './spring-utils.js';
@@ -11,6 +11,7 @@ const spring_utils_js_1 = require("./spring-utils.js");
11
11
  * @see [Documentation](https://www.remotion.dev/docs/spring)
12
12
  * @param {number} frame The current time value. Most of the time you want to pass in the return value of useCurrentFrame.
13
13
  * @param {number} fps The framerate at which the animation runs. Pass in the value obtained by `useVideoConfig()`.
14
+ * @param {?boolean} reverse Whether the animation plays in reverse or not. Default `false`.
14
15
  * @param {?Object} config optional object that allows you to customize the physical properties of the animation.
15
16
  * @param {number} [config.mass=1] The weight of the spring. If you reduce the mass, the animation becomes faster!
16
17
  * @param {number} [config.damping=10] How hard the animation decelerates.
@@ -22,29 +23,42 @@ const spring_utils_js_1 = require("./spring-utils.js");
22
23
  * @param {?number} [config.durationThreshold] How close to the end the animation is considered to be done. Default `0.005`
23
24
  * @param {?number} [config.delay] Delay the animation for this amount of frames. Default `0`
24
25
  */
25
- function spring({ frame: passedFrame, fps, config = {}, from = 0, to = 1, durationInFrames, durationRestThreshold, delay = 0, }) {
26
- (0, validation_spring_duration_js_1.validateSpringDuration)(durationInFrames);
26
+ function spring({ frame: passedFrame, fps, config = {}, from = 0, to = 1, durationInFrames: passedDurationInFrames, durationRestThreshold, delay = 0, reverse = false, }) {
27
+ (0, validation_spring_duration_js_1.validateSpringDuration)(passedDurationInFrames);
27
28
  (0, validate_frame_js_1.validateFrame)({
28
29
  frame: passedFrame,
29
30
  durationInFrames: Infinity,
30
31
  allowFloats: true,
31
32
  });
32
33
  (0, validate_fps_js_1.validateFps)(fps, 'to spring()', false);
33
- const durationRatio = durationInFrames === undefined
34
- ? 1
35
- : durationInFrames /
36
- (0, measure_spring_js_1.measureSpring)({
37
- fps,
38
- config,
39
- from,
40
- to,
41
- threshold: durationRestThreshold,
42
- });
43
- // Delay the spring by telling the calculation we're at an earlier frame.
44
- const frame = passedFrame - delay;
34
+ const needsToCalculateNaturalDuration = reverse || typeof passedDurationInFrames !== 'undefined';
35
+ const naturalDuration = needsToCalculateNaturalDuration
36
+ ? (0, measure_spring_js_1.measureSpring)({
37
+ fps,
38
+ config,
39
+ from,
40
+ to,
41
+ threshold: durationRestThreshold,
42
+ })
43
+ : undefined;
44
+ const naturalDurationGetter = needsToCalculateNaturalDuration
45
+ ? {
46
+ get: () => naturalDuration,
47
+ }
48
+ : {
49
+ get: () => {
50
+ throw new Error('did not calculate natural duration, this is an error with Remotion. Please report');
51
+ },
52
+ };
53
+ const frame = reverse
54
+ ? (passedDurationInFrames !== null && passedDurationInFrames !== void 0 ? passedDurationInFrames : naturalDurationGetter.get()) - passedFrame
55
+ : passedFrame;
45
56
  const spr = (0, spring_utils_js_1.springCalculation)({
46
57
  fps,
47
- frame: frame / durationRatio,
58
+ frame: (passedDurationInFrames === undefined
59
+ ? frame
60
+ : frame / (passedDurationInFrames / naturalDurationGetter.get())) -
61
+ delay,
48
62
  config,
49
63
  from,
50
64
  to,
@@ -51,12 +51,21 @@ const useMediaPlayback = ({ mediaRef, src, mediaType, playbackRate: localPlaybac
51
51
  (0, warn_about_non_seekable_media_js_1.warnAboutNonSeekableMedia)(mediaRef.current, onlyWarnForMediaSeekingError ? 'console-warning' : 'console-error');
52
52
  }
53
53
  }
54
+ // Only perform a seek if the time is not already the same.
55
+ // Chrome rounds to 6 digits, so 0.033333333 -> 0.033333,
56
+ // therefore a threshold is allowed.
57
+ // Refer to the https://github.com/remotion-dev/video-buffering-example
58
+ // which is fixed by only seeking conditionally.
59
+ const makesSenseToSeek = Math.abs(mediaRef.current.currentTime - shouldBeTime) > 0.00001;
54
60
  if (!playing || absoluteFrame === 0) {
55
- mediaRef.current.currentTime = shouldBeTime;
61
+ if (makesSenseToSeek) {
62
+ mediaRef.current.currentTime = shouldBeTime;
63
+ }
56
64
  }
57
65
  if (mediaRef.current.paused && !mediaRef.current.ended && playing) {
58
- const { current } = mediaRef;
59
- current.currentTime = shouldBeTime;
66
+ if (makesSenseToSeek) {
67
+ mediaRef.current.currentTime = shouldBeTime;
68
+ }
60
69
  (0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)(mediaRef, mediaType);
61
70
  }
62
71
  }, [
@@ -1 +1 @@
1
- export declare const VERSION = "3.3.91";
1
+ export declare const VERSION = "3.3.92";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '3.3.91';
5
+ exports.VERSION = '3.3.92';
@@ -14,6 +14,7 @@ export declare type OffthreadVideoImageFormat = 'png' | 'jpeg';
14
14
  export declare type OffthreadVideoProps = {
15
15
  src: string;
16
16
  className?: string;
17
+ id?: string;
17
18
  style?: React.CSSProperties;
18
19
  volume?: VolumeProp;
19
20
  playbackRate?: number;
@@ -58,7 +58,7 @@ function truthy(value) {
58
58
  }
59
59
 
60
60
  // Automatically generated on publish
61
- const VERSION = '3.3.91';
61
+ const VERSION = '3.3.92';
62
62
 
63
63
  const checkMultipleRemotionVersions = () => {
64
64
  if (typeof globalThis === 'undefined') {
@@ -1505,12 +1505,21 @@ const useMediaPlayback = ({ mediaRef, src, mediaType, playbackRate: localPlaybac
1505
1505
  warnAboutNonSeekableMedia(mediaRef.current, onlyWarnForMediaSeekingError ? 'console-warning' : 'console-error');
1506
1506
  }
1507
1507
  }
1508
+ // Only perform a seek if the time is not already the same.
1509
+ // Chrome rounds to 6 digits, so 0.033333333 -> 0.033333,
1510
+ // therefore a threshold is allowed.
1511
+ // Refer to the https://github.com/remotion-dev/video-buffering-example
1512
+ // which is fixed by only seeking conditionally.
1513
+ const makesSenseToSeek = Math.abs(mediaRef.current.currentTime - shouldBeTime) > 0.00001;
1508
1514
  if (!playing || absoluteFrame === 0) {
1509
- mediaRef.current.currentTime = shouldBeTime;
1515
+ if (makesSenseToSeek) {
1516
+ mediaRef.current.currentTime = shouldBeTime;
1517
+ }
1510
1518
  }
1511
1519
  if (mediaRef.current.paused && !mediaRef.current.ended && playing) {
1512
- const { current } = mediaRef;
1513
- current.currentTime = shouldBeTime;
1520
+ if (makesSenseToSeek) {
1521
+ mediaRef.current.currentTime = shouldBeTime;
1522
+ }
1514
1523
  playAndHandleNotAllowedError(mediaRef, mediaType);
1515
1524
  }
1516
1525
  }, [
@@ -3562,6 +3571,7 @@ function measureSpring({ fps, config = {}, threshold = 0.005, from = 0, to = 1,
3562
3571
  * @see [Documentation](https://www.remotion.dev/docs/spring)
3563
3572
  * @param {number} frame The current time value. Most of the time you want to pass in the return value of useCurrentFrame.
3564
3573
  * @param {number} fps The framerate at which the animation runs. Pass in the value obtained by `useVideoConfig()`.
3574
+ * @param {?boolean} reverse Whether the animation plays in reverse or not. Default `false`.
3565
3575
  * @param {?Object} config optional object that allows you to customize the physical properties of the animation.
3566
3576
  * @param {number} [config.mass=1] The weight of the spring. If you reduce the mass, the animation becomes faster!
3567
3577
  * @param {number} [config.damping=10] How hard the animation decelerates.
@@ -3573,29 +3583,42 @@ function measureSpring({ fps, config = {}, threshold = 0.005, from = 0, to = 1,
3573
3583
  * @param {?number} [config.durationThreshold] How close to the end the animation is considered to be done. Default `0.005`
3574
3584
  * @param {?number} [config.delay] Delay the animation for this amount of frames. Default `0`
3575
3585
  */
3576
- function spring({ frame: passedFrame, fps, config = {}, from = 0, to = 1, durationInFrames, durationRestThreshold, delay = 0, }) {
3577
- validateSpringDuration(durationInFrames);
3586
+ function spring({ frame: passedFrame, fps, config = {}, from = 0, to = 1, durationInFrames: passedDurationInFrames, durationRestThreshold, delay = 0, reverse = false, }) {
3587
+ validateSpringDuration(passedDurationInFrames);
3578
3588
  validateFrame({
3579
3589
  frame: passedFrame,
3580
3590
  durationInFrames: Infinity,
3581
3591
  allowFloats: true,
3582
3592
  });
3583
3593
  validateFps(fps, 'to spring()', false);
3584
- const durationRatio = durationInFrames === undefined
3585
- ? 1
3586
- : durationInFrames /
3587
- measureSpring({
3588
- fps,
3589
- config,
3590
- from,
3591
- to,
3592
- threshold: durationRestThreshold,
3593
- });
3594
- // Delay the spring by telling the calculation we're at an earlier frame.
3595
- const frame = passedFrame - delay;
3594
+ const needsToCalculateNaturalDuration = reverse || typeof passedDurationInFrames !== 'undefined';
3595
+ const naturalDuration = needsToCalculateNaturalDuration
3596
+ ? measureSpring({
3597
+ fps,
3598
+ config,
3599
+ from,
3600
+ to,
3601
+ threshold: durationRestThreshold,
3602
+ })
3603
+ : undefined;
3604
+ const naturalDurationGetter = needsToCalculateNaturalDuration
3605
+ ? {
3606
+ get: () => naturalDuration,
3607
+ }
3608
+ : {
3609
+ get: () => {
3610
+ throw new Error('did not calculate natural duration, this is an error with Remotion. Please report');
3611
+ },
3612
+ };
3613
+ const frame = reverse
3614
+ ? (passedDurationInFrames !== null && passedDurationInFrames !== void 0 ? passedDurationInFrames : naturalDurationGetter.get()) - passedFrame
3615
+ : passedFrame;
3596
3616
  const spr = springCalculation({
3597
3617
  fps,
3598
- frame: frame / durationRatio,
3618
+ frame: (passedDurationInFrames === undefined
3619
+ ? frame
3620
+ : frame / (passedDurationInFrames / naturalDurationGetter.get())) -
3621
+ delay,
3599
3622
  config,
3600
3623
  from,
3601
3624
  to,
@@ -1,4 +1,4 @@
1
1
  // Automatically generated on publish
2
- const VERSION = '3.3.91';
2
+ const VERSION = '3.3.92';
3
3
 
4
4
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "3.3.91",
3
+ "version": "3.3.92",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",