remotion 4.0.30 → 4.0.31

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 @@ exports.Audio = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const absolute_src_js_1 = require("../absolute-src.js");
7
+ const calculate_loop_js_1 = require("../calculate-loop.js");
7
8
  const cancel_render_js_1 = require("../cancel-render.js");
8
9
  const get_remotion_environment_js_1 = require("../get-remotion-environment.js");
9
10
  const index_js_1 = require("../loop/index.js");
@@ -29,7 +30,7 @@ const AudioRefForwardingFunction = (props, ref) => {
29
30
  const onError = (0, react_1.useCallback)((e) => {
30
31
  console.log(e.currentTarget.error);
31
32
  // If there is no `loop` property, we don't need to get the duration
32
- // and thsi does not need to be a fatal error
33
+ // and this does not need to be a fatal error
33
34
  const errMessage = `Could not play audio with src ${otherProps.src}: ${e.currentTarget.error}. See https://remotion.dev/docs/media-playback-error for help.`;
34
35
  if (loop) {
35
36
  (0, cancel_render_js_1.cancelRender)(new Error(errMessage));
@@ -43,9 +44,12 @@ const AudioRefForwardingFunction = (props, ref) => {
43
44
  }, [setDurations]);
44
45
  if (loop && props.src && durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)] !== undefined) {
45
46
  const duration = Math.floor(durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)] * fps);
46
- const playbackRate = (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1;
47
- const actualDuration = duration / playbackRate;
48
- return ((0, jsx_runtime_1.jsx)(index_js_1.Loop, { layout: "none", durationInFrames: Math.floor(actualDuration), children: (0, jsx_runtime_1.jsx)(exports.Audio, { ...propsOtherThanLoop, ref: ref }) }));
47
+ return ((0, jsx_runtime_1.jsx)(index_js_1.Loop, { layout: "none", durationInFrames: (0, calculate_loop_js_1.calculateLoopDuration)({
48
+ endAt,
49
+ mediaDuration: duration,
50
+ playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
51
+ startFrom,
52
+ }), children: (0, jsx_runtime_1.jsx)(exports.Audio, { ...propsOtherThanLoop, ref: ref }) }));
49
53
  }
50
54
  if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
51
55
  (0, validate_start_from_props_js_1.validateStartFromProps)(startFrom, endAt);
@@ -0,0 +1,6 @@
1
+ export declare const calculateLoopDuration: ({ endAt, mediaDuration, playbackRate, startFrom, }: {
2
+ mediaDuration: number;
3
+ playbackRate: number;
4
+ startFrom: number | undefined;
5
+ endAt: number | undefined;
6
+ }) => number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateLoopDuration = void 0;
4
+ const calculateLoopDuration = ({ endAt, mediaDuration, playbackRate, startFrom, }) => {
5
+ let duration = mediaDuration;
6
+ // Account for endAt
7
+ if (typeof endAt !== 'undefined') {
8
+ duration = endAt;
9
+ }
10
+ // Account for startFrom
11
+ if (typeof startFrom !== 'undefined') {
12
+ duration -= startFrom;
13
+ }
14
+ const actualDuration = duration / playbackRate;
15
+ return Math.floor(actualDuration);
16
+ };
17
+ exports.calculateLoopDuration = calculateLoopDuration;
@@ -0,0 +1,3 @@
1
+ export type RemotionEnvironment = 'preview' | 'rendering' | 'player-development' | 'player-production';
2
+ export declare const getRemotionEnvironment: () => RemotionEnvironment;
3
+ export declare const useRemotionEnvironment: () => RemotionEnvironment;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRemotionEnvironment = exports.getRemotionEnvironment = void 0;
4
+ const is_player_js_1 = require("./is-player.js");
5
+ const getRemotionEnvironment = () => {
6
+ if (process.env.NODE_ENV === 'production') {
7
+ if (typeof window !== 'undefined' && window.remotion_isPlayer) {
8
+ return 'player-production';
9
+ }
10
+ return 'rendering';
11
+ }
12
+ // The Vitest framework sets NODE_ENV as test.
13
+ // Right now we don't need to treat it in a special
14
+ // way which is good - defaulting to `rendering`.
15
+ if (process.env.NODE_ENV === 'test') {
16
+ return 'rendering';
17
+ }
18
+ if (typeof window !== 'undefined' && window.remotion_isPlayer) {
19
+ return 'player-development';
20
+ }
21
+ return 'preview';
22
+ };
23
+ exports.getRemotionEnvironment = getRemotionEnvironment;
24
+ const useRemotionEnvironment = () => {
25
+ const isPlayer = (0, is_player_js_1.useIsPlayer)();
26
+ if (isPlayer) {
27
+ if (process.env.NODE_ENV === 'production') {
28
+ return 'player-production';
29
+ }
30
+ return 'player-development';
31
+ }
32
+ return (0, exports.getRemotionEnvironment)();
33
+ };
34
+ exports.useRemotionEnvironment = useRemotionEnvironment;
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.30";
1
+ export declare const VERSION = "4.0.31";
@@ -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 = '4.0.30';
5
+ exports.VERSION = '4.0.31';
@@ -4,6 +4,7 @@ exports.Video = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const absolute_src_js_1 = require("../absolute-src.js");
7
+ const calculate_loop_js_1 = require("../calculate-loop.js");
7
8
  const get_remotion_environment_js_1 = require("../get-remotion-environment.js");
8
9
  const index_js_1 = require("../loop/index.js");
9
10
  const Sequence_js_1 = require("../Sequence.js");
