🎥 Make videos programmatically with React
Move shared pitch shifter from core to media
JonnyBurger47b74cc84bb5
diff --git a/bun.lock b/bun.lockindex 8723c81894..bde8af5817 100644--- a/bun.lock+++ b/bun.lock@@ -2791,6 +2791,7 @@"@mediabunny/flac-encoder": "catalog:","@mediabunny/mp3-encoder": "catalog:","@remotion/licensing": "workspace:*",+ "@remotion/media": "workspace:*","mediabunny": "catalog:","remotion": "workspace:*",},@@ -2798,7 +2799,6 @@"@react-three/fiber": "catalog:","@remotion/effects": "workspace:*","@remotion/eslint-config-internal": "workspace:*",- "@remotion/media": "workspace:*","@remotion/paths": "workspace:*","@remotion/player": "workspace:*","@remotion/shapes": "workspace:*",diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex c43405a4dd..51d3c6e813 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -11,7 +11,6 @@ import {SharedAudioTagsContextProvider,type ScheduleAudioNodeOptions,} from './audio/shared-audio-tags.js';-import {StreamingPitchShifter} from './audio/streaming-pitch-shifter.js';import type {RemotionAudioContextState} from './audio/use-audio-context.js';import {useFrameForVolumeProp,@@ -299,7 +298,6 @@ const compositionSelectorRef = createRef<{// Mark them as Internals so use don't assume this is public// API and are less likely to use itexport const Internals = {- StreamingPitchShifter,AbsoluteFillElement,MaxMediaCacheSizeContext,getMediabunnyInputResourceKey,diff --git a/packages/media/bundle.ts b/packages/media/bundle.tsindex 23a4d1c63d..7fe416b0c7 100644--- a/packages/media/bundle.ts+++ b/packages/media/bundle.ts@@ -6,7 +6,8 @@ if (process.env.NODE_ENV !== 'production') {}console.time('Generated.');const output = await build({- entrypoints: ['src/index.ts'],+ entrypoints: ['src/index.ts', 'src/internal.ts'],+ splitting: true,naming: '[name].mjs',external: ['remotion',diff --git a/packages/media/package.json b/packages/media/package.jsonindex d67bfd8d88..544dd7aa02 100644--- a/packages/media/package.json+++ b/packages/media/package.json@@ -51,7 +51,12 @@"module": "./dist/esm/index.mjs","import": "./dist/esm/index.mjs"},- "./package.json": "./package.json"+ "./package.json": "./package.json",+ "./internal": {+ "types": "./dist/internal.d.ts",+ "module": "./dist/esm/internal.mjs",+ "import": "./dist/esm/internal.mjs"+ }},"description": "Experimental WebCodecs-based media tags","homepage": "https://remotion.dev/docs/media"diff --git a/packages/media/src/audio/pitch-shift.ts b/packages/media/src/audio/pitch-shift.tsindex c203b03b35..fce2ea844e 100644--- a/packages/media/src/audio/pitch-shift.ts+++ b/packages/media/src/audio/pitch-shift.ts@@ -1,5 +1,5 @@-import {Internals} from 'remotion';import type {AudioBufferSlice} from '../make-iterator-with-priming';+import {StreamingPitchShifter} from './streaming-pitch-shifter';const getPlanarSlice = (slice: AudioBufferSlice) => {const {buffer} = slice.buffer;@@ -60,8 +60,7 @@ export async function* pitchShiftAudioIterator({return;}- let shifter: InstanceType<typeof Internals.StreamingPitchShifter> | null =- null;+ let shifter: StreamingPitchShifter | null = null;let sampleRate = 0;let numberOfChannels = 0;let segmentStart = 0;@@ -113,7 +112,7 @@ export async function* pitchShiftAudioIterator({segmentStart = slice.timelineTimestamp;segmentInputFrames = 0;segmentOutputFrames = 0;- shifter = new Internals.StreamingPitchShifter({+ shifter = new StreamingPitchShifter({numberOfChannels,sampleRate,toneFrequency,diff --git a/packages/core/src/audio/streaming-pitch-shifter.ts b/packages/media/src/audio/streaming-pitch-shifter.tssimilarity index 100%rename from packages/core/src/audio/streaming-pitch-shifter.tsrename to packages/media/src/audio/streaming-pitch-shifter.tsdiff --git a/packages/media/src/internal.ts b/packages/media/src/internal.tsnew file mode 100644index 0000000000..1c3243025d--- /dev/null+++ b/packages/media/src/internal.ts@@ -0,0 +1,2 @@+// Internal entry point for other Remotion packages.+export {StreamingPitchShifter} from './audio/streaming-pitch-shifter';diff --git a/packages/media/src/test/pitch-shift.test.ts b/packages/media/src/test/pitch-shift.test.tsindex e01954c469..dbca756d9e 100644--- a/packages/media/src/test/pitch-shift.test.ts+++ b/packages/media/src/test/pitch-shift.test.ts@@ -1,5 +1,5 @@-import {Internals} from 'remotion';import {expect, test} from 'vitest';+import {StreamingPitchShifter} from '../audio/streaming-pitch-shifter';const makeSine = ({frequency,@@ -59,7 +59,7 @@ test('changes pitch while preserving the sample count', () => {});for (const toneFrequency of [0.75, 1.5]) {- const shifter = new Internals.StreamingPitchShifter({+ const shifter = new StreamingPitchShifter({numberOfChannels: 1,sampleRate,toneFrequency,diff --git a/packages/web-renderer/bundle.ts b/packages/web-renderer/bundle.tsindex 8446593e25..a3dbfdf6bd 100644--- a/packages/web-renderer/bundle.ts+++ b/packages/web-renderer/bundle.ts@@ -6,6 +6,7 @@ await buildPackage({esm: 'build',},external: [+ '@remotion/media/internal','remotion','react','react-dom',diff --git a/packages/web-renderer/package.json b/packages/web-renderer/package.jsonindex 59d7609fc7..953509f4c8 100644--- a/packages/web-renderer/package.json+++ b/packages/web-renderer/package.json@@ -24,7 +24,8 @@"@mediabunny/flac-encoder": "catalog:","@remotion/licensing": "workspace:*","remotion": "workspace:*",- "mediabunny": "catalog:"+ "mediabunny": "catalog:",+ "@remotion/media": "workspace:*"},"devDependencies": {"@remotion/effects": "workspace:*",@@ -32,7 +33,6 @@"@remotion/eslint-config-internal": "workspace:*","@remotion/paths": "workspace:*","@remotion/player": "workspace:*",- "@remotion/media": "workspace:*","@remotion/shapes": "workspace:*","@remotion/three": "workspace:*","@remotion/transitions": "workspace:*",diff --git a/packages/web-renderer/src/audio.ts b/packages/web-renderer/src/audio.tsindex c3f13a28da..3dabd93a16 100644--- a/packages/web-renderer/src/audio.ts+++ b/packages/web-renderer/src/audio.ts@@ -1,4 +1,5 @@-import {Internals, type TRenderAsset} from 'remotion';+import {StreamingPitchShifter} from '@remotion/media/internal';+import type {TRenderAsset} from 'remotion';const TARGET_NUMBER_OF_CHANNELS = 2;@@ -9,7 +10,7 @@ type PendingAudioFrame = {};type PitchShiftState = {- shifter: InstanceType<typeof Internals.StreamingPitchShifter>;+ shifter: StreamingPitchShifter;pending: {frame: PendingAudioFrame; written: number}[];};@@ -115,7 +116,7 @@ export const createAudioMixer = ({let state = shifters.get(asset.id);if (!state) {state = {- shifter: new Internals.StreamingPitchShifter({+ shifter: new StreamingPitchShifter({numberOfChannels: TARGET_NUMBER_OF_CHANNELS,sampleRate,toneFrequency: asset.toneFrequency,