Skip to content

πŸŽ₯ Make videos programmatically with React

fix(media): preserve existing pitch behavior by default

JonnyBurger6a4001261be2
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdx
index 7f77caef6a..047e13ef8b 100644
--- a/packages/docs/docs/media/audio.mdx
+++ b/packages/docs/docs/media/audio.mdx
@@ -202,7 +202,7 @@ export const MyComposition = () => {
:::note
Playing audio in reverse is not supported.
-Audio pitch is preserved by default when changing `playbackRate`. Pass `preservePitch={false}` to let the pitch change with the speed.
+Changing `playbackRate` also changes the audio pitch by default. Pass [`preservePitch={true}`](#preservepitch) to preserve the original pitch.
:::
### `loop?`<AvailableFrom v="3.2.29" />
@@ -228,7 +228,7 @@ It has no effect on numeric `volume` values, including `volume={interpolate(fram
### `preservePitch?`<AvailableFrom v="4.0.538" />
-Preserves the audio pitch when changing [`playbackRate`](#playbackrate), including playback speed inherited from parent [`<Sequence>`](/docs/sequence#playbackrate) components. Defaults to `true`. Applies during preview, [server-side rendering](/docs/ssr), and [client-side rendering](/docs/client-side-rendering).
+Preserves the audio pitch when changing [`playbackRate`](#playbackrate), including playback speed inherited from parent [`<Sequence>`](/docs/sequence#playbackrate) components. Defaults to `false`. Applies during preview, [server-side rendering](/docs/ssr), and [client-side rendering](/docs/client-side-rendering).
```tsx twoslash title="MyComposition.tsx"
import {Audio} from '@remotion/media';
@@ -239,13 +239,13 @@ export const MyComposition = () => (
);
```
-Before v4.0.538, changing `playbackRate` also changed the pitch in the Mediabunny and WebCodecs path. Set `preservePitch={false}` to retain that behavior: for example, `playbackRate={2}` doubles the pitch.
+The default retains the existing behavior of the Mediabunny and WebCodecs path: for example, `playbackRate={2}` doubles the pitch. Set `preservePitch={true}` to change speed without changing pitch. If you already compensate for speed with `toneFrequency`, remove that compensation when enabling `preservePitch` to avoid applying it twice.
[`toneFrequency`](#tonefrequency) remains an independent pitch multiplier. For example, `toneFrequency={0.8}` lowers the pitch by 20% even when preserving pitch at a different speed. Keep `preservePitch` and the authored playback speed constant for each asset during rendering.
In the Mediabunny and WebCodecs path, this prop does not compensate for the Studio's or [`<Player>`](/docs/player/player)'s playback speed. It only compensates for speed changes authored in the composition.
-When [falling back to a native media component](/docs/media/fallback), this prop is forwarded to [`<Html5Audio>`](/docs/html5-audio#preservepitch). An explicit `fallbackHtml5AudioProps.preservePitch` takes precedence. See the fallback component's documentation for server-side support. Native fallbacks do not apply `toneFrequency` during preview.
+When [falling back to a native media component](/docs/media/fallback), this prop is forwarded to [`<Html5Audio>`](/docs/html5-audio#preservepitch). An explicit `fallbackHtml5AudioProps.preservePitch` takes precedence. When neither setting is provided, the native fallback retains its existing default of preserving pitch. See the fallback component's documentation for server-side support. Native fallbacks do not apply `toneFrequency` during preview.
### `muted?`
diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdx
index c9c6595da2..d78d58baf5 100644
--- a/packages/docs/docs/media/video.mdx
+++ b/packages/docs/docs/media/video.mdx
@@ -251,12 +251,12 @@ export const MyComposition = () => {
:::note
Playing a video in reverse is not supported.
-Audio pitch is preserved by default when changing `playbackRate`. Pass `preservePitch={false}` to let the pitch change with the speed.
+Changing `playbackRate` also changes the audio pitch by default. Pass [`preservePitch={true}`](#preservepitch) to preserve the original pitch.
:::
### `preservePitch?`<AvailableFrom v="4.0.538" />
-Preserves the audio pitch when changing [`playbackRate`](#playbackrate), including playback speed inherited from parent [`<Sequence>`](/docs/sequence#playbackrate) components. Defaults to `true`. Applies during preview, [server-side rendering](/docs/ssr), and [client-side rendering](/docs/client-side-rendering).
+Preserves the audio pitch when changing [`playbackRate`](#playbackrate), including playback speed inherited from parent [`<Sequence>`](/docs/sequence#playbackrate) components. Defaults to `false`. Applies during preview, [server-side rendering](/docs/ssr), and [client-side rendering](/docs/client-side-rendering).
```tsx twoslash title="MyComposition.tsx"
import {Video} from '@remotion/media';
@@ -267,13 +267,13 @@ export const MyComposition = () => (
);
```
-Before v4.0.538, changing `playbackRate` also changed the pitch in the Mediabunny and WebCodecs path. Set `preservePitch={false}` to retain that behavior: for example, `playbackRate={2}` doubles the pitch.
+The default retains the existing behavior of the Mediabunny and WebCodecs path: for example, `playbackRate={2}` doubles the pitch. Set `preservePitch={true}` to change speed without changing pitch. If you already compensate for speed with `toneFrequency`, remove that compensation when enabling `preservePitch` to avoid applying it twice.
[`toneFrequency`](#tonefrequency) remains an independent pitch multiplier. For example, `toneFrequency={0.8}` lowers the pitch by 20% even when preserving pitch at a different speed. Keep `preservePitch` and the authored playback speed constant for each asset during rendering.
In the Mediabunny and WebCodecs path, this prop does not compensate for the Studio's or [`<Player>`](/docs/player/player)'s playback speed. It only compensates for speed changes authored in the composition.
-When [falling back to a native media component](/docs/media/fallback), this prop is forwarded to [`<OffthreadVideo>`](/docs/offthreadvideo#preservepitch). An explicit `fallbackOffthreadVideoProps.preservePitch` takes precedence. See the fallback component's documentation for server-side support. Native fallbacks do not apply `toneFrequency` during preview.
+When [falling back to a native media component](/docs/media/fallback), this prop is forwarded to [`<OffthreadVideo>`](/docs/offthreadvideo#preservepitch). An explicit `fallbackOffthreadVideoProps.preservePitch` takes precedence. When neither setting is provided, the native fallback retains its existing default of preserving pitch. See the fallback component's documentation for server-side support. Native fallbacks do not apply `toneFrequency` during preview.
### `muted?`
diff --git a/packages/docs/docs/video-tags.mdx b/packages/docs/docs/video-tags.mdx
index 0e17e6d1f3..7be9b716dd 100644
--- a/packages/docs/docs/video-tags.mdx
+++ b/packages/docs/docs/video-tags.mdx
@@ -29,14 +29,14 @@ The comparison below shows when a fallback or alternative may be relevant.
| **HLS Support** | [βœ… Supported](/docs/hls) | [Chrome v142+, only during preview](/docs/hls) | [Only during preview](/docs/hls) |
| **CORS required** | Yes | No | No |
| **Loopable** | βœ… | ❌ | βœ… |
-| **`playbackRate`** <br/> (Speed Change) | βœ…, audio pitch is preserved by default | βœ…, audio pitch is preserved by default | βœ…, audio pitch is preserved by default |
+| **`playbackRate`** <br/> (Speed Change) | βœ…, audio pitch changes by default; opt in with `preservePitch` | βœ…, audio pitch is preserved by default | βœ…, audio pitch is preserved by default |
| **`toneFrequency`** <br/> (Pitch Change) | βœ… | Only during server-side rendering | Only during server-side rendering |
| **[Three.js texture](/docs/videos/as-threejs-texture)** | [Snippet](/docs/videos/as-threejs-texture) - works best | [`useOffthreadVideoTexture()`](/docs/use-offthread-video-texture) | [ `useVideoTexture()` ](/docs/use-video-texture) |
| **[Client-side rendering](/docs/client-side-rendering)** | βœ… | ❌ | ❌ |
-`playbackRate` changes the media speed with all three components. `<Video>` and `<Audio>` from `@remotion/media` preserve pitch by default in preview and rendering. Set `preservePitch={false}` to let pitch change with the speed.
+`playbackRate` changes the media speed with all three components. `<Video>` and `<Audio>` from `@remotion/media` change pitch with the speed by default. Set `preservePitch={true}` to preserve pitch in preview and rendering.
-`<OffthreadVideo>`, `<Html5Video>`, and `<Html5Audio>` preserve audio pitch by default during preview and server-side rendering. If `@remotion/media` falls back to one of these components, the fallback component's behavior applies.
+`<OffthreadVideo>`, `<Html5Video>`, and `<Html5Audio>` preserve audio pitch by default during preview and server-side rendering. If `@remotion/media` falls back to one of these components, the fallback component's behavior applies unless `preservePitch` or its fallback override is explicitly set.
## Using a different tag in preview and rendering
diff --git a/packages/media/src/audio/audio-for-preview.tsx b/packages/media/src/audio/audio-for-preview.tsx
index 4078f7d782..6825bc2866 100644
--- a/packages/media/src/audio/audio-for-preview.tsx
+++ b/packages/media/src/audio/audio-for-preview.tsx
@@ -45,7 +45,7 @@ type NewAudioForPreviewProps = {
readonly showInTimeline: boolean;
readonly _remotionInternalStack: string | null;
readonly disallowFallbackToHtml5Audio: boolean;
- readonly preservePitch: boolean;
+ readonly preservePitch: boolean | null;
readonly toneFrequency: number | undefined;
readonly audioStreamIndex: number | undefined;
readonly fallbackHtml5AudioProps: FallbackHtml5AudioProps | undefined;
@@ -434,7 +434,9 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({
pauseWhenBuffering={fallbackHtml5AudioProps?.pauseWhenBuffering}
crossOrigin={fallbackHtml5AudioProps?.crossOrigin}
{...fallbackHtml5AudioProps}
- preservePitch={fallbackHtml5AudioProps?.preservePitch ?? preservePitch}
+ preservePitch={
+ fallbackHtml5AudioProps?.preservePitch ?? preservePitch ?? true
+ }
/>
);
}
@@ -464,7 +466,7 @@ type InnerAudioProps = {
readonly trimBefore?: number | undefined;
readonly _remotionInternalStack: string | null;
readonly disallowFallbackToHtml5Audio?: boolean;
- readonly preservePitch: boolean;
+ readonly preservePitch: boolean | null;
readonly toneFrequency?: number;
readonly audioStreamIndex?: number;
readonly fallbackHtml5AudioProps?: FallbackHtml5AudioProps;
diff --git a/packages/media/src/audio/audio-for-rendering.tsx b/packages/media/src/audio/audio-for-rendering.tsx
index 1861e5bb67..29d97fdce0 100644
--- a/packages/media/src/audio/audio-for-rendering.tsx
+++ b/packages/media/src/audio/audio-for-rendering.tsx
@@ -33,7 +33,7 @@ export const AudioForRendering: React.FC<AudioProps> = ({
name,
disallowFallbackToHtml5Audio,
toneFrequency,
- preservePitch = true,
+ preservePitch,
trimAfter,
trimBefore,
onError,
@@ -335,7 +335,9 @@ export const AudioForRendering: React.FC<AudioProps> = ({
acceptableTimeShiftInSeconds={
fallbackHtml5AudioProps?.acceptableTimeShiftInSeconds
}
- preservePitch={fallbackHtml5AudioProps?.preservePitch ?? preservePitch}
+ preservePitch={
+ fallbackHtml5AudioProps?.preservePitch ?? preservePitch ?? true
+ }
name={name}
showInTimeline={showInTimeline}
/>
diff --git a/packages/media/src/audio/audio.tsx b/packages/media/src/audio/audio.tsx
index 463bbbac7b..1f22d8a4d9 100644
--- a/packages/media/src/audio/audio.tsx
+++ b/packages/media/src/audio/audio.tsx
@@ -52,7 +52,7 @@ export const audioSchema: InteractivitySchema = {
},
preservePitch: {
type: 'boolean',
- default: true,
+ default: false,
description: 'Preserve pitch',
keyframable: false,
},
@@ -234,7 +234,7 @@ const AudioInner: React.FC<
<AudioForPreview
name={name}
{...otherProps}
- preservePitch={props.preservePitch ?? true}
+ preservePitch={props.preservePitch ?? null}
trimAfter={effectiveTrimAfter}
style={premountingStyle}
_remotionInternalStack={sourceStack}
diff --git a/packages/media/src/audio/props.ts b/packages/media/src/audio/props.ts
index 831aa56839..908161e4a5 100644
--- a/packages/media/src/audio/props.ts
+++ b/packages/media/src/audio/props.ts
@@ -27,7 +27,7 @@ export type AudioProps = {
volume?: VolumeProp;
loopVolumeCurveBehavior?: LoopVolumeCurveBehavior;
playbackRate?: number;
- /** Keep the original pitch when changing playback speed. Default: true. */
+ /** Keep the original pitch when changing playback speed. Default: false. */
preservePitch?: boolean;
muted?: boolean;
style?: React.CSSProperties;
diff --git a/packages/media/src/test/pitch-shift-preview.test.tsx b/packages/media/src/test/pitch-shift-preview.test.tsx
index 4ab1f16a5d..d700da8638 100644
--- a/packages/media/src/test/pitch-shift-preview.test.tsx
+++ b/packages/media/src/test/pitch-shift-preview.test.tsx
@@ -178,7 +178,7 @@ test('Audio and Video update pitch while preserving authored speed changes', asy
};
expect(getScheduledFrequency() * playbackRate * parentRate).toBeCloseTo(
- 440 * (preservePitch === false ? playbackRate * parentRate : 1),
+ 440 * (preservePitch ? 1 : playbackRate * parentRate),
-1,
);
createdNodes.length = 0;
@@ -191,7 +191,7 @@ test('Audio and Video update pitch while preserving authored speed changes', asy
() => createdNodes.filter((node) => node.buffer !== null).length >= 8,
);
expect(getScheduledFrequency() * playbackRate * parentRate).toBeCloseTo(
- 660 * (preservePitch === false ? playbackRate * parentRate : 1),
+ 660 * (preservePitch ? 1 : playbackRate * parentRate),
-1,
);
} finally {
diff --git a/packages/media/src/video/props.ts b/packages/media/src/video/props.ts
index fab741123e..5b2aec0727 100644
--- a/packages/media/src/video/props.ts
+++ b/packages/media/src/video/props.ts
@@ -59,7 +59,7 @@ type OptionalVideoProps = {
loopVolumeCurveBehavior: LoopVolumeCurveBehavior;
onVideoFrame: OnVideoFrame | undefined;
playbackRate: number;
- /** Keep the original pitch when changing playback speed. Default: true. */
+ /** Keep the original pitch when changing playback speed. Default: false. */
preservePitch: boolean;
muted: boolean;
delayRenderRetries: number | null;
@@ -104,8 +104,9 @@ export type NativeVideoProps = Omit<
export type InnerVideoProps = MandatoryVideoProps &
OuterVideoProps &
- Omit<OptionalVideoProps, 'effects'> &
+ Omit<OptionalVideoProps, 'effects' | 'preservePitch'> &
NativeVideoProps & {
+ preservePitch: boolean | null;
effects: EffectDefinitionAndStack<unknown>[];
_remotionInternalStack: string | undefined;
};
diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsx
index 47f47ae3d9..ed8cbb8c3a 100644
--- a/packages/media/src/video/video-for-preview.tsx
+++ b/packages/media/src/video/video-for-preview.tsx
@@ -57,7 +57,7 @@ type VideoForPreviewProps = NativeVideoProps & {
readonly src: string;
readonly style: React.CSSProperties | undefined;
readonly playbackRate: number;
- readonly preservePitch: boolean;
+ readonly preservePitch: boolean | null;
readonly toneFrequency: number;
readonly logLevel: LogLevel;
readonly className: string | undefined;
@@ -594,7 +594,7 @@ const VideoForPreviewAssertedShowing: React.FC<
_remotionInternalStack={_remotionInternalStack ?? undefined}
{...fallbackOffthreadVideoProps}
preservePitch={
- fallbackOffthreadVideoProps?.preservePitch ?? preservePitch
+ fallbackOffthreadVideoProps?.preservePitch ?? preservePitch ?? true
}
/>
);
diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsx
index 5ca1af82a6..4620b8b787 100644
--- a/packages/media/src/video/video-for-rendering.tsx
+++ b/packages/media/src/video/video-for-rendering.tsx
@@ -54,7 +54,7 @@ type InnerVideoProps = NativeVideoProps & {
readonly disallowFallbackToOffthreadVideo: boolean;
readonly _remotionInternalStack: string | undefined;
readonly toneFrequency: number;
- readonly preservePitch: boolean;
+ readonly preservePitch: boolean | null;
readonly trimBeforeValue: number | undefined;
readonly trimAfterValue: number | undefined;
readonly headless: boolean;
@@ -536,7 +536,7 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
trimBefore={trimBeforeValue}
useWebAudioApi={fallbackOffthreadVideoProps?.useWebAudioApi ?? false}
preservePitch={
- fallbackOffthreadVideoProps?.preservePitch ?? preservePitch
+ fallbackOffthreadVideoProps?.preservePitch ?? preservePitch ?? true
}
startFrom={undefined}
endAt={undefined}
diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsx
index 1c2ec5a838..97aef749f8 100644
--- a/packages/media/src/video/video.tsx
+++ b/packages/media/src/video/video.tsx
@@ -58,7 +58,7 @@ export const videoSchema: InteractivitySchema = {
},
preservePitch: {
type: 'boolean',
- default: true,
+ default: false,
description: 'Preserve pitch',
keyframable: false,
},
@@ -216,7 +216,7 @@ const InnerVideo: React.FC<
onVideoFrame={onVideoFrame}
playbackRate={playbackRate}
toneFrequency={toneFrequency ?? 1}
- preservePitch={preservePitch ?? true}
+ preservePitch={preservePitch}
src={src}
style={style}
volume={volume}
@@ -454,7 +454,7 @@ const VideoInner: React.FC<
trimBefore={trimBefore}
volume={volume ?? 1}
toneFrequency={toneFrequency ?? 1}
- preservePitch={preservePitch ?? true}
+ preservePitch={preservePitch ?? null}
_remotionInternalStack={sourceStack}
debugOverlay={debugOverlay ?? false}
headless={headless ?? false}
diff --git a/packages/web-renderer/src/test/fixtures/pitch-shift-audio.tsx b/packages/web-renderer/src/test/fixtures/pitch-shift-audio.tsx
index 61c17bfd7a..cbc7f0b44c 100644
--- a/packages/web-renderer/src/test/fixtures/pitch-shift-audio.tsx
+++ b/packages/web-renderer/src/test/fixtures/pitch-shift-audio.tsx
@@ -64,6 +64,7 @@ const Component: React.FC = () => {
loop
trimBefore={3}
playbackRate={1.25}
+ preservePitch
/>
</Sequence>
<Sequence from={45} durationInFrames={9}>
diff --git a/packages/web-renderer/src/test/pitch-shift-audio.test.tsx b/packages/web-renderer/src/test/pitch-shift-audio.test.tsx
index 471cbeb29e..3fb0734ebd 100644
--- a/packages/web-renderer/src/test/pitch-shift-audio.test.tsx
+++ b/packages/web-renderer/src/test/pitch-shift-audio.test.tsx
@@ -280,7 +280,7 @@ test.each([0.01, 2])(
);
// KINO-7177: measure the encoded result, including inherited speed and opt-out.
-test.each([true, false])(
+test.each([true, undefined])(
'exports clip speed with preservePitch=%s',
async (preservePitch) => {
const src = makeToneWav();