@@ -30,10 +31,13 @@ const VideoForwardingFunction = (props, ref) => {
30
31
  setDurations({ type: 'got-duration', durationInSeconds, src });
31
32
  }, [setDurations]);
32
33
  if (loop && props.src && durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)] !== undefined) {
33
- const naturalDuration = durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)] * fps;
34
- const playbackRate = (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1;
35
- const durationInFrames = Math.floor(naturalDuration / playbackRate);
36
- return ((0, jsx_runtime_1.jsx)(index_js_1.Loop, { durationInFrames: durationInFrames, children: (0, jsx_runtime_1.jsx)(exports.Video, { ...propsOtherThanLoop, ref: ref }) }));
34
+ const mediaDuration = durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)] * fps;
35
+ return ((0, jsx_runtime_1.jsx)(index_js_1.Loop, { durationInFrames: (0, calculate_loop_js_1.calculateLoopDuration)({
36
+ endAt,
37
+ mediaDuration,
38
+ playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
39
+ startFrom,
40
+ }), children: (0, jsx_runtime_1.jsx)(exports.Video, { ...propsOtherThanLoop, ref: ref }) }));
37
41
  }
38
42
  if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
39
43
  (0, validate_start_from_props_js_1.validateStartFromProps)(startFrom, endAt);
@@ -59,7 +59,7 @@ function truthy(value) {
59
59
  }
60
60
 
61
61
  // Automatically generated on publish
62
- const VERSION = '4.0.30';
62
+ const VERSION = '4.0.31';
63
63
 
64
64
  const checkMultipleRemotionVersions = () => {
65
65
  if (typeof globalThis === 'undefined') {
@@ -136,6 +136,20 @@ const getAbsoluteSrc = (relativeSrc) => {
136
136
  return new URL(relativeSrc, window.location.origin).href;
137
137
  };
138
138
 
139
+ const calculateLoopDuration = ({ endAt, mediaDuration, playbackRate, startFrom, }) => {
140
+ let duration = mediaDuration;
141
+ // Account for endAt
142
+ if (typeof endAt !== 'undefined') {
143
+ duration = endAt;
144
+ }
145
+ // Account for startFrom
146
+ if (typeof startFrom !== 'undefined') {
147
+ duration -= startFrom;
148
+ }
149
+ const actualDuration = duration / playbackRate;
150
+ return Math.floor(actualDuration);
151
+ };
152
+
139
153
  const isErrorLike = (err) => {
140
154
  if (err === null) {
141
155
  return false;
@@ -2525,7 +2539,7 @@ const AudioRefForwardingFunction = (props, ref) => {
2525
2539
  const onError = useCallback((e) => {
2526
2540
  console.log(e.currentTarget.error);
2527
2541
  // If there is no `loop` property, we don't need to get the duration
2528
- // and thsi does not need to be a fatal error
2542
+ // and this does not need to be a fatal error
2529
2543
  const errMessage = `Could not play audio with src ${otherProps.src}: ${e.currentTarget.error}. See https://remotion.dev/docs/media-playback-error for help.`;
2530
2544
  if (loop) {
2531
2545
  cancelRender(new Error(errMessage));
@@ -2539,9 +2553,12 @@ const AudioRefForwardingFunction = (props, ref) => {
2539
2553
  }, [setDurations]);
2540
2554
  if (loop && props.src && durations[getAbsoluteSrc(props.src)] !== undefined) {
2541
2555
  const duration = Math.floor(durations[getAbsoluteSrc(props.src)] * fps);
2542
- const playbackRate = (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1;
2543
- const actualDuration = duration / playbackRate;
2544
- return (jsx(Loop, { layout: "none", durationInFrames: Math.floor(actualDuration), children: jsx(Audio, { ...propsOtherThanLoop, ref: ref }) }));
2556
+ return (jsx(Loop, { layout: "none", durationInFrames: calculateLoopDuration({
2557
+ endAt,
2558
+ mediaDuration: duration,
2559
+ playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
2560
+ startFrom,
2561
+ }), children: jsx(Audio, { ...propsOtherThanLoop, ref: ref }) }));
2545
2562
  }
2546
2563
  if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
2547
2564
  validateStartFromProps(startFrom, endAt);
@@ -4719,10 +4736,13 @@ const VideoForwardingFunction = (props, ref) => {
4719
4736
  setDurations({ type: 'got-duration', durationInSeconds, src });
4720
4737
  }, [setDurations]);
4721
4738
  if (loop && props.src && durations[getAbsoluteSrc(props.src)] !== undefined) {
4722
- const naturalDuration = durations[getAbsoluteSrc(props.src)] * fps;
4723
- const playbackRate = (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1;
4724
- const durationInFrames = Math.floor(naturalDuration / playbackRate);
4725
- return (jsx(Loop, { durationInFrames: durationInFrames, children: jsx(Video, { ...propsOtherThanLoop, ref: ref }) }));
4739
+ const mediaDuration = durations[getAbsoluteSrc(props.src)] * fps;
4740
+ return (jsx(Loop, { durationInFrames: calculateLoopDuration({
4741
+ endAt,
4742
+ mediaDuration,
4743
+ playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
4744
+ startFrom,
4745
+ }), children: jsx(Video, { ...propsOtherThanLoop, ref: ref }) }));
4726
4746
  }
4727
4747
  if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
4728
4748
  validateStartFromProps(startFrom, endAt);
@@ -1,4 +1,4 @@
1
1
  // Automatically generated on publish
2
- const VERSION = '4.0.30';
2
+ const VERSION = '4.0.31';
3
3
 
4
4
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "4.0.30",
3
+ "version": "4.0.31",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",