🎥 Make videos programmatically with React
nice
Jonny Burgerdf4d7cf3a67b
diff --git a/packages/docs/components/AudioWaveformExamples.tsx b/packages/docs/components/AudioWaveformExamples.tsxindex fad6709af0..6bcc096898 100644--- a/packages/docs/components/AudioWaveformExamples.tsx+++ b/packages/docs/components/AudioWaveformExamples.tsx@@ -1,18 +1,26 @@import {- smoothenSvgPath,+ createSmoothSvgPath,useAudioData,visualizeAudioWaveform,} from '@remotion/media-utils';import {Player} from '@remotion/player';import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import voice from './voice-short.mp3';+import {+ AbsoluteFill,+ Audio,+ staticFile,+ useCurrentFrame,+ useVideoConfig,+} from 'remotion';++const src = staticFile('voice-short.mp3');const BaseExample: React.FC = () => {const frame = useCurrentFrame();const {fps} = useVideoConfig();- const audioDataVoice = useAudioData(voice);- const {width, height} = useVideoConfig();+ const audioDataVoice = useAudioData(src);+ const {width} = useVideoConfig();+ const height = 300;if (!audioDataVoice) {return null;@@ -27,18 +35,18 @@ const BaseExample: React.FC = () => {channel: 0,});- const p = smoothenSvgPath({+ const p = createSmoothSvgPath({points: waveform.map((x, i) => {return {x: (i / (waveform.length - 1)) * width,- y: (x - 0.5) * 300 + height / 2,+ y: x * height + height / 2,};}),});return (<div style={{flex: 1}}>- <Audio src={voice} />+ <Audio src={src} /><AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}><svgstyle={{backgroundColor: '#0B84F3'}}@@ -56,8 +64,9 @@ const BaseExample: React.FC = () => {const MovingExample: React.FC = () => {const frame = useCurrentFrame();const {fps} = useVideoConfig();- const audioDataVoice = useAudioData(voice);- const {width, height} = useVideoConfig();+ const audioDataVoice = useAudioData(src);+ const {width} = useVideoConfig();+ const height = 300;if (!audioDataVoice) {return null;@@ -72,18 +81,18 @@ const MovingExample: React.FC = () => {channel: 0,});- const p = smoothenSvgPath({+ const p = createSmoothSvgPath({points: waveform.map((x, i) => {return {x: (i / (waveform.length - 1)) * width,- y: (x - 0.5) * 300 + height / 2,+ y: x * height + height / 2,};}),});return (<div style={{flex: 1}}>- <Audio src={voice} />+ <Audio src={src} /><AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}><svgstyle={{backgroundColor: '#0B84F3'}}@@ -101,8 +110,9 @@ const MovingExample: React.FC = () => {const PosterizedExample: React.FC = () => {const frame = useCurrentFrame();const {fps} = useVideoConfig();- const audioDataVoice = useAudioData(voice);- const {width, height} = useVideoConfig();+ const audioDataVoice = useAudioData(src);+ const {width} = useVideoConfig();+ const height = 300;if (!audioDataVoice) {return null;@@ -117,18 +127,18 @@ const PosterizedExample: React.FC = () => {channel: 0,});- const p = smoothenSvgPath({+ const p = createSmoothSvgPath({points: waveform.map((x, i) => {return {x: (i / (waveform.length - 1)) * width,- y: (x - 0.5) * 300 + height / 2,+ y: x * height + height / 2,};}),});return (<div style={{flex: 1}}>- <Audio src={voice} />+ <Audio src={src} /><AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}><svgstyle={{backgroundColor: ' #0B84F3'}}@@ -165,8 +175,8 @@ export const AudioWaveFormExample: React.FC<{<div><Playercomponent={component}- compositionWidth={2160}- compositionHeight={1080}+ compositionWidth={1080}+ compositionHeight={300}controlsdurationInFrames={300}fps={30}diff --git a/packages/docs/components/TableOfContents/media-utils.tsx b/packages/docs/components/TableOfContents/media-utils.tsxindex e0fd7709bb..f4699808f3 100644--- a/packages/docs/components/TableOfContents/media-utils.tsx+++ b/packages/docs/components/TableOfContents/media-utils.tsx@@ -41,7 +41,15 @@ export const TableOfContents: React.FC = () => {</TOCItem><TOCItem link="/docs/visualize-audio"><strong>visualizeAudio()</strong>- <div>Processes a waveform for visualization</div>+ <div>Process a music waveform for visualization</div>+ </TOCItem>+ <TOCItem link="/docs/media-utils/visualize-audio-waveform">+ <strong>visualizeAudioWaveform()</strong>+ <div>Process a voice waveform for visualization</div>+ </TOCItem>+ <TOCItem link="/docs/media-utils/create-smooth-svg-path">+ <strong>createSmoothSvgPath()</strong>+ <div>Turn waveform points into a smooth SVG path</div></TOCItem></Grid></div>diff --git a/packages/docs/docs/audio-visualization.mdx b/packages/docs/docs/audio-visualization.mdxindex e21fe9bfbd..01cbc9ae9f 100644--- a/packages/docs/docs/audio-visualization.mdx+++ b/packages/docs/docs/audio-visualization.mdx@@ -9,9 +9,11 @@ Remotion has APIs for visualizing audio, for example for creating audiograms orThe `@remotion/media-utils` package provides helper functions for reading and processing audio. Using the [`getAudioData()`](/docs/get-audio-data) API you can read audio, and using the [`useAudioData()`](/docs/use-audio-data) helper hook you can load this audio data directly into your component.-Using the [`visualizeAudio()`](/docs/visualize-audio) API, you can get an audio spectrum for the current frame, with the `numberOfSamples` parameter being an option to control the amount of detail you need.+## Bar visualization-Refer to the documentation of the above mentioned functions to learn more.+Using the [`visualizeAudio()`](/docs/visualize-audio) API, you can get an audio spectrum for the current frame.++Bar visualizations are ideal for visualizing music.```tsx twoslashimport {useAudioData, visualizeAudio} from '@remotion/media-utils';@@ -41,21 +43,27 @@ export const MyComponent: React.FC = () => {<div><Audio src={music} />{visualization.map((v) => {- return (- <div style={{width: 1000 * v, height: 15, backgroundColor: 'blue'}} />- );+ return <div style={{width: 1000 * v, height: 15, backgroundColor: 'blue'}} />;})}</div>);};```+## Waveform visualization++See an example for a waveform visualizations using [`visualizeAudioWaveform()`](/docs/media-utils/visualize-audio-waveform) here.++import {AudioWaveFormExample} from '../components/AudioWaveformExamples.tsx';++<AudioWaveFormExample type="moving" />+## Working with large files-[`useAudioData()`](/docs/use-audio-data) loads the entire audio file into memory.+[`useAudioData()`](/docs/use-audio-data) loads the entire audio file into memory.This is fine for small files, but for large files, it can be slow and consume a lot of memory.-Use [`useWindowedAudioData()`](/docs/use-windowed-audio-data) to only load a portion of the audio around the current frame.+Use [`useWindowedAudioData()`](/docs/use-windowed-audio-data) to only load a portion of the audio around the current frame.The tradeoff is that this API only works with `.wav` files.## See alsodiff --git a/packages/docs/docs/media-utils/create-smooth-svg-path.mdx b/packages/docs/docs/media-utils/create-smooth-svg-path.mdxnew file mode 100644index 0000000000..a5a78f6c5b--- /dev/null+++ b/packages/docs/docs/media-utils/create-smooth-svg-path.mdx@@ -0,0 +1,28 @@+---+title: createSmoothSvgPath()+id: create-smooth-svg-path+crumb: '@remotion/media-utils'+---++_Part of the `@remotion/media-utils`_ package of helper functions.++This function takes points, usually generated from [`visualizeAudioWaveform()`](/docs/visualize-audio-waveform) or [`visualizeAudio()`](/docs/visualize-audio), and adds SVG `C` (curve) statements inbetween them to create a smooth path.++```tsx twoslash+import {createSmoothSvgPath} from '@remotion/media-utils';+import React from 'react';++const points = [+ {x: 0, y: 0},+ {x: 100, y: 100},+ {x: 200, y: 50},+ {x: 300, y: 150},+];++const path = createSmoothSvgPath({points});+```++## See also++- [Audio visualization](/docs/audio-visualization)+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/media-utils/src/create-smooth-svg-path.ts)diff --git a/packages/docs/docs/visualize-audio-waveform.mdx b/packages/docs/docs/media-utils/visualize-audio-waveform.mdxsimilarity index 70%rename from packages/docs/docs/visualize-audio-waveform.mdxrename to packages/docs/docs/media-utils/visualize-audio-waveform.mdxindex 87938e4975..275d609dbb 100644--- a/packages/docs/docs/visualize-audio-waveform.mdx+++ b/packages/docs/docs/media-utils/visualize-audio-waveform.mdx@@ -5,20 +5,21 @@ id: visualize-audio-waveformcrumb: '@remotion/media-utils'----import {AudioWaveFormExample} from '../components/AudioWaveformExamples.tsx';+import {AudioWaveFormExample} from '../../components/AudioWaveformExamples.tsx';_Part of the `@remotion/media-utils`_ package of helper functions.-This function takes in `AudioData` (preferrably fetched by the [`useAudioData()`](/docs/use-audio-data) hook) and processes it in a way that makes visualizing the audio waveform that is playing at the current frame easy.+This function takes in `AudioData` (for example fetched by [`useAudioData()`](/docs/use-audio-data)) and processes it for displaying as a waveform.-```tsx twoslash+This function is suitable for visualizing voice. For visualizing music, use [`visualizeAudio()`](/docs/visualize-audio)++```tsx twoslash title="Usage"import {createSmoothSvgPath, useAudioData, visualizeAudioWaveform, AudioData} from '@remotion/media-utils';import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import voice from './voice-short.mp3';+import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig, staticFile} from 'remotion';const frame = useCurrentFrame();-const audioData = useAudioData(voice) as AudioData;+const audioData = useAudioData(staticFile('voice-short.mp3')) as AudioData;const {fps} = useVideoConfig();// ---cut---@@ -33,10 +34,6 @@ const waveform = visualizeAudioWaveform({See [Examples](#examples) below.-:::info-This function is suitable for visualizing voice. For visualizing music, use [`visualizeAudio()`](/docs/visualize-audio)-:::-## ArgumentsThe only argument for this function is an object containing the following values:@@ -69,13 +66,16 @@ Must be a power of two, such as `32`, `64`, `128`, etc. This parameter controls`number`-Time in seconds (can be float) which represents the duration for which you want to see the audio waveform. Example: Your video has an `fps` of 30, and you pass 15 as the `frame` on `visualizeAudioWaveform` and 0.25 as `windowInSeconds` then output will have audio waveform data from (15/30) - .125 = 0.375 sec to (15/30) +0.125 = 0.625 sec.+Time in seconds (can be float) which represents the duration for which you want to see the audio waveform.+Example: Your video has an `fps` of 30, and you pass 15 as the `frame` on `visualizeAudioWaveform` and 0.25 as `windowInSeconds` then output will have audio waveform data from (15/30) - .125 = 0.375 sec to (15/30) +0.125 = 0.625 sec.## Return value`number[]`-An array of values describing the amplitude of each frequency range. Each value is between 0 and 1. The array is of length defined by the `numberOfSamples` parameter.+An array of values describing the amplitude of each frequency range.+Each value is between -1 and 1.+The array is of length defined by the `numberOfSamples` parameter.## Examples@@ -84,13 +84,14 @@ An array of values describing the amplitude of each frequency range. Each value```tsx twoslashimport {createSmoothSvgPath, useAudioData, visualizeAudioWaveform} from '@remotion/media-utils';import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import voice from './voice-short.mp3';+import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig, staticFile} from 'remotion';++const height = 300;const BaseExample: React.FC = () => {const frame = useCurrentFrame();- const audioDataVoice = useAudioData(voice);- const {width, height, fps} = useVideoConfig();+ const audioDataVoice = useAudioData(staticFile('voice-short.mp3'));+ const {width, fps} = useVideoConfig();if (!audioDataVoice) {return null;@@ -104,15 +105,18 @@ const BaseExample: React.FC = () => {windowInSeconds: 1 / fps,});- const p = createSmoothSvgPath(- waveform.map((x, i) => {- return [(i / (waveform.length - 1)) * width, (x - 0.5) * 300 + height / 2];+ const p = createSmoothSvgPath({+ points: waveform.map((x, i) => {+ return {+ x: (i / (waveform.length - 1)) * width,+ y: (x - 0.5) * height + height / 2,+ };}),- );+ });return (<div style={{flex: 1}}>- <Audio src={voice} />+ <Audio src={staticFile('voice-short.mp3')} /><AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}><svg style={{backgroundColor: ' #0B84F3'}} viewBox={`0 0 ${width} ${height}`} width={width} height={height}><path stroke="white" fill="none" strokeWidth={10} d={p as string} />@@ -133,11 +137,10 @@ By increasing the `windowInSeconds` by tenfold, the audiogram starts moving to t```tsx twoslash {6}import {createSmoothSvgPath, useAudioData, visualizeAudioWaveform, AudioData} from '@remotion/media-utils';import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import voice from './voice-short.mp3';+import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig, staticFile} from 'remotion';const frame = useCurrentFrame();-const audioDataVoice = useAudioData(voice) as AudioData;+const audioDataVoice = useAudioData(staticFile('voice-short.mp3')) as AudioData;const {fps} = useVideoConfig();// ---cut---@@ -160,11 +163,10 @@ By only calculating the waveform every third frame, we make the waveform calmer```tsx twoslash {3}import {createSmoothSvgPath, useAudioData, visualizeAudioWaveform, AudioData} from '@remotion/media-utils';import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import voice from './voice-short.mp3';+import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig, staticFile} from 'remotion';const frame = useCurrentFrame();-const audioDataVoice = useAudioData(voice) as AudioData;+const audioDataVoice = useAudioData(staticFile('voice-short.mp3')) as AudioData;const {fps} = useVideoConfig();// ---cut---@@ -181,6 +183,7 @@ const waveform = visualizeAudioWaveform({## See also+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/media-utils/src/visualize-audio-waveform.ts)- [Audio visualization](/docs/audio-visualization)- [`useAudioData()`](/docs/use-audio-data)- [`getAudioData()`](/docs/get-audio-data)diff --git a/packages/docs/docs/visualize-audio.mdx b/packages/docs/docs/visualize-audio.mdxindex fe267fde35..5313e00b7f 100644--- a/packages/docs/docs/visualize-audio.mdx+++ b/packages/docs/docs/visualize-audio.mdx@@ -2,12 +2,12 @@image: /generated/articles-docs-visualize-audio.pngtitle: visualizeAudio()id: visualize-audio-crumb: "@remotion/media-utils"+crumb: '@remotion/media-utils'---_Part of the `@remotion/media-utils` package of helper functions._-This function takes in `AudioData` (preferably fetched by the [`useAudioData()`](/docs/use-audio-data) hook) and processes it in a way that makes visualizing the audio that is playing at the current frame easy.+This function takes in `AudioData` (for example fetched by [`useAudioData()`](/docs/use-audio-data)) and processes it for displaying as bars.## Arguments@@ -64,13 +64,13 @@ Usually the values on left side of the array can become much larger than the valIn this example, we render a bar chart visualizing the audio spectrum of an audio file we imported using [`useAudioData()`](/docs/use-audio-data) and `visualizeAudio()`.```tsx twoslash-import { useAudioData, visualizeAudio } from "@remotion/media-utils";-import { Audio, staticFile, useCurrentFrame, useVideoConfig } from "remotion";+import {useAudioData, visualizeAudio} from '@remotion/media-utils';+import {Audio, staticFile, useCurrentFrame, useVideoConfig} from 'remotion';export const MyComponent: React.FC = () => {const frame = useCurrentFrame();- const { width, height, fps } = useVideoConfig();- const audioData = useAudioData(staticFile("music.mp3"));+ const {width, height, fps} = useVideoConfig();+ const audioData = useAudioData(staticFile('music.mp3'));if (!audioData) {return null;@@ -87,13 +87,9 @@ export const MyComponent: React.FC = () => {// the longer the barreturn (<div>- <Audio src={staticFile("music.mp3")} />+ <Audio src={staticFile('music.mp3')} />{visualization.map((v) => {- return (- <div- style={{ width: 1000 * v, height: 15, backgroundColor: "blue" }}- />- );+ return <div style={{width: 1000 * v, height: 15, backgroundColor: 'blue'}} />;})}</div>);@@ -105,14 +101,14 @@ export const MyComponent: React.FC = () => {A logarithmic representation of the audio will look more appealing than a linear one. Below is an example of a postprocessing step that looks prettier than the default one.```tsx twoslash-import { visualizeAudio } from "@remotion/media-utils";+import {visualizeAudio} from '@remotion/media-utils';const params = {audioData: {channelWaveforms: [],sampleRate: 0,durationInSeconds: 0,numberOfChannels: 0,- resultId: "",+ resultId: '',isRemote: true,},frame: 0,diff --git a/packages/docs/components/voice-short.mp3 b/packages/docs/public/voice-short.mp3similarity index 100%rename from packages/docs/components/voice-short.mp3rename to packages/docs/public/voice-short.mp3diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex e24d215072..899f0c53ab 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -198,6 +198,8 @@ module.exports = {'use-audio-data','use-windowed-audio-data','visualize-audio',+ 'media-utils/visualize-audio-waveform',+ 'media-utils/create-smooth-svg-path','get-image-dimensions',],},diff --git a/packages/docs/static/voice-short.mp3 b/packages/docs/static/voice-short.mp3new file mode 100644index 0000000000..33b56ef741Binary files /dev/null and b/packages/docs/static/voice-short.mp3 differdiff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex 68580a0d80..30be512e1e 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -122,7 +122,6 @@ import {ParseAndDownloadMedia} from './ParseAndDownloadMedia';import {SmoothTextTransition} from './SmoothTextTransition';import {Seek} from './StudioApis/Seek';import {VoiceVisualization} from './voice-visualization';-import {TwoChannelVoiceVisualization} from './voice-visualization/two-channel';class Vector2 {readonly x: number;@@ -1545,14 +1544,6 @@ export const Index: React.FC = () => {fps={30}durationInFrames={100}/>- <Composition- id="two-tone"- component={TwoChannelVoiceVisualization}- width={1080}- height={1080}- fps={30}- durationInFrames={100}- /></Folder></>);diff --git a/packages/example/src/voice-visualization/VoiceVisualization.tsx b/packages/example/src/voice-visualization/VoiceVisualization.tsxnew file mode 100644index 0000000000..c67ac677ed--- /dev/null+++ b/packages/example/src/voice-visualization/VoiceVisualization.tsx@@ -0,0 +1,67 @@+import {+ AudioData,+ createSmoothSvgPath,+ visualizeAudioWaveform,+} from '@remotion/media-utils';+import React from 'react';+import {useCurrentFrame, useVideoConfig} from 'remotion';++export const VoiceVis: React.FC<{+ audioDataVoice: AudioData;+ padding: number;+ numberOfSamples: number;+ windowInSeconds: number;+ posterization: number;+ amplitude: number;+}> = ({+ audioDataVoice,+ padding,+ numberOfSamples,+ windowInSeconds,+ posterization,+ amplitude,+}) => {+ const {width, fps} = useVideoConfig();+ const frame = useCurrentFrame();++ const height = 200;++ const posterized = Math.round(frame / posterization) * posterization;++ const waveform = visualizeAudioWaveform({+ fps,+ frame: posterized,+ audioData: audioDataVoice,+ numberOfSamples: numberOfSamples,+ windowInSeconds: windowInSeconds,+ channel: 0,+ });++ const p = createSmoothSvgPath({+ points: waveform.map((y, i) => {+ return {+ x: (i / (waveform.length - 1)) * width,+ y: height / 2 + ((y * height) / 2) * amplitude,+ };+ }),+ });++ return (+ <svg+ viewBox={`0 0 ${width} ${height}`}+ style={{+ overflow: 'visible',+ }}+ width={width - padding * 2}+ height={height}+ >+ <path+ strokeLinecap="round"+ fill="none"+ stroke="#222"+ strokeWidth={10}+ d={p}+ />+ </svg>+ );+};diff --git a/packages/example/src/voice-visualization/index.tsx b/packages/example/src/voice-visualization/index.tsxindex 67f536e289..0f10a766b4 100644--- a/packages/example/src/voice-visualization/index.tsx+++ b/packages/example/src/voice-visualization/index.tsx@@ -1,67 +1,56 @@-import {- smoothenSvgPath,- useAudioData,- visualizeAudioWaveform,-} from '@remotion/media-utils';+import {useAudioData} from '@remotion/media-utils';import React from 'react';-import {Audio, useCurrentFrame, useVideoConfig} from 'remotion';+import {Audio} from 'remotion';import voice from '../resources/voice-short.mp3';+import {VoiceVis} from './VoiceVisualization';const padding = 80;export const VoiceVisualization: React.FC = () => {- const frame = useCurrentFrame();- const {fps} = useVideoConfig();const audioDataVoice = useAudioData(voice);- const {width} = useVideoConfig();-- const height = 600;if (!audioDataVoice) {return null;}- const posterized = Math.round(frame / 1) * 1;-- const waveform = visualizeAudioWaveform({- fps,- frame: posterized,- audioData: audioDataVoice,- numberOfSamples: 40,- windowInSeconds: 1,- channel: 0,- });-- const p = smoothenSvgPath({- points: waveform.map((y, i) => {- return {- x: (i / (waveform.length - 1)) * width,- y: height / 2 + (y * height) / 2,- };- }),- });-return (- <div style={{flex: 1, padding}} className="flex-1 bg-white">+ <div+ style={{flex: 1, padding}}+ className="flex-1 bg-white items-center justify-center flex flex-col"+ ><Audio src={voice} />- <div className="flex justify-center items-center">- <svg- viewBox={`0 0 ${width} ${height}`}- style={{- overflow: 'visible',- }}- width={width - padding * 2}- height={height}- >- <path- strokeLinecap="round"- fill="none"- stroke="#222"- strokeWidth={10}- d={p}- />- </svg>- </div>+ <VoiceVis+ padding={padding}+ audioDataVoice={audioDataVoice}+ numberOfSamples={10}+ windowInSeconds={1}+ posterization={3}+ amplitude={3}+ />+ <VoiceVis+ padding={padding}+ audioDataVoice={audioDataVoice}+ numberOfSamples={40}+ windowInSeconds={1}+ posterization={3}+ amplitude={3}+ />+ <VoiceVis+ padding={padding}+ audioDataVoice={audioDataVoice}+ numberOfSamples={64}+ windowInSeconds={1}+ posterization={3}+ amplitude={3}+ />+ <VoiceVis+ padding={padding}+ audioDataVoice={audioDataVoice}+ numberOfSamples={200}+ windowInSeconds={1}+ posterization={3}+ amplitude={3}+ /></div>);};diff --git a/packages/example/src/voice-visualization/two-channel.tsx b/packages/example/src/voice-visualization/two-channel.tsxdeleted file mode 100644index 6aad8df33c..0000000000--- a/packages/example/src/voice-visualization/two-channel.tsx+++ /dev/null@@ -1,105 +0,0 @@-import {- smoothenSvgPath,- useAudioData,- visualizeAudioWaveform,-} from '@remotion/media-utils';-import React from 'react';-import {AbsoluteFill, Audio, useCurrentFrame, useVideoConfig} from 'remotion';-import styled from 'styled-components';-import voice from '../resources/voice-short.mp3';--const FullSize = styled(AbsoluteFill)`- display: flex;- justify-content: center;- align-items: center;-`;--const makeDuoform = (form: number[], width: number, height: number) => {- const p2Path = form.map((y, i) => {- return [- (i / (form.length - 1)) * width,- height / 2 + (Math.max(0.015, Math.abs(y)) * height) / 2,- ] as [number, number];- });- const p2PathReverse = form- .map((y, i) => {- return [- (i / (form.length - 1)) * width,- height / 2 - (Math.max(0.015, Math.abs(y)) * height) / 2,- ] as [number, number];- })- .reverse();-- const p2 = smoothenSvgPath(p2Path);- const p2Reverse = smoothenSvgPath(p2PathReverse);-- const joined = [- p2,- `L ${p2PathReverse[0][0]} ${p2PathReverse[0][1]}`,- p2Reverse,- `L ${p2Path[0][0]} ${p2Path[0][1]}`,- ].join(' ');-- return joined;-};--export const TwoChannelVoiceVisualization: React.FC = () => {- const frame = useCurrentFrame();- const {fps} = useVideoConfig();- const audioDataVoice = useAudioData(voice);- const {width, height} = useVideoConfig();-- if (!audioDataVoice) {- return null;- }-- const posterized = Math.round(frame / 3) * 3;-- const waveform = visualizeAudioWaveform({- fps,- frame: posterized + 0.5 * fps,- audioData: audioDataVoice,- numberOfSamples: 16,- windowInSeconds: 1,- channel: 0,- });- const waveform2 = visualizeAudioWaveform({- fps,- frame: posterized,- audioData: audioDataVoice,- numberOfSamples: 16,- windowInSeconds: 1,- channel: 1,- });-- const joined = makeDuoform(waveform, width, height);- const joined2 = makeDuoform(waveform2, width, height);-- return (- <div style={{flex: 1, backgroundColor: 'white'}}>- <Audio src={voice} />- <FullSize style={{opacity: 1}}>- <svg viewBox={`0 0 ${width} ${height}`} width={width} height={height}>- <defs>- <linearGradient id="myGradient2" gradientTransform="rotate(90)">- <stop offset="0%" stopColor="#adffff" />- <stop offset="100%" stopColor="rgb(173, 255, 255)" />- </linearGradient>- </defs>- <path fill="url(#myGradient2)" fillRule="nonzero" d={joined} />- </svg>- </FullSize>- <FullSize style={{opacity: 0.5, mixBlendMode: 'exclusion'}}>- <svg viewBox={`0 0 ${width} ${height}`} width={width} height={height}>- <defs>- <linearGradient id="myGradient" gradientTransform="rotate(90)">- <stop offset="5%" stopColor="#ff0000" />- <stop offset="95%" stopColor="#ff7d19" />- </linearGradient>- </defs>- <path fill="url(#myGradient)" fillRule="nonzero" d={joined2} />- </svg>- </FullSize>{' '}- </div>- );-};diff --git a/packages/media-utils/src/index.ts b/packages/media-utils/src/index.tsindex 491fcf35d6..cebf146fa3 100644--- a/packages/media-utils/src/index.ts+++ b/packages/media-utils/src/index.ts@@ -1,5 +1,5 @@export {audioBufferToDataUrl} from './audio-buffer/audio-url-helpers';-export {createSmoothSvgPath as smoothenSvgPath} from './create-smooth-svg-path';+export {createSmoothSvgPath} from './create-smooth-svg-path';export {getAudioData} from './get-audio-data';export {getAudioDuration,diff --git a/packages/media-utils/src/visualize-audio-waveform.ts b/packages/media-utils/src/visualize-audio-waveform.tsindex 2d96e8406c..8bffd28435 100644--- a/packages/media-utils/src/visualize-audio-waveform.ts+++ b/packages/media-utils/src/visualize-audio-waveform.ts@@ -10,7 +10,7 @@ export type VisualizeAudioWaveformOptions = {fps: number;windowInSeconds: number;numberOfSamples: number;- channel: number;+ channel?: number;};const visualizeAudioWaveformFrame = ({