Skip to content

🎥 Make videos programmatically with React

`remotion`: Allow volume > 1

Jonny Burger12a9e8b58371
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index 79f02063ed..871eb643b1 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -129,7 +129,6 @@ export type AudioOrVideoAsset = {
volume: number;
mediaFrame: number;
playbackRate: number;
- allowAmplificationDuringRender: boolean;
toneFrequency: number | null;
audioStartFrame: number;
};
diff --git a/packages/core/src/audio/AudioForPreview.tsx b/packages/core/src/audio/AudioForPreview.tsx
index d7905e3cf4..cadfc8aca6 100644
--- a/packages/core/src/audio/AudioForPreview.tsx
+++ b/packages/core/src/audio/AudioForPreview.tsx
@@ -9,8 +9,10 @@ import React, {
} from 'react';
import {SequenceContext} from '../SequenceContext.js';
import {SequenceVisibilityToggleContext} from '../SequenceManager.js';
+import {useLogLevel} from '../log-level-context.js';
import {usePreload} from '../prefetch.js';
import {random} from '../random.js';
+import {useAmplification} from '../use-amplification.js';
import {useMediaInTimeline} from '../use-media-in-timeline.js';
import {
DEFAULT_ACCEPTABLE_TIMESHIFT,
@@ -49,6 +51,8 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
);
}
+ const logLevel = useLogLevel();
+
const {
volume,
muted,
@@ -94,7 +98,6 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
frame: volumePropFrame,
volume,
mediaVolume,
- allowAmplificationDuringRender: false,
});
const propsToPass = useMemo((): RemotionAudioProps => {
@@ -171,6 +174,12 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
onAutoPlayError: null,
});
+ useAmplification({
+ logLevel,
+ mediaRef: audioRef,
+ volume: userPreferredVolume,
+ });
+
useImperativeHandle(ref, () => {
return audioRef.current as HTMLAudioElement;
}, [audioRef]);
diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsx
index 3125f97db3..9e3ee642dd 100644
--- a/packages/core/src/audio/AudioForRendering.tsx
+++ b/packages/core/src/audio/AudioForRendering.tsx
@@ -75,7 +75,6 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
volume: volumeProp,
frame: volumePropFrame,
mediaVolume: 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
});
useImperativeHandle(ref, () => {
@@ -107,7 +106,6 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
volume,
mediaFrame: frame,
playbackRate: props.playbackRate ?? 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
toneFrequency: toneFrequency ?? null,
audioStartFrame: Math.max(0, -(sequenceContext?.relativeFrom ?? 0)),
});
@@ -124,7 +122,6 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
frame,
playbackRate,
props.playbackRate,
- allowAmplificationDuringRender,
toneFrequency,
sequenceContext?.relativeFrom,
]);
diff --git a/packages/core/src/audio/props.ts b/packages/core/src/audio/props.ts
index 3671e4c18a..71cd4ecc9d 100644
--- a/packages/core/src/audio/props.ts
+++ b/packages/core/src/audio/props.ts
@@ -17,6 +17,9 @@ export type RemotionAudioProps = Omit<
volume?: VolumeProp;
playbackRate?: number;
acceptableTimeShiftInSeconds?: number;
+ /**
+ * @deprecated Amplification is now always enabled. To prevent amplification, set `volume` to a value less than 1.
+ */
allowAmplificationDuringRender?: boolean;
_remotionInternalNeedsDurationCalculation?: boolean;
_remotionInternalNativeLoopPassed?: boolean;
diff --git a/packages/core/src/test/volume-prop.test.ts b/packages/core/src/test/volume-prop.test.ts
index 290daf9d93..e0e45dd3ef 100644
--- a/packages/core/src/test/volume-prop.test.ts
+++ b/packages/core/src/test/volume-prop.test.ts
@@ -8,7 +8,6 @@ describe('EvaluateVolume does not throw', () => {
frame: 10,
volume: undefined,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expect(evaluateVolume(toEvaluate)).toEqual(1);
});
@@ -18,7 +17,6 @@ describe('EvaluateVolume does not throw', () => {
frame: 10,
volume: smallVolume,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expect(evaluateVolume(toEvaluate)).toEqual(smallVolume);
});
@@ -27,7 +25,6 @@ describe('EvaluateVolume does not throw', () => {
frame: 10,
volume: 10,
mediaVolume: 1,
- allowAmplificationDuringRender: true,
};
expect(evaluateVolume(toEvaluate)).toBe(10);
});
@@ -36,7 +33,6 @@ describe('EvaluateVolume does not throw', () => {
frame: 1,
volume: (frame: number) => frame * 0.5,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expect(evaluateVolume(toEvaluate)).toBe(0.5);
});
@@ -45,7 +41,6 @@ describe('EvaluateVolume does not throw', () => {
frame: 10,
volume: (frame: number) => frame,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expect(evaluateVolume(toEvaluate)).toBe(1);
});
@@ -75,7 +70,6 @@ describe('evaluateVolume throws exception', () => {
frame: 1,
volume: () => invalidVolume,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expectToThrow(() => {
evaluateVolume(toEvaluate);
@@ -87,7 +81,6 @@ describe('evaluateVolume throws exception', () => {
frame: 1,
volume: () => invalidVolume,
mediaVolume: 1,
- allowAmplificationDuringRender: false,
};
expectToThrow(() => {
evaluateVolume(toEvaluate);
diff --git a/packages/core/src/use-amplification.ts b/packages/core/src/use-amplification.ts
new file mode 100644
index 0000000000..b1c99018e6
--- /dev/null
+++ b/packages/core/src/use-amplification.ts
@@ -0,0 +1,65 @@
+import {useLayoutEffect, useRef, type RefObject} from 'react';
+import type {LogLevel} from './log';
+import {Log} from './log';
+
+let warned = false;
+
+const warnOnce = (logLevel: LogLevel) => {
+ if (warned) {
+ return;
+ }
+
+ warned = true;
+
+ Log.warn(logLevel, 'AudioContext is not supported in this browser');
+};
+
+export const useAmplification = ({
+ mediaRef,
+ volume,
+ logLevel,
+}: {
+ mediaRef: RefObject<HTMLAudioElement | HTMLVideoElement | null>;
+ volume: number;
+ logLevel: LogLevel;
+}) => {
+ const shouldAmplify = volume > 1;
+ const gainRef = useRef<GainNode | null>(null);
+
+ useLayoutEffect(() => {
+ if (!shouldAmplify) {
+ return;
+ }
+
+ if (!AudioContext) {
+ warnOnce(logLevel);
+ return;
+ }
+
+ if (!mediaRef.current) {
+ return;
+ }
+
+ const audioContext = new AudioContext();
+ const source = audioContext.createMediaElementSource(mediaRef.current);
+ const gainNode = audioContext.createGain();
+ gainRef.current = gainNode;
+ source.connect(gainNode);
+ gainNode.connect(audioContext.destination);
+
+ return () => {
+ gainNode.disconnect();
+ source.disconnect();
+ audioContext.close();
+ gainRef.current = null;
+ };
+ }, [logLevel, mediaRef, shouldAmplify]);
+
+ useLayoutEffect(() => {
+ if (!gainRef.current) {
+ return;
+ }
+
+ gainRef.current.gain.value = volume;
+ }, [volume]);
+};
diff --git a/packages/core/src/use-media-in-timeline.ts b/packages/core/src/use-media-in-timeline.ts
index 158b4695d9..119ee1eca8 100644
--- a/packages/core/src/use-media-in-timeline.ts
+++ b/packages/core/src/use-media-in-timeline.ts
@@ -86,7 +86,6 @@ export const useMediaInTimeline = ({
frame: i + startsAt,
volume,
mediaVolume,
- allowAmplificationDuringRender: false,
});
})
.join(',');
diff --git a/packages/core/src/use-sync-volume-with-media-tag.ts b/packages/core/src/use-sync-volume-with-media-tag.ts
index 2d726aba1a..7e62370c91 100644
--- a/packages/core/src/use-sync-volume-with-media-tag.ts
+++ b/packages/core/src/use-sync-volume-with-media-tag.ts
@@ -26,7 +26,6 @@ export const useSyncVolumeWithMediaTag = ({
frame: volumePropFrame,
volume,
mediaVolume,
- allowAmplificationDuringRender: false,
});
if (!isApproximatelyTheSame(userPreferredVolume, mediaRef.current.volume)) {
diff --git a/packages/core/src/video/OffthreadVideoForRendering.tsx b/packages/core/src/video/OffthreadVideoForRendering.tsx
index e37b4f79bb..00b72ecc54 100644
--- a/packages/core/src/video/OffthreadVideoForRendering.tsx
+++ b/packages/core/src/video/OffthreadVideoForRendering.tsx
@@ -92,7 +92,6 @@ export const OffthreadVideoForRendering: React.FC<OffthreadVideoProps> = ({
volume: volumeProp,
frame: volumePropsFrame,
mediaVolume: 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
});
useEffect(() => {
@@ -120,7 +119,6 @@ export const OffthreadVideoForRendering: React.FC<OffthreadVideoProps> = ({
volume,
mediaFrame: frame,
playbackRate: playbackRate ?? 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
toneFrequency: toneFrequency ?? null,
audioStartFrame: Math.max(0, -(sequenceContext?.relativeFrom ?? 0)),
});
@@ -136,7 +134,6 @@ export const OffthreadVideoForRendering: React.FC<OffthreadVideoProps> = ({
frame,
absoluteFrame,
playbackRate,
- allowAmplificationDuringRender,
toneFrequency,
sequenceContext?.relativeFrom,
]);
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index b549150af7..8ea9820210 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -93,7 +93,6 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
volume: volumeProp,
frame: volumePropsFrame,
mediaVolume: 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
});
useEffect(() => {
@@ -121,7 +120,6 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
volume,
mediaFrame: frame,
playbackRate: playbackRate ?? 1,
- allowAmplificationDuringRender: allowAmplificationDuringRender ?? false,
toneFrequency: toneFrequency ?? null,
audioStartFrame: Math.max(0, -(sequenceContext?.relativeFrom ?? 0)),
});
@@ -137,7 +135,6 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
frame,
absoluteFrame,
playbackRate,
- allowAmplificationDuringRender,
toneFrequency,
sequenceContext?.relativeFrom,
]);
diff --git a/packages/core/src/volume-prop.ts b/packages/core/src/volume-prop.ts
index f6d0eb8624..c2b04b021a 100644
--- a/packages/core/src/volume-prop.ts
+++ b/packages/core/src/volume-prop.ts
@@ -4,14 +4,12 @@ export const evaluateVolume = ({
frame,
volume,
mediaVolume = 1,
- allowAmplificationDuringRender,
}: {
frame: number;
volume: VolumeProp | undefined;
mediaVolume: number;
- allowAmplificationDuringRender: boolean;
}): number => {
- const maxVolume = allowAmplificationDuringRender ? Infinity : 1;
+ const maxVolume = Infinity;
if (typeof volume === 'number') {
return Math.min(maxVolume, volume * mediaVolume);
}
diff --git a/packages/docs/docs/audio.mdx b/packages/docs/docs/audio.mdx
index e50aa6b9aa..e24823500c 100644
--- a/packages/docs/docs/audio.mdx
+++ b/packages/docs/docs/audio.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-audio.png
title: <Audio>
id: audio
-crumb: "How to"
+crumb: 'How to'
---
Using this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.
@@ -14,12 +14,12 @@ Using this component, you can add audio to your video. All audio formats which a
[Put an audio file into the `public/` folder](/docs/assets) and use [`staticFile()`](/docs/staticfile) to reference it.
```tsx twoslash
-import { AbsoluteFill, Audio, staticFile } from "remotion";
+import {AbsoluteFill, Audio, staticFile} from 'remotion';
export const MyVideo = () => {
return (
<AbsoluteFill>
- <Audio src={staticFile("audio.mp3")} />
+ <Audio src={staticFile('audio.mp3')} />
</AbsoluteFill>
);
};
@@ -30,29 +30,24 @@ export const MyVideo = () => {
The component also accepts a `volume` props which allows you to control the volume of the audio in it's entirety or frame by frame. Read the page on [using audio](/docs/using-audio) to learn more.
```tsx twoslash title="Setting a static volume"
-import { AbsoluteFill, Audio, staticFile } from "remotion";
+import {AbsoluteFill, Audio, staticFile} from 'remotion';
export const MyVideo = () => {
return (
<AbsoluteFill>
- <Audio volume={0.5} src={staticFile("background.mp3")} />
+ <Audio volume={0.5} src={staticFile('background.mp3')} />
</AbsoluteFill>
);
};
```
```tsx twoslash title="Changing the volume over time"
-import { AbsoluteFill, Audio, interpolate, staticFile } from "remotion";
+import {AbsoluteFill, Audio, interpolate, staticFile} from 'remotion';
export const MyVideo = () => {
return (
<AbsoluteFill>
- <Audio
- volume={(f) =>
- interpolate(f, [0, 30], [0, 1], { extrapolateLeft: "clamp" })
- }
- src={staticFile("voice.mp3")}
- />
+ <Audio volume={(f) => interpolate(f, [0, 30], [0, 1], {extrapolateLeft: 'clamp'})} src={staticFile('voice.mp3')} />
</AbsoluteFill>
);
};
@@ -84,12 +79,12 @@ By passing `endAt={120}`, any audio after the 4 second mark in the file will be
The audio will play the range from `00:02:00` to `00:04:00`, meaning the audio will play for 2 seconds.
```tsx twoslash
-import { AbsoluteFill, Audio, staticFile } from "remotion";
+import {AbsoluteFill, Audio, staticFile} from 'remotion';
export const MyVideo = () => {
return (
<AbsoluteFill>
- <Audio src={staticFile("audio.mp3")} startFrom={60} endAt={120} />
+ <Audio src={staticFile('audio.mp3')} startFrom={60} endAt={120} />
</AbsoluteFill>
);
};
@@ -102,12 +97,12 @@ You can use the `playbackRate` prop to control the speed of the audio. `1` is th
While Remotion doesn't limit the range of possible playback speeds, in development mode the [`HTMLMediaElement.playbackRate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate) API is used which throws errors on extreme values. At the time of writing, Google Chrome throws an exception if the playback rate is below `0.0625` or above `16`.
```tsx twoslash
-import { AbsoluteFill, Audio, staticFile } from "remotion";
+import {AbsoluteFill, Audio, staticFile} from 'remotion';
export const MyVideo = () => {
return (
<AbsoluteFill>
- <Audio src={staticFile("audio.mp3")} playbackRate={2} />
+ <Audio src={staticFile('audio.mp3')} playbackRate={2} />
</AbsoluteFill>
);
};
@@ -118,13 +113,13 @@ export const MyVideo = () => {
The `muted` prop will be respected. It will lead to no audio being played while still keeping the audio tag mounted. It's value may change over time, for example to only mute a certain section of the audio.
```tsx twoslash
-import { AbsoluteFill, Audio, staticFile, useCurrentFrame } from "remotion";
+import {AbsoluteFill, Audio, staticFile, useCurrentFrame} from 'remotion';
export const MyVideo = () => {
const frame = useCurrentFrame();
return (
<AbsoluteFill>
- <Audio src={staticFile("audio.mp3")} muted={frame < 30} />
+ <Audio src={staticFile('audio.mp3')} muted={frame < 30} />
</AbsoluteFill>
);
};
@@ -141,13 +136,13 @@ A name and that will be shown as the label of the sequence in the timeline of th
You can use the `loop` prop to loop audio.
```tsx twoslash
-import { AbsoluteFill, Audio, staticFile, useCurrentFrame } from "remotion";
+import {AbsoluteFill, Audio, staticFile, useCurrentFrame} from 'remotion';
export const MyVideo = () => {
const frame = useCurrentFrame();
return (
<AbsoluteFill>
- <Audio loop src={staticFile("audio.mp3")} />
+ <Audio loop src={staticFile('audio.mp3')} />
</AbsoluteFill>
);
};
@@ -165,10 +160,10 @@ A `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of
In the [Remotion Studio](/docs/terminology/studio) or in the [Remotion Player](/docs/player), Remotion will seek the audio if it gets too much out of sync with Remotion's internal time - be it due to the audio loading or the page being too slow to keep up in real-time. By default, a seek is triggered if `0.45` seconds of time shift is encountered. Using this prop, you can customize the threshold.
-### `allowAmplificationDuringRender`<AvailableFrom v="3.3.17"/>
+### ~`allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />~
-Make values for [`volume`](#volume) greater than `1` result in amplification during renders.
-In the Remotion Studio, the volume will be limited to `1`, since the browser cannot amplify audio.
+Deprecated since v4.0.279: It is now always allowed to set the volume higher than `1`.
+To prevent synthetic amplification, set a volume not higher than 1.
### `pauseWhenBuffering`<AvailableFrom v="4.0.111"/>
@@ -196,11 +191,11 @@ Customize the [number of retries](/docs/delay-render#retrying) of the [`delayRen
<Credits
contributors={[
{
- username: "JonnyBurger",
- contribution: "Implementation",
+ username: 'JonnyBurger',
+ contribution: 'Implementation',
},
{
- username: "evoxf1",
+ username: 'evoxf1',
contribution: (
<>
<code>toneFrequency</code> prop
diff --git a/packages/docs/docs/offthreadvideo.mdx b/packages/docs/docs/offthreadvideo.mdx
index abbb1dfee4..1979aaff7c 100644
--- a/packages/docs/docs/offthreadvideo.mdx
+++ b/packages/docs/docs/offthreadvideo.mdx
@@ -137,11 +137,6 @@ export const MyComposition = () => {
};
```
-### `allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />
-
-Make values for [`volume`](/docs/video#volume) greater than `1` result in amplification during renders.
-During Preview, the volume will be limited to `1`, since the browser cannot amplify audio.
-
### `name?`<AvailableFrom v="4.0.71"/>
A name and that will be shown as the label of the sequence in the timeline of the Remotion Studio. This property is purely for helping you keep track of items in the timeline.
@@ -197,10 +192,10 @@ export const MyComposition = () => {
In the [Studio](/docs/terminology/studio) or in the [Remotion Player](/docs/player), Remotion will seek the video if it gets too much out of sync with Remotion's internal time - be it due to the video loading or the page being too slow to keep up in real-time. By default, a seek is triggered if `0.45` seconds of time shift is encountered. Using this prop, you can customize the threshold.
-### `allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />
+### ~`allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />~
-Make values for [`volume`](#volume) greater than `1` result in amplification during renders.
-During Preview, the volume will be limited to `1`, since the browser cannot amplify audio.
+Deprecated since v4.0.279: It is now always allowed to set the volume higher than `1`.
+To prevent synthetic amplification, set a volume not higher than 1.
### `toneFrequency?`<AvailableFrom v="4.0.47"/>
@@ -280,17 +275,7 @@ You can use the following `<LoopableOffthreadVideo>` component that uses [`@remo
```tsx twoslash title="src/LoopableOffthreadVideo.tsx"
import {mediaParserController, parseMedia} from '@remotion/media-parser';
import React, {useEffect, useState} from 'react';
-import {
- cancelRender,
- continueRender,
- delayRender,
- getRemotionEnvironment,
- Loop,
- OffthreadVideo,
- RemotionOffthreadVideoProps,
- useVideoConfig,
- Video
-} from 'remotion';
+import {cancelRender, continueRender, delayRender, getRemotionEnvironment, Loop, OffthreadVideo, RemotionOffthreadVideoProps, useVideoConfig, Video} from 'remotion';
const LoopedOffthreadVideo: React.FC<RemotionOffthreadVideoProps> = (props) => {
const [duration, setDuration] = useState<number | null>(null);
diff --git a/packages/docs/docs/video.mdx b/packages/docs/docs/video.mdx
index a7934833a8..cf3890d71e 100644
--- a/packages/docs/docs/video.mdx
+++ b/packages/docs/docs/video.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-video.png
title: <Video>
id: video
-crumb: "API"
+crumb: 'API'
---
Wraps the native [`<video>`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement) element to include video in your component that is synchronized with Remotion's time.
@@ -18,12 +18,12 @@ Prefer [`<OffthreadVideo>`](/docs/offthreadvideo) which during render is faster
All the props that the native `<video>` element accepts (except `autoplay` and `controls`) will be forwarded (but of course not all are useful for Remotion). This means you can use all CSS to style the video.
```tsx twoslash
-import { AbsoluteFill, staticFile, Video } from "remotion";
+import {AbsoluteFill, staticFile, Video} from 'remotion';
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video src={staticFile("video.webm")} />
+ <Video src={staticFile('video.webm')} />
</AbsoluteFill>
);
};
@@ -32,7 +32,7 @@ export const MyComposition = () => {
You can load a video from an URL as well:
```tsx twoslash
-import { AbsoluteFill, Video } from "remotion";
+import {AbsoluteFill, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
@@ -61,13 +61,13 @@ By passing `endAt={120}`, any video after the 4 second mark in the file will be
The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.
```tsx twoslash
-import { AbsoluteFill, staticFile, Video } from "remotion";
+import {AbsoluteFill, staticFile, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video src={staticFile("video.webm")} startFrom={60} endAt={120} />
+ <Video src={staticFile('video.webm')} startFrom={60} endAt={120} />
</AbsoluteFill>
);
};
@@ -82,16 +82,13 @@ Removes a portion of the video at the end. See [`startFrom`](/docs/video#startfr
You can pass any style you can pass to a native `<video>` element. For example, set its size:
```tsx twoslash
-import { AbsoluteFill, staticFile, Video } from "remotion";
+import {AbsoluteFill, staticFile, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video
- src={staticFile("video.webm")}
- style={{ height: 720, width: 1280 }}
- />
+ <Video src={staticFile('video.webm')} style={{height: 720, width: 1280}} />
</AbsoluteFill>
);
};
@@ -102,31 +99,26 @@ export const MyComposition = () => {
Allows you to control the volume for the whole track or change it on a per-frame basis. Refer to the [using audio](/docs/using-audio#controlling-volume) guide to learn how to use it.
```tsx twoslash title="Example using static volume"
-import { AbsoluteFill, staticFile, Video } from "remotion";
+import {AbsoluteFill, staticFile, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video volume={0.5} src={staticFile("video.webm")} />
+ <Video volume={0.5} src={staticFile('video.webm')} />
</AbsoluteFill>
);
};
```
```tsx twoslash title="Example of a ramp up over 100 frames"
-import { AbsoluteFill, interpolate, staticFile, Video } from "remotion";
+import {AbsoluteFill, interpolate, staticFile, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video
- volume={(f) =>
- interpolate(f, [0, 100], [0, 1], { extrapolateLeft: "clamp" })
- }
- src={staticFile("video.webm")}
- />
+ <Video volume={(f) => interpolate(f, [0, 100], [0, 1], {extrapolateLeft: 'clamp'})} src={staticFile('video.webm')} />
</AbsoluteFill>
);
};
@@ -154,13 +146,13 @@ Controls the speed of the video. `1` is the default and means regular speed, `0.
While Remotion doesn't limit the range of possible playback speeds, in development mode the [`HTMLMediaElement.playbackRate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate) API is used which throws errors on extreme values. At the time of writing, Google Chrome throws an exception if the playback rate is below `0.0625` or above `16`.
```tsx twoslash title="Example of a video playing twice as fast"
-import { AbsoluteFill, staticFile, Video } from "remotion";
+import {AbsoluteFill, staticFile, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video playbackRate={2} src={staticFile("video.webm")} />
+ <Video playbackRate={2} src={staticFile('video.webm')} />
</AbsoluteFill>
);
};
@@ -171,15 +163,12 @@ export const MyComposition = () => {
You can drop the audio of the video by adding a `muted` prop:
```tsx twoslash title="Example of a muted video"
-import { AbsoluteFill, Video } from "remotion";
+import {AbsoluteFill, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video
- muted
- src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
- />
+ <Video muted src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />
</AbsoluteFill>
);
};
@@ -192,15 +181,12 @@ This has the benefit that Remotion will not have to download the video file duri
Makes the video loop indefinitely.
```tsx twoslash title="Example of a looped video"
-import { AbsoluteFill, Video } from "remotion";
+import {AbsoluteFill, Video} from 'remotion';
// ---cut---
export const MyComposition = () => {
return (
<AbsoluteFill>
- <Video
- loop
- src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
- />
+ <Video loop src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />
</AbsoluteFill>
);
};
@@ -210,10 +196,10 @@ export const MyComposition = () => {
In the [Studio](/docs/terminology/studio) or in the [Remotion Player](/docs/player), Remotion will seek the video if it gets too much out of sync with Remotion's internal time - be it due to the video loading or the page being too slow to keep up in real-time. By default, a seek is triggered if `0.45` seconds of time shift is encountered. Using this prop, you can customize the threshold.
-### `allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />
+### ~`allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />~
-Make values for [`volume`](#volume) greater than `1` result in amplification during renders.
-During Preview, the volume will be limited to `1`, since the browser cannot amplify audio.
+Deprecated since v4.0.279: It is now always allowed to set the volume higher than `1`.
+To prevent synthetic amplification, set a volume not higher than 1.
### `toneFrequency?`<AvailableFrom v="4.0.47"/>
@@ -256,7 +242,6 @@ Corresponds to the [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/
One of `"anonymous"`, `"use-credentials"` or `undefined`.
Default: `"anonymous"` if `onVideoFrame` is specified, `undefined`, otherwise.
-
## Speed up renders for video with silent audio
Remotion will download the whole video during render in order to mix its audio. If the video contains a silent audio track, you can add the muted property to signal to Remotion that it does not need to download the video and make the render more efficient.
diff --git a/packages/renderer/src/assets/calculate-asset-positions.ts b/packages/renderer/src/assets/calculate-asset-positions.ts
index 244249f05d..fef3084e16 100644
--- a/packages/renderer/src/assets/calculate-asset-positions.ts
+++ b/packages/renderer/src/assets/calculate-asset-positions.ts
@@ -56,7 +56,6 @@ export const calculateAssetPositions = (
trimLeft: asset.mediaFrame,
volume: [],
playbackRate: asset.playbackRate,
- allowAmplificationDuringRender: asset.allowAmplificationDuringRender,
toneFrequency: asset.toneFrequency,
audioStartFrame: asset.audioStartFrame,
});
diff --git a/packages/renderer/src/assets/ffmpeg-volume-expression.ts b/packages/renderer/src/assets/ffmpeg-volume-expression.ts
index 4167bb7df9..578a5a1663 100644
--- a/packages/renderer/src/assets/ffmpeg-volume-expression.ts
+++ b/packages/renderer/src/assets/ffmpeg-volume-expression.ts
@@ -87,20 +87,17 @@ export const ffmpegVolumeExpression = ({
volume,
fps,
trimLeft,
- allowAmplificationDuringRender,
}: {
volume: AssetVolume;
trimLeft: number;
fps: number;
- allowAmplificationDuringRender: boolean;
}): FfmpegVolumeExpression => {
- const maxVolume = allowAmplificationDuringRender ? Infinity : 1;
// If it's a static volume, we return it and tell
// FFMPEG it only has to evaluate it once
if (typeof volume === 'number') {
return {
eval: 'once',
- value: String(Math.min(maxVolume, volume)),
+ value: String(volume),
};
}
@@ -109,7 +106,6 @@ export const ffmpegVolumeExpression = ({
volume: volume[0],
fps,
trimLeft,
- allowAmplificationDuringRender,
});
}
@@ -126,9 +122,7 @@ export const ffmpegVolumeExpression = ({
const volumeMap: {[volume: string]: number[]} = {};
paddedVolume.forEach((baseVolume, frame) => {
// Adjust volume based on how many other tracks have not yet finished
- const actualVolume = roundVolumeToAvoidStackOverflow(
- Math.min(maxVolume, baseVolume),
- );
+ const actualVolume = roundVolumeToAvoidStackOverflow(baseVolume);
if (!volumeMap[actualVolume]) {
volumeMap[actualVolume] = [];
}
diff --git a/packages/renderer/src/assets/types.ts b/packages/renderer/src/assets/types.ts
index 45d7989b02..d07e7f4c28 100644
--- a/packages/renderer/src/assets/types.ts
+++ b/packages/renderer/src/assets/types.ts
@@ -14,7 +14,6 @@ export type UnsafeAsset = Omit<
volume: number[];
id: string;
playbackRate: number;
- allowAmplificationDuringRender: boolean;
toneFrequency: number | null;
};
diff --git a/packages/renderer/src/stringify-ffmpeg-filter.ts b/packages/renderer/src/stringify-ffmpeg-filter.ts
index a54d412b5f..30157e243d 100644
--- a/packages/renderer/src/stringify-ffmpeg-filter.ts
+++ b/packages/renderer/src/stringify-ffmpeg-filter.ts
@@ -215,7 +215,6 @@ export const stringifyFfmpegFilter = ({
volume,
fps,
trimLeft: actualTrimLeft,
- allowAmplificationDuringRender: asset.allowAmplificationDuringRender,
});
const padAtEnd = chunkLengthInSeconds - audibleDuration - startInVideoSeconds;
diff --git a/packages/renderer/src/test/asset-calculation.test.tsx b/packages/renderer/src/test/asset-calculation.test.tsx
index 84219bbb36..f294156338 100644
--- a/packages/renderer/src/test/asset-calculation.test.tsx
+++ b/packages/renderer/src/test/asset-calculation.test.tsx
@@ -41,7 +41,6 @@ test('Should be able to collect assets', async () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -63,7 +62,6 @@ test('Should get multiple assets', async () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -75,7 +73,6 @@ test('Should get multiple assets', async () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -101,7 +98,6 @@ test('Should handle jumps inbetween', async () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -113,7 +109,6 @@ test('Should handle jumps inbetween', async () => {
trimLeft: 21,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -136,7 +131,6 @@ test('Should support sequencing', async () => {
trimLeft: 20,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 20,
});
@@ -169,7 +163,6 @@ test('Should calculate volumes correctly', async () => {
interpolate(i, [0, 4], [0, 1], {extrapolateRight: 'clamp'}),
)
.filter((f) => f > 0),
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
});
@@ -212,7 +205,6 @@ test('Should calculate startFrom correctly', async () => {
}),
)
.filter((i) => i > 0),
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 100,
});
diff --git a/packages/renderer/src/test/asset-compression.test.ts b/packages/renderer/src/test/asset-compression.test.ts
index f0b8119aa2..c0a421b4bd 100644
--- a/packages/renderer/src/test/asset-compression.test.ts
+++ b/packages/renderer/src/test/asset-compression.test.ts
@@ -15,7 +15,6 @@ test('Should compress and uncompress assets', () => {
playbackRate: 1,
type: 'video' as const,
volume: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
@@ -29,7 +28,6 @@ test('Should compress and uncompress assets', () => {
playbackRate: 1,
type: 'video' as const,
volume: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
@@ -56,7 +54,6 @@ test('Should compress and uncompress assets', () => {
trimLeft: 0,
type: 'video',
volume: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
diff --git a/packages/renderer/src/test/dont-skip-assets.test.ts b/packages/renderer/src/test/dont-skip-assets.test.ts
index b3f2b0da6f..86d6b1d9b5 100644
--- a/packages/renderer/src/test/dont-skip-assets.test.ts
+++ b/packages/renderer/src/test/dont-skip-assets.test.ts
@@ -23,7 +23,6 @@ const mock: TRenderAsset[][] = new Array(2934)
volume: 1,
playbackRate: 1,
mediaFrame: 0,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
}
@@ -36,7 +35,6 @@ const mock: TRenderAsset[][] = new Array(2934)
volume: 1,
playbackRate: 1,
mediaFrame: k,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
@@ -59,7 +57,6 @@ test('Dont skip assets', () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
@@ -72,7 +69,6 @@ test('Dont skip assets', () => {
trimLeft: 0,
volume: 1,
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
diff --git a/packages/renderer/src/test/ffmpeg-filters.test.ts b/packages/renderer/src/test/ffmpeg-filters.test.ts
index 4106d29c70..59a300ae7b 100644
--- a/packages/renderer/src/test/ffmpeg-filters.test.ts
+++ b/packages/renderer/src/test/ffmpeg-filters.test.ts
@@ -16,7 +16,6 @@ const baseAsset: MediaAsset = {
volume: 1,
id: '1',
playbackRate: 1,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
};
@@ -325,7 +324,6 @@ test('Should calculate pad correctly with a lot of playbackRate', () => {
trimLeft: 0,
startInVideo: 0,
playbackRate: 16,
- allowAmplificationDuringRender: false,
toneFrequency: null,
audioStartFrame: 0,
},
diff --git a/packages/renderer/src/test/ffmpeg-volume-expression.test.ts b/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
index a42a7c4606..819dd792c2 100644
--- a/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
+++ b/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
@@ -8,7 +8,6 @@ test('Simple expression', () => {
volume: 0.5,
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'once',
@@ -22,7 +21,6 @@ test('Simple expression with volume multiplier', () => {
volume: 0.5,
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'once',
@@ -36,7 +34,6 @@ test('Complex expression with volume multiplier', () => {
volume: [0, 1],
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'frame',
@@ -50,7 +47,6 @@ test('Should respect trimLeft multiplier', () => {
volume: [0, 1],
fps: 30,
trimLeft: 0.5,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'frame',
@@ -67,7 +63,6 @@ test('Really complex volume expression', () => {
volume: [0, 0.25, 0.5, 0.99, 0.99, 0.99, 0.99, 1, 1, 1, 1, 1],
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'frame',
@@ -80,7 +75,6 @@ test('Should use 0 as else statement', () => {
ffmpegVolumeExpression({
volume: [0, 0, 0, 1, 1],
fps: 30,
- allowAmplificationDuringRender: false,
trimLeft: 0,
}),
).toEqual({
@@ -95,7 +89,6 @@ test('Simple expression - should not be higher than 1', () => {
volume: 2,
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'once',
@@ -109,7 +102,6 @@ test('Complex expression - should be higher than 1 if allowed', () => {
volume: [0.5, 2],
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: true,
}),
).toEqual({
eval: 'frame',
@@ -123,7 +115,6 @@ test('Should simplify an expression', () => {
volume: [0, 1, 1, 1, 0, 1],
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
}),
).toEqual({
eval: 'frame',
@@ -142,7 +133,6 @@ test('Should stay under half 8000 windows character limit', () => {
}),
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
});
expect(expression.value.length).toBeLessThan(4000);
@@ -157,7 +147,6 @@ test('Last volume should be default case', () => {
}),
fps: 30,
trimLeft: 0,
- allowAmplificationDuringRender: false,
});
expect(expression).toEqual({
eval: 'frame',