Skip to content

πŸŽ₯ Make videos programmatically with React

Merge branch 'main' into audio-waveform

Jonny Burgerf66f43ff1c59
diff --cc packages/docs/docs/audio-visualization.mdx
index 0000000000,3fc11b5fc0..e21fe9bfbd
mode 000000,100644..100644
--- a/packages/docs/docs/audio-visualization.mdx
+++ b/packages/docs/docs/audio-visualization.mdx
@@@ -1,0 -1,66 +1,67 @@@
+ ---
+ image: /generated/articles-docs-audio-visualization.png
+ title: Audio visualization
+ id: audio-visualization
+ crumb: 'Techniques'
+ ---
+
+ Remotion has APIs for visualizing audio, for example for creating audiograms or music visualizers.
+
+ The `@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.
+
+ Refer to the documentation of the above mentioned functions to learn more.
+
+ ```tsx twoslash
+ import {useAudioData, visualizeAudio} from '@remotion/media-utils';
+ import {Audio, staticFile, useCurrentFrame, useVideoConfig} from 'remotion';
+
+ const music = staticFile('music.mp3');
+
+ export const MyComponent: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {width, height, fps} = useVideoConfig();
+ const audioData = useAudioData(music);
+
+ if (!audioData) {
+ return null;
+ }
+
+ const visualization = visualizeAudio({
+ fps,
+ frame,
+ audioData,
+ numberOfSamples: 16,
+ }); // [0.22, 0.1, 0.01, 0.01, 0.01, 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+
+ // Render a bar chart for each frequency, the higher the amplitude,
+ // the longer the bar
+ return (
+ <div>
+ <Audio src={music} />
+ {visualization.map((v) => {
+ return (
+ <div style={{width: 1000 * v, height: 15, backgroundColor: 'blue'}} />
+ );
+ })}
+ </div>
+ );
+ };
+ ```
+
+ ## Working with large files
+
+ [`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.
+ The tradeoff is that this API only works with `.wav` files.
+
+ ## See also
+
+ - [Using audio](/docs/using-audio)
+ - [`useAudioData()`](/docs/use-audio-data)
+ - [`useWindowedAudioData()`](/docs/use-windowed-audio-data)
+ - [`visualizeAudio()`](/docs/visualize-audio)
++- [`visualizeAudioWaveform()`](/docs/visualize-audio-waveform)
diff --cc packages/docs/sidebars.js
index 867e63fd79,e24d215072..56ecadf86d
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@@ -1,287 -1,1237 +1,287 @@@
module.exports = {
- lambdaSidebar: [
- {
- type: "link",
- label: "← Back to main docs",
- href: "/docs",
- },
- "lambda",
- {
- collapsed: false,
- type: "category",
- label: "CLI",
- items: [
- "lambda/cli",
- "lambda/cli/sites",
- "lambda/cli/functions",
- "lambda/cli/render",
- "lambda/cli/still",
- "lambda/cli/policies",
- "lambda/cli/regions",
- "lambda/cli/quotas",
- ],
- },
- "lambda/setup",
- "lambda/permissions",
- "lambda/region-selection",
- "lambda/concurrency",
- "lambda/runtime",
- "lambda/disk-size",
- "lambda/faq",
- "lambda/light-client",
- "lambda/custom-layers",
- {
- collapsed: false,
- type: "category",
- label: "Node.JS APIs",
- items: [
- "lambda/estimateprice",
- "lambda/deployfunction",
- "lambda/deletefunction",
- "lambda/getfunctioninfo",
- "lambda/getfunctions",
- "lambda/deletesite",
- "lambda/deploysite",
- "lambda/getawsclient",
- "lambda/getregions",
- "lambda/getsites",
- "lambda/downloadmedia",
- "lambda/getuserpolicy",
- "lambda/getrolepolicy",
- "lambda/getorcreatebucket",
- "lambda/getrenderprogress",
- "lambda/presignurl",
- "lambda/rendermediaonlambda",
- "lambda/renderstillonlambda",
- "lambda/simulatepermissions",
- ],
- },
- "lambda/checklist",
- {
- collapsed: false,
- type: "category",
- label: "Troubleshooting",
- items: [
- "lambda/troubleshooting/permissions",
- "lambda/troubleshooting/rate-limit",
- ],
- },
- "lambda/changelog",
- "lambda/upgrading",
- "lambda/uninstall",
- ],
- someSidebar: [
- {
- collapsed: false,
- type: "category",
- label: "Getting started",
- items: [
- "getting-started",
- "the-fundamentals",
- "animating-properties",
- "reusability",
- "timeline",
- "render",
- ],
- },
- {
- type: "category",
- label: "Techniques",
- collapsed: false,
- items: [
- "assets",
- "using-audio",
- "fonts",
- "using-randomness",
- "audio-visualization",
- "use-img-and-iframe",
- "javascript",
- "data-fetching",
- "encoding",
- "transparent-videos",
- "parametrized-rendering",
- "dynamic-metadata",
- "ssr",
- "webpack",
- "legacy-babel",
- "env-variables",
- "third-party",
- "stills",
- "scaling",
- "video-manipulation",
- ],
- },
- {
- type: "category",
- label: "CLI",
- link: {
- type: "doc",
- id: "cli/cli",
- },
- collapsed: true,
- items: [
- "cli/preview",
- "cli/render",
- "cli/still",
- "cli/compositions",
- {
- type: "link",
- href: "/docs/lambda/cli",
- label: "lambda ↗️",
- },
- "cli/versions",
- "cli/upgrade",
- "cli/help",
- ],
- },
- "config",
- {
- type: "category",
- label: "API - Core",
- collapsed: false,
- items: [
- "continue-render",
- "delay-render",
- "interpolate",
- "interpolate-colors",
- "get-input-props",
- "measure-spring",
- "random",
- "register-root",
- "spring",
- "staticfile",
- "use-current-frame",
- "use-video-config",
- "audio",
- "composition",
- "sequence",
- "loop",
- "video",
- "offthreadvideo",
- "absolute-fill",
- "img",
- "iframe",
- "freeze",
- "still",
- "series",
- "folder",
- "easing",
- ],
- },
- {
- type: "category",
- label: "API - @remotion/bundler",
- items: ["bundle"],
- },
- "gif",
- {
- type: "category",
- label: "API - @remotion/media-utils",
- items: [
- "audio-buffer-to-data-url",
- "get-audio-data",
- "get-audio-duration-in-seconds",
- "get-video-metadata",
- "get-waveform-portion",
- "use-audio-data",
- "visualize-audio",
- "visualize-audio-waveform"
- ],
- },
- {
- type: "link",
- href: "/docs/lambda",
- label: "API - @remotion/lambda",
- },
- {
- type: "category",
- link: {
- type: "doc",
- id: "player/player",
- },
- label: "API - @remotion/player",
- items: [
- "player/installation",
- "player/examples",
- "player/api",
- "player/scaling",
- "player/integration",
- "player/autoplay",
- "player/preloading",
- ],
- },
- {
- type: "category",
- label: "API - @remotion/three",
- link: {
- type: "doc",
- id: "three",
- },
- items: ["three-canvas", "use-video-texture"],
- },
- {
- type: "category",
- label: "API - @remotion/preload",
- link: {
- type: "doc",
- id: "preload/preload",
- },
- items: [
- "preload/preload-video",
- "preload/preload-audio",
- "preload/resolve-redirect",
- ],
- },
- {
- type: "category",
- link: {
- type: "doc",
- id: "renderer",
- },
- label: "API - @remotion/renderer",
- items: [
- "renderer/get-compositions",
- "renderer/render-media",
- "renderer/render-frames",
- "renderer/render-still",
- "renderer/stitch-frames-to-video",
- "renderer/open-browser",
- "renderer/make-cancel-signal",
- ],
- },
- {
- type: "category",
- label: "Troubleshooting",
- collapsed: false,
- items: [
- "timeout",
- "target-closed",
- "media-playback-error",
- "performance",
- "webpack-dynamic-imports",
- "non-seekable-media",
- "flickering",
- "version-mismatch",
- "enametoolong",
- "slow-method-to-extract-frame",
- ],
- },
- {
- type: "category",
- label: "Miscellaneous",
- collapsed: false,
- items: [
- "brownfield",
- "chromium-flags",
- "video-vs-offthreadvideo",
- "prereleases",
- "gpu",
- "react-18",
- "miscellaneous/typescript-aliases",
- ],
- },
- "3-0-migration",
- "2-0-migration",
- "license",
- ],
- apiSidebar: [
- 'api',
++ lambdaSidebar: [
+ {
- type: 'category',
- label: 'Command line',
- link: {
- type: 'doc',
- id: 'cli/cli',
- },
- collapsed: true,
- items: [
- 'cli/studio',
- 'cli/render',
- 'cli/still',
- 'cli/compositions',
- 'cli/bundle',
- {
- type: 'category',
- label: 'lambda',
- link: {
- type: 'doc',
- id: 'lambda/cli',
- },
- items: [
- 'lambda/cli/sites',
- 'lambda/cli/functions',
- 'lambda/cli/render',
- 'lambda/cli/still',
- 'lambda/cli/policies',
- 'lambda/cli/compositions',
- 'lambda/cli/regions',
- 'lambda/cli/quotas',
- ],
- },
- {
- type: 'category',
- label: 'cloudrun',
- link: {
- type: 'doc',
- id: 'cloudrun/cli',
- },
- items: [
- 'cloudrun/cli/sites',
- 'cloudrun/cli/services',
- 'cloudrun/cli/render',
- 'cloudrun/cli/still',
- 'cloudrun/cli/permissions',
- 'cloudrun/cli/regions',
- ],
- },
- 'cli/benchmark',
- {
- type: 'category',
- label: 'browser',
- link: {
- type: 'doc',
- id: 'cli/browser/index',
- },
- items: ['cli/browser/ensure'],
- },
- 'cli/versions',
- 'cli/upgrade',
- 'cli/ffmpeg',
- 'cli/ffprobe',
- 'cli/gpu',
- 'cli/help',
- ],
- },
- 'config',
- {
- type: 'html',
- value:
- '<hr style="margin-top: 4px; margin-bottom: 4px; border-bottom: none"/>', // The HTML to be rendered
- defaultStyle: true, // Use the default menu item styling
- },
- {
- type: 'category',
- label: 'remotion',
- link: {
- type: 'doc',
- id: 'remotion',
- },
- items: [
- 'absolute-fill',
- 'audio',
- 'artifact',
- 'calculate-metadata',
- 'cancel-render',
- 'composition',
- 'continue-render',
- 'delay-render',
- 'easing',
- 'folder',
- 'freeze',
- 'get-input-props',
- 'get-remotion-environment',
- 'getstaticfiles',
- 'iframe',
- 'img',
- 'interpolate-colors',
- 'interpolate',
- 'loop',
- 'measure-spring',
- 'offthreadvideo',
- 'animatedimage',
- 'prefetch',
- 'random',
- 'register-root',
- 'sequence',
- 'series',
- 'spring',
- 'staticfile',
- 'still',
- 'use-buffer-state',
- 'use-current-frame',
- 'use-current-scale',
- 'use-video-config',
- 'version',
- 'video',
- 'watchstaticfile',
- ],
- },
- {
- type: 'category',
- label: '@remotion/bundler',
- link: {
- type: 'doc',
- id: 'bundler',
- },
- items: ['bundle'],
- },
- {
- type: 'category',
- link: {
- type: 'doc',
- id: 'renderer',
- },
- label: '@remotion/renderer',
- items: [
- 'renderer/get-compositions',
- 'renderer/select-composition',
- 'renderer/render-media',
- 'renderer/render-frames',
- 'renderer/render-still',
- 'renderer/stitch-frames-to-video',
- 'renderer/open-browser',
- 'renderer/ensure-browser',
- 'renderer/make-cancel-signal',
- 'renderer/ensure-ffmpeg',
- 'renderer/ensure-ffprobe',
- 'renderer/get-can-extract-frames-fast',
- 'renderer/get-video-metadata',
- 'renderer/get-silent-parts',
- 'renderer/extract-audio',
- ],
- },
- {
- type: 'category',
- link: {
- type: 'doc',
- id: 'player/installation',
- },
-
- label: '@remotion/player',
- items: [
- {
- type: 'link',
- href: '/docs/player',
- label: 'Guide + Examples',
- },
- 'player/api',
- 'player/thumbnail',
- ],
- },
- {
- type: 'category',
- label: '@remotion/gif',
- link: {
- type: 'doc',
- id: 'gif/index',
- },
- items: ['gif/gif', 'gif/get-gif-duration-in-seconds', 'gif/preload-gif'],
- },
- {
- type: 'category',
- label: '@remotion/media-utils',
- link: {
- type: 'doc',
- id: 'media-utils/index',
- },
- items: [
- 'audio-buffer-to-data-url',
- 'get-audio-data',
- 'get-audio-duration-in-seconds',
- 'get-video-metadata',
- 'get-waveform-portion',
- 'use-audio-data',
- 'use-windowed-audio-data',
- 'visualize-audio',
- 'get-image-dimensions',
- ],
- },
- {
- type: 'category',
- label: '@remotion/media-parser',
- link: {
- type: 'doc',
- id: 'media-parser/index',
- },
- items: [
- {
- type: 'link',
- href: '/docs/media-parser/metadata',
- label: 'Guide',
- },
- 'media-parser/parse-media',
- 'media-parser/download-and-parse-media',
- 'media-parser/media-parser-controller',
- 'media-parser/has-been-aborted',
- 'media-parser/node-reader',
- 'media-parser/fetch-reader',
- 'media-parser/web-file-reader',
- 'media-parser/node-writer',
- ],
- },
-
- {
- type: 'category',
- label: '@remotion/motion-blur',
- link: {
- type: 'doc',
- id: 'motion-blur/index',
- },
- items: [
- 'motion-blur/trail',
- 'motion-blur/camera-motion-blur',
- 'motion-blur/common-mistake',
- ],
- },
- {
- type: 'category',
- label: '@remotion/lambda',
- link: {
- type: 'doc',
- id: 'lambda/api',
- },
- items: [
- {
- type: 'link',
- href: '/docs/lambda/cli',
- label: 'CLI Reference',
- },
- 'lambda/estimateprice',
- 'lambda/deployfunction',
- 'lambda/deletefunction',
- 'lambda/getfunctioninfo',
- 'lambda/getfunctions',
- 'lambda/deletesite',
- 'lambda/deploysite',
- 'lambda/getawsclient',
- 'lambda/getregions',
- 'lambda/getsites',
- 'lambda/downloadmedia',
- 'lambda/deleterender',
- 'lambda/getuserpolicy',
- 'lambda/getrolepolicy',
- 'lambda/getcompositionsonlambda',
- 'lambda/getorcreatebucket',
- 'lambda/getrenderprogress',
- 'lambda/presignurl',
- 'lambda/rendermediaonlambda',
- 'lambda/renderstillonlambda',
- 'lambda/simulatepermissions',
- 'lambda/speculatefunctionname',
- 'lambda/validatewebhooksignature',
- 'lambda/approuterwebhook',
- 'lambda/pagesrouterwebhook',
- 'lambda/expresswebhook',
- ],
- },
- {
- type: 'category',
- label: '@remotion/cloudrun',
- link: {
- type: 'doc',
- id: 'cloudrun/api',
- },
- items: [
- {
- type: 'link',
- href: '/docs/cloudrun/cli',
- label: 'CLI Reference',
- },
- 'cloudrun/getserviceinfo',
- 'cloudrun/deployservice',
- 'cloudrun/deleteservice',
- 'cloudrun/getservices',
- 'cloudrun/speculateservicename',
- 'cloudrun/getregions',
- 'cloudrun/deploysite',
- 'cloudrun/deletesite',
- 'cloudrun/getsites',
- 'cloudrun/getorcreatebucket',
- 'cloudrun/rendermediaoncloudrun',
- 'cloudrun/renderstilloncloudrun',
- 'cloudrun/testpermissions',
- ],
- },
- {
- type: 'category',
- label: '@remotion/tailwind',
- link: {
- type: 'doc',
- id: 'tailwind/tailwind',
- },
- items: ['tailwind/enable-tailwind'],
- },
- {
- type: 'category',
- label: '@remotion/tailwind-v4',
- link: {
- type: 'doc',
- id: 'tailwind-v4/overview',
- },
- items: ['tailwind-v4/enable-tailwind'],
- },
- {
- type: 'category',
- label: '@remotion/enable-scss',
- link: {
- type: 'doc',
- id: 'enable-scss/overview',
- },
- items: ['enable-scss/enable-scss'],
- },
- {
- type: 'category',
- label: '@remotion/three',
- link: {
- type: 'doc',
- id: 'three',
- },
- items: [
- 'three-canvas',
- 'use-video-texture',
- 'use-offthread-video-texture',
- ],
- },
- {
- type: 'category',
- label: '@remotion/skia',
- link: {
- type: 'doc',
- id: 'skia/skia',
- },
- items: ['skia/enable-skia', 'skia/skia-canvas'],
- },
- {
- type: 'category',
- label: '@remotion/lottie',
- link: {
- type: 'doc',
- id: 'lottie/lottie-index',
- },
- items: [
- 'lottie/lottie-comp',
- 'lottie/getlottiemetadata',
- 'lottie/lottie-staticfile',
- 'lottie/lottie-remote',
- 'lottie/lottie-lottiefiles',
- ],
- },
- {
- type: 'category',
- label: '@remotion/preload',
- link: {
- type: 'doc',
- id: 'preload/preload',
- },
- items: [
- 'preload/preload-video',
- 'preload/preload-audio',
- 'preload/preload-image',
- 'preload/preload-font',
- 'preload/resolve-redirect',
- ],
- },
- {
- type: 'category',
- label: '@remotion/paths',
- link: {
- type: 'doc',
- id: 'paths/index',
- },
- items: [
- 'paths/get-length',
- 'paths/get-point-at-length',
- 'paths/get-tangent-at-length',
- 'paths/get-instruction-index-at-length',
- 'paths/reverse-path',
- 'paths/normalize-path',
- 'paths/interpolate-path',
- 'paths/evolve-path',
- 'paths/reset-path',
- 'paths/get-subpaths',
- 'paths/translate-path',
- 'paths/warp-path',
- 'paths/scale-path',
- 'paths/get-bounding-box',
- 'paths/extend-viewbox',
- 'paths/parse-path',
- 'paths/serialize-instructions',
- 'paths/reduce-instructions',
- 'paths/get-parts',
- ],
- },
- {
- type: 'category',
- label: '@remotion/noise',
- link: {
- type: 'doc',
- id: 'noise/index',
- },
- items: ['noise/noise-2d', 'noise/noise-3d', 'noise/noise-4d'],
- },
- {
- type: 'category',
- label: '@remotion/google-fonts',
- link: {
- type: 'doc',
- id: 'google-fonts/google-fonts',
- },
- items: [
- 'google-fonts/load-font',
- 'google-fonts/get-available-fonts',
- 'google-fonts/get-info',
- ],
- },
- {
- type: 'category',
- label: '@remotion/shapes',
- link: {
- type: 'doc',
- id: 'shapes/index',
- },
- items: [
- 'shapes/rect',
- 'shapes/triangle',
- 'shapes/circle',
- 'shapes/ellipse',
- 'shapes/star',
- 'shapes/pie',
- 'shapes/polygon',
- 'shapes/make-rect',
- 'shapes/make-triangle',
- 'shapes/make-circle',
- 'shapes/make-ellipse',
- 'shapes/make-star',
- 'shapes/make-pie',
- 'shapes/make-polygon',
- ],
- },
- {
- type: 'category',
- label: '@remotion/rive',
- link: {
- type: 'doc',
- id: 'rive/index',
- },
- items: ['rive/index', 'rive/remotionrivecanvas'],
- },
- {
- type: 'category',
- label: '@remotion/studio',
- link: {
- type: 'doc',
- id: 'studio/api',
- },
- items: [
- 'studio/get-static-files',
- 'studio/watch-public-folder',
- 'studio/watch-static-file',
- 'studio/write-static-file',
- 'studio/delete-static-file',
- 'studio/restart-studio',
- 'studio/save-default-props',
- 'studio/seek',
- 'studio/update-default-props',
- 'studio/focus-default-props-path',
- 'studio/reevaluate-composition',
- ],
- },
- {
- type: 'category',
- label: '@remotion/transitions',
- link: {
- type: 'doc',
- id: 'transitions/index',
- },
- items: [
- 'transitions/transitionseries',
- 'transitions/use-transition-progress',
- {
- type: 'category',
- label: 'Timings',
- link: {
- type: 'doc',
- id: 'transitions/timings/index',
- },
- items: [
- 'transitions/timings/springtiming',
- 'transitions/timings/lineartiming',
- 'transitions/timings/custom',
- ],
- },
- {
- type: 'category',
- label: 'Presentations',
- link: {
- type: 'doc',
- id: 'transitions/presentations/index',
- },
- items: [
- 'transitions/presentations/fade',
- 'transitions/presentations/slide',
- 'transitions/presentations/wipe',
- 'transitions/presentations/flip',
- 'transitions/presentations/clock-wipe',
- 'transitions/presentations/none',
- {
- type: 'doc',
- id: 'transitions/presentations/cube',
- className: 'pro-item',
- },
- 'transitions/presentations/custom',
- 'transitions/audio-transitions',
- ],
- },
- ],
- },
- {
- type: 'category',
- label: '@remotion/zod-types',
- link: {
- type: 'doc',
- id: 'zod-types/index',
- },
- items: ['zod-types/z-color', 'zod-types/z-textarea'],
- },
- {
- type: 'category',
- label: '@remotion/layout-utils',
- link: {
- type: 'doc',
- id: 'layout-utils/index',
- },
- items: [
- 'layout-utils/best-practices',
- 'layout-utils/measure-text',
- 'layout-utils/fill-text-box',
- 'layout-utils/fit-text',
- 'layout-utils/debug',
- ],
- },
- {
- type: 'category',
- label: '@remotion/animation-utils',
- link: {
- type: 'doc',
- id: 'animation-utils/index',
- },
- items: [
- 'animation-utils/make-transform',
- 'animation-utils/interpolate-styles',
- ],
- },
- {
- type: 'category',
- label: '@remotion/animated-emoji',
- link: {
- type: 'doc',
- id: 'animated-emoji/index',
- },
- items: [
- 'animated-emoji/animated-emoji',
- 'animated-emoji/get-available-emoji',
- ],
- },
- {
- type: 'category',
- label: '@remotion/webcodecs',
- link: {
- type: 'doc',
- id: 'webcodecs/index',
- },
- items: [
- {
- type: 'link',
- href: '/docs/webcodecs/convert-a-video',
- label: 'Guide',
- },
- 'webcodecs/convert-media',
- 'webcodecs/webcodecs-controller',
- 'webcodecs/get-available-containers',
- 'webcodecs/can-reencode-audio-track',
- 'webcodecs/can-reencode-video-track',
- 'webcodecs/can-copy-audio-track',
- 'webcodecs/can-copy-video-track',
- 'webcodecs/default-on-audio-track-handler',
- 'webcodecs/default-on-video-track-handler',
- 'webcodecs/get-default-audio-codec',
- 'webcodecs/get-default-video-codec',
- 'webcodecs/get-available-audio-codecs',
- 'webcodecs/get-available-video-codecs',
- ],
++ type: 'link',
++ label: '← Back to main docs',
++ href: '/docs',
+ },
++ 'lambda',
+ {
++ collapsed: false,
+ type: 'category',
- label: '@remotion/captions',
- link: {
- type: 'doc',
- id: 'captions/index',
- },
++ label: 'CLI',
+ items: [
- 'captions/caption',
- 'captions/parse-srt',
- 'captions/serialize-srt',
- 'captions/create-tiktok-style-captions',
++ 'lambda/cli',
++ 'lambda/cli/sites',
++ 'lambda/cli/functions',
++ 'lambda/cli/render',
++ 'lambda/cli/still',
++ 'lambda/cli/policies',
++ 'lambda/cli/regions',
++ 'lambda/cli/quotas',
+ ],
+ },
++ 'lambda/setup',
++ 'lambda/permissions',
++ 'lambda/region-selection',
++ 'lambda/concurrency',
++ 'lambda/runtime',
++ 'lambda/disk-size',
++ 'lambda/faq',
++ 'lambda/light-client',
++ 'lambda/custom-layers',
+ {
++ collapsed: false,
+ type: 'category',
- label: '@remotion/install-whisper-cpp',
- link: {
- type: 'doc',
- id: 'install-whisper-cpp/index',
- },
++ label: 'Node.JS APIs',
+ items: [
- 'install-whisper-cpp/install-whisper-cpp',
- 'install-whisper-cpp/download-whisper-model',
- 'install-whisper-cpp/transcribe',
- 'install-whisper-cpp/to-captions',
- 'install-whisper-cpp/convert-to-captions',
++ 'lambda/estimateprice',
++ 'lambda/deployfunction',
++ 'lambda/deletefunction',
++ 'lambda/getfunctioninfo',
++ 'lambda/getfunctions',
++ 'lambda/deletesite',
++ 'lambda/deploysite',
++ 'lambda/getawsclient',
++ 'lambda/getregions',
++ 'lambda/getsites',
++ 'lambda/downloadmedia',
++ 'lambda/getuserpolicy',
++ 'lambda/getrolepolicy',
++ 'lambda/getorcreatebucket',
++ 'lambda/getrenderprogress',
++ 'lambda/presignurl',
++ 'lambda/rendermediaonlambda',
++ 'lambda/renderstillonlambda',
++ 'lambda/simulatepermissions',
+ ],
+ },
++ 'lambda/checklist',
+ {
++ collapsed: false,
+ type: 'category',
- label: '@remotion/openai-whisper',
- link: {
- type: 'doc',
- id: 'openai-whisper/index',
- },
- items: ['openai-whisper/openai-whisper-api-to-captions'],
- },
- {
- type: 'category',
- label: '@remotion/fonts',
- link: {
- type: 'doc',
-
- id: 'fonts-api/fonts-api',
- },
- items: ['fonts-api/load-font'],
- },
- {
- type: 'category',
- label: '@remotion/licensing',
- link: {
- type: 'doc',
- id: 'licensing/index',
- },
- items: ['licensing/register-usage-point', 'licensing/get-usage'],
++ label: 'Troubleshooting',
++ items: [
++ 'lambda/troubleshooting/permissions',
++ 'lambda/troubleshooting/rate-limit',
++ ],
+ },
++ 'lambda/changelog',
++ 'lambda/upgrading',
++ 'lambda/uninstall',
+ ],
- mainSidebar: [
++ someSidebar: [
+ {
++ collapsed: false,
+ type: 'category',
+ label: 'Getting started',
+ items: [
+ 'getting-started',
+ 'the-fundamentals',
+ 'animating-properties',
+ 'reusability',
- 'preview',
++ 'timeline',
++ 'render',
+ ],
+ },
+ {
+ type: 'category',
- label: 'Designing visuals',
++ label: 'Techniques',
++ collapsed: false,
+ items: [
- 'transforms',
+ 'assets',
- 'layers',
- 'transitioning',
+ 'using-audio',
+ 'fonts',
- 'measuring',
+ 'using-randomness',
+ 'audio-visualization',
- 'noise-visualization',
- 'animation-math',
- ],
- },
- {
- type: 'category',
- label: 'Embedding videos',
- items: [
- 'videos/index',
- 'miscellaneous/snippets/align-duration',
- 'videos/sequence',
- 'videos/transparency',
++ 'use-img-and-iframe',
++ 'javascript',
++ 'data-fetching',
++ 'encoding',
++ 'transparent-videos',
++ 'parametrized-rendering',
++ 'dynamic-metadata',
++ 'ssr',
++ 'webpack',
++ 'legacy-babel',
++ 'env-variables',
++ 'third-party',
++ 'stills',
++ 'scaling',
+ 'video-manipulation',
- 'miscellaneous/snippets/accelerated-video',
- 'miscellaneous/snippets/jumpcuts',
- 'miscellaneous/snippets/freeze-portions',
- 'miscellaneous/snippets/hls',
- 'video-vs-offthreadvideo',
+ ],
+ },
+ {
+ type: 'category',
- label: 'Parameterized videos',
++ label: 'CLI',
+ link: {
+ type: 'doc',
- id: 'parameterized-rendering',
++ id: 'cli/cli',
+ },
++ collapsed: true,
+ items: [
- 'passing-props',
- 'schemas',
- 'visual-editing',
- 'data-fetching',
- 'dynamic-metadata',
- 'props-resolution',
++ 'cli/preview',
++ 'cli/render',
++ 'cli/still',
++ 'cli/compositions',
++ {
++ type: 'link',
++ href: '/docs/lambda/cli',
++ label: 'lambda ↗️',
++ },
++ 'cli/versions',
++ 'cli/upgrade',
++ 'cli/help',
+ ],
+ },
-
++ 'config',
+ {
+ type: 'category',
- label: 'Rendering',
- link: {
- type: 'doc',
- id: 'render',
- },
++ label: 'API - Core',
++ collapsed: false,
+ items: [
- 'encoding',
- 'stills',
- 'scaling',
- 'transparent-videos',
- 'render-as-gif',
- 'overlay',
- 'quality',
- 'dataset-render',
- 'render-all',
- 'miscellaneous/video-formats',
- 'artifacts',
- 'metadata',
- 'hardware-acceleration',
++ 'continue-render',
++ 'delay-render',
++ 'interpolate',
++ 'interpolate-colors',
++ 'get-input-props',
++ 'measure-spring',
++ 'random',
++ 'register-root',
++ 'spring',
++ 'staticfile',
++ 'use-current-frame',
++ 'use-video-config',
++ 'audio',
++ 'composition',
++ 'sequence',
++ 'loop',
++ 'video',
++ 'offthreadvideo',
++ 'absolute-fill',
++ 'img',
++ 'iframe',
++ 'freeze',
++ 'still',
++ 'series',
++ 'folder',
++ 'easing',
+ ],
+ },
+ {
+ type: 'category',
- label: 'Studio',
- items: [
- 'studio/studio',
- 'studio/shortcuts',
- 'studio/quick-switcher',
- 'studio/deploy-static',
- 'studio/deploy-server',
- ],
++ label: 'API - @remotion/bundler',
++ items: ['bundle'],
+ },
++ 'gif',
+ {
+ type: 'category',
- label: 'Server-side rendering',
- link: {
- type: 'doc',
- id: 'ssr',
- },
++ label: 'API - @remotion/media-utils',
+ items: [
- 'ssr',
- 'ssr-node',
- 'docker',
- 'miscellaneous/linux-single-process',
- 'gpu',
- 'miscellaneous/cloud-gpu',
- 'miscellaneous/cloud-gpu-docker',
- 'compare-ssr',
++ 'audio-buffer-to-data-url',
++ 'get-audio-data',
++ 'get-audio-duration-in-seconds',
++ 'get-video-metadata',
++ 'get-waveform-portion',
++ 'use-audio-data',
++ 'visualize-audio',
++ 'visualize-audio-waveform',
+ ],
+ },
++ {
++ type: 'link',
++ href: '/docs/lambda',
++ label: 'API - @remotion/lambda',
++ },
+ {
+ type: 'category',
+ link: {
+ type: 'doc',
- id: 'player/index',
++ id: 'player/player',
+ },
- label: 'Player',
++ label: 'API - @remotion/player',
+ items: [
- {
- type: 'link',
- href: '/docs/player/player',
- label: 'API Reference',
- },
++ 'player/installation',
+ 'player/examples',
++ 'player/api',
+ 'player/scaling',
+ 'player/integration',
+ 'player/autoplay',
- 'player/current-time',
- 'troubleshooting/player-flicker',
- 'player/buffer-state',
+ 'player/preloading',
- 'player/premounting',
- 'player/best-practices',
- 'player/drag-and-drop/index',
- 'player/custom-controls',
- 'player/media-keys',
- 'player/playback-issues',
- ],
- },
-
- {
- type: 'category',
- label: 'Lambda',
- link: {
- type: 'doc',
- id: 'lambda',
- },
- items: [
- {
- type: 'link',
- href: '/docs/lambda/api',
- label: 'API Reference',
- },
- 'lambda/setup',
- 'lambda/authentication',
- 'lambda/permissions',
- 'lambda/region-selection',
- 'lambda/concurrency',
- 'lambda/runtime',
- 'lambda/disk-size',
- 'lambda/faq',
- 'lambda/light-client',
- 'lambda/custom-layers',
- 'lambda/custom-destination',
- 'lambda/checklist',
- 'lambda/webhooks',
- 'lambda/cost-example',
- 'lambda/autodelete',
- {
- type: 'category',
- label: 'Troubleshooting',
- items: [
- 'lambda/troubleshooting/debug',
- 'lambda/troubleshooting/permissions',
- 'lambda/troubleshooting/rate-limit',
- 'lambda/troubleshooting/unrecognizedclientexception',
- 'lambda/troubleshooting/bucket-disallows-acl',
- 'lambda/troubleshooting/security-token',
- ],
- },
- {
- type: 'category',
- label: 'Using without IAM users',
- link: {
- type: 'doc',
- id: 'lambda/without-iam/index',
- },
- items: [
- 'lambda/without-iam/index',
- 'lambda/without-iam/example',
- 'lambda/without-iam/ec2',
- ],
- },
- 'lambda/php',
- 'lambda/go',
- 'lambda/python',
- 'lambda/ruby',
- 'lambda/serverless-framework-integration',
- 'lambda/supabase',
- 'lambda/r2',
- 'lambda/insights',
- 'lambda/multiple-buckets',
- 'lambda/how-lambda-works',
- 'lambda/bucket-naming',
- 'lambda/optimizing-cost',
- 'lambda/optimizing-speed',
- 'lambda/limits',
- 'lambda/changelog',
- 'lambda/upgrading',
- 'lambda/uninstall',
- 'lambda/s3-public-access',
- 'lambda/naming-convention',
+ ],
+ },
+ {
+ type: 'category',
- label: 'Cloud Run',
++ label: 'API - @remotion/three',
+ link: {
+ type: 'doc',
- id: 'cloudrun-alpha',
++ id: 'three',
+ },
- items: [
- 'cloudrun',
- 'cloudrun/setup',
- 'cloudrun/permissions',
- 'cloudrun/generate-env',
- 'cloudrun/region-selection',
- 'cloudrun/checklist',
- 'cloudrun/instancecount',
- 'cloudrun/multiple-buckets',
- 'cloudrun/limits',
- 'cloudrun/light-client',
- 'cloudrun/upgrading',
- 'cloudrun/uninstall',
- ],
++ items: ['three-canvas', 'use-video-texture'],
+ },
+ {
+ type: 'category',
- label: 'Media Parser',
++ label: 'API - @remotion/preload',
+ link: {
+ type: 'doc',
- id: 'media-parser/index',
++ id: 'preload/preload',
+ },
+ items: [
- {
- type: 'link',
- href: '/docs/media-parser/parse-media',
- label: 'API Reference',
- },
- 'media-parser/fields',
- 'media-parser/metadata',
- 'media-parser/fast-and-slow',
- 'media-parser/tags',
- 'media-parser/format-support',
- 'media-parser/runtime-support',
- 'media-parser/pause-resume-abort',
- 'media-parser/webcodecs',
- 'media-parser/foreign-file-types',
- 'media-parser/stream-selection',
++ 'preload/preload-video',
++ 'preload/preload-audio',
++ 'preload/resolve-redirect',
+ ],
+ },
+ {
+ type: 'category',
- label: 'WebCodecs',
+ link: {
+ type: 'doc',
- id: 'webcodecs/index',
++ id: 'renderer',
+ },
++ label: 'API - @remotion/renderer',
+ items: [
- {
- type: 'link',
- href: '/docs/webcodecs/convert-media',
- label: 'API Reference',
- },
- 'webcodecs/convert-a-video',
- 'webcodecs/rotate-a-video',
- 'webcodecs/resize-a-video',
- 'webcodecs/fix-mediarecorder-video',
- 'webcodecs/track-transformation',
- 'webcodecs/pause-resume-abort',
- 'webcodecs/telemetry',
- ],
- },
- {
- type: 'category',
- label: 'Building apps',
- items: [
- 'brownfield',
- 'studio-into-app',
- 'player-into-remotion-project',
- 'video-uploads',
- 'presigned-urls',
- 'font-picker',
- 'building-a-timeline',
- 'multiple-fps',
- 'angular',
- 'svelte',
- 'vue',
- ],
- },
- {
- type: 'category',
- label: 'Tooling',
- items: [
- 'tailwind',
- 'env-variables',
- 'webpack',
- 'legacy-babel',
- 'javascript',
- 'third-party',
- 'miscellaneous/typescript-aliases',
- 'figma',
- 'spline',
- 'after-effects',
++ 'renderer/get-compositions',
++ 'renderer/render-media',
++ 'renderer/render-frames',
++ 'renderer/render-still',
++ 'renderer/stitch-frames-to-video',
++ 'renderer/open-browser',
++ 'renderer/make-cancel-signal',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Troubleshooting',
++ collapsed: false,
+ items: [
- 'troubleshooting/debug-failed-render',
+ 'timeout',
+ 'target-closed',
+ 'media-playback-error',
+ 'performance',
+ 'webpack-dynamic-imports',
+ 'non-seekable-media',
+ 'flickering',
+ 'version-mismatch',
+ 'enametoolong',
+ 'slow-method-to-extract-frame',
- 'wrong-composition-mount',
- 'staticfile-relative-paths',
- 'staticfile-remote-urls',
- 'troubleshooting/background-image',
- 'troubleshooting/nextjs-image',
- 'troubleshooting/rosetta',
- 'troubleshooting/loading-root-component',
- 'troubleshooting/defaultprops-too-big',
- 'troubleshooting/could-not-be-parsed-as-a-value-list',
- 'troubleshooting/broken-fast-refresh',
- 'troubleshooting/timed-out-page-function',
- 'troubleshooting/delay-render-proxy',
- 'troubleshooting/bundling-bundle',
- 'troubleshooting/browser-launch',
- 'troubleshooting/sigkill',
- 'troubleshooting/subpixel-rendering',
- 'troubleshooting/could-not-find-executable-to-run',
- 'troubleshooting/stuck-render',
- ],
- },
- {
- type: 'category',
- label: 'Snippets',
- items: [
- 'miscellaneous/snippets/different-segments-at-different-speeds',
- 'miscellaneous/snippets/player-in-iframe',
- 'miscellaneous/snippets/use-delay-render',
- 'miscellaneous/snippets/offthread-video-while-rendering',
- 'miscellaneous/snippets/combine-compositions',
- ],
- },
- {
- type: 'link',
- href: '/docs/api',
- label: 'API Reference',
- },
- 'upgrading',
- {
- type: 'link',
- href: '/docs/recorder',
- label: 'Recorder',
- },
- {
- type: 'category',
- label: 'Terminology',
- link: {
- type: 'doc',
- id: 'terminology',
- },
- items: [
- 'terminology/player',
- 'terminology/studio',
- 'terminology/concurrency',
- 'terminology/input-props',
- 'terminology/cloud-run-url',
- 'terminology/service-name',
- 'terminology/entry-point',
- 'terminology/root-file',
- 'terminology/remotion-root',
- 'terminology/public-dir',
- 'terminology/serve-url',
- 'terminology/bundle',
- 'terminology/sequence',
- 'terminology/composition',
- ],
- },
- 'resources',
- {
- type: 'category',
- label: 'Migration guides',
- items: [
- 'react-19',
- '5-0-migration',
- '4-0-migration',
- '3-0-migration',
- '2-0-migration',
- ],
- },
- {
- type: 'category',
- label: 'Get help',
- link: {
- type: 'doc',
- id: 'get-help',
- },
- items: [
- {
- type: 'link',
- href: '/docs/get-help',
- label: 'How to get help',
- },
- {
- type: 'link',
- href: 'https://remotion.dev/discord',
- label: 'Discord',
- },
- {
- type: 'link',
- href: 'https://remotion.dev/discord',
- label: 'GitHub Issues',
- },
- 'support',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Miscellaneous',
++ collapsed: false,
+ items: [
- 'security',
++ 'brownfield',
+ 'chromium-flags',
- 'miscellaneous/changing-temp-dir',
- 'miscellaneous/chrome-headless-shell',
- 'miscellaneous/linux-dependencies',
- 'gl-options',
- 'bun',
- 'deno',
- 'standalone',
- 'miscellaneous/emojis',
- 'media-fragments',
- 'system-prompt',
- ],
- },
- {
- type: 'category',
- label: 'FAQ',
- items: [
- 'miscellaneous/render-in-browser',
- 'miscellaneous/automatic-duration',
- 'miscellaneous/vercel-functions',
- 'miscellaneous/render-on-edge',
- 'miscellaneous/embed-studio',
- 'miscellaneous/absolute-paths',
- 'miscellaneous/live-streaming',
- 'miscellaneous/parse-media-vs-get-video-metadata',
- 'compare/motion-canvas',
- ],
- },
- {
- type: 'category',
- label: 'Contributing',
- items: [
- 'contributing/index',
- 'contributing/feature',
- 'contributing/option',
- 'contributing/docs',
- 'contributing/formatting',
- 'contributing/bounty',
- 'contributing/rust',
- 'contributing/presentation',
- 'authoring-packages',
++ 'video-vs-offthreadvideo',
+ 'prereleases',
- 'contributing/ineligible',
++ 'gpu',
++ 'react-18',
++ 'miscellaneous/typescript-aliases',
+ ],
+ },
++ '3-0-migration',
++ '2-0-migration',
+ 'license',
- 'acknowledgements',
- ],
- recorderSidebar: [
- {
- type: 'category',
- label: 'Recorder',
- items: [
- 'recorder/index',
- 'recorder/before-you-buy',
- 'recorder/buy',
- 'recorder/demo',
- 'recorder/setup',
- 'recorder/create',
- {
- type: 'category',
- label: 'Record',
- items: [
- 'recorder/record/index',
- 'recorder/record/manually',
- 'recorder/record/delete',
- 'recorder/record/cropping',
- ],
- },
- 'recorder/captions',
- {
- type: 'category',
- label: 'Editing',
- collapsed: false,
- items: [
- 'recorder/editing/editing',
- 'recorder/editing/silence-removal',
- 'recorder/editing/captions',
- 'recorder/editing/layout',
- 'recorder/editing/scenes',
- 'recorder/editing/endcard',
- 'recorder/editing/transitions',
- 'recorder/editing/chapters',
- 'recorder/editing/music',
- 'recorder/editing/b-roll',
- 'recorder/editing/cutting-clips',
- 'recorder/editing/normalizing-audio',
- ],
- },
- {
- type: 'category',
- label: 'Exporting',
- collapsed: false,
- items: [
- 'recorder/exporting',
- 'recorder/lambda-rendering',
- 'recorder/exporting-subtitles',
- ],
- },
- 'recorder/source-control',
- 'recorder/external-recordings',
- 'recorder/upgrading',
- {
- type: 'category',
- label: 'Troubleshooting',
- items: [
- 'recorder/troubleshooting/failed-to-execute-get-video-metadata',
- 'recorder/troubleshooting/cannot-read-properties-of-undefined',
- ],
- },
- 'recorder/roadmap',
- 'recorder/gear',
- 'recorder/our-recorder',
- 'recorder/support',
- ],
- },
+ ],
};
diff --cc packages/media-utils/src/get-wave-form-samples.ts
index d9d4070e3a,70020f3a9d..2bb1297979
--- a/packages/media-utils/src/get-wave-form-samples.ts
+++ b/packages/media-utils/src/get-wave-form-samples.ts
@@@ -22,10 -12,7 +22,10 @@@ export const getWaveformSamples = (
sum += Math.abs(audioBuffer[blockStart + j]); // find the sum of all the samples in the block
}
- filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
+ filteredData.push(
+ (sum / blockSize) *
- (i % 2 === 0 && outputRange === 'minus-one-to-one' ? -1 : 1)
++ (i % 2 === 0 && outputRange === 'minus-one-to-one' ? -1 : 1),
+ ); // divide the sum by the block size to get the average
}
return filteredData;
diff --cc packages/media-utils/src/get-waveform-portion.ts
index e6f938db60,cba71d0f3a..c659d83c44
--- a/packages/media-utils/src/get-waveform-portion.ts
+++ b/packages/media-utils/src/get-waveform-portion.ts
@@@ -8,30 -6,11 +8,34 @@@ type Bar =
amplitude: number;
};
+const concatArrays = (arrays: Float32Array[]): Float32Array => {
+ // sum of individual array lengths
+ const totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
+
+ const result = new Float32Array(totalLength);
+
+ // for each array - copy it over result
+ // next array is copied right after the previous one
+ let length = 0;
+ for (const array of arrays) {
+ result.set(array, length);
+ length += array.length;
+ }
+
+ return result;
+};
+
+type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;
+
+function truthy<T>(value: T): value is Truthy<T> {
+ return Boolean(value);
+}
+
- const getWaveformPortion = ({
+ /*
+ * @description Takes bulky waveform data (for example fetched by getAudioData()) and returns a trimmed and simplified version of it, for simpler visualization
+ * @see [Documentation](https://remotion.dev/docs/get-waveform-portion)
+ */
+ export const getWaveformPortion = ({
audioData,
startTimeInSeconds,
durationInSeconds,
@@@ -43,50 -20,23 +47,50 @@@
startTimeInSeconds: number;
durationInSeconds: number;
numberOfSamples: number;
+ channel: number;
+ outputRange?: SampleOutputRange;
}): Bar[] => {
+ validateChannel(channel, audioData.numberOfChannels);
+
+ const waveform = audioData.channelWaveforms[channel];
+
const startSample = Math.floor(
- (startTimeInSeconds / audioData.durationInSeconds) * waveform.length
- (startTimeInSeconds / audioData.durationInSeconds) *
- audioData.channelWaveforms[0].length,
++ (startTimeInSeconds / audioData.durationInSeconds) * waveform.length,
);
const endSample = Math.floor(
((startTimeInSeconds + durationInSeconds) / audioData.durationInSeconds) *
- waveform.length
- audioData.channelWaveforms[0].length,
++ waveform.length,
);
- return getWaveformSamples(
- audioData.channelWaveforms[0].slice(startSample, endSample),
+ const samplesBeforeStart = 0 - startSample;
+ const samplesAfterEnd = endSample - waveform.length;
+
+ const clampedStart = Math.max(startSample, 0);
+ const clampedEnd = Math.min(waveform.length, endSample);
+
+ const padStart =
+ samplesBeforeStart > 0
+ ? new Float32Array(samplesBeforeStart).fill(0)
+ : null;
+ const padEnd =
+ samplesAfterEnd > 0 ? new Float32Array(samplesAfterEnd).fill(0) : null;
+ const arrs = [
+ padStart,
+ waveform.slice(clampedStart, clampedEnd),
+ padEnd,
+ ].filter(truthy);
+ const audioBuffer = arrs.length === 1 ? arrs[0] : concatArrays(arrs);
+
+ return getWaveformSamples({
+ audioBuffer,
numberOfSamples,
- ).map((w, i) => {
+ outputRange,
+ }).map((w, i) => {
return {
index: i,
amplitude: w,
};
});
};
+
- export {getWaveformPortion, Bar};
++export {Bar};
diff --cc packages/media-utils/src/index.ts
index fb875a0382,aa3798bcc3..041417ea20
--- a/packages/media-utils/src/index.ts
+++ b/packages/media-utils/src/index.ts
@@@ -5,9 -4,17 +5,19 @@@ export
getAudioDuration,
getAudioDurationInSeconds,
} from './get-audio-duration-in-seconds';
+ export {getImageDimensions} from './get-image-dimensions';
+ export {getPartialWaveData} from './get-partial-wave-data';
export {getVideoMetadata} from './get-video-metadata';
export {getWaveformPortion} from './get-waveform-portion';
- export {AudioData, VideoMetadata} from './types';
+ export {WaveProbe, probeWaveFile} from './probe-wave-file';
+ export * from './types';
++export {VideoMetadata} from './types';
+ export type {AudioData, VideoMetadata as VideoData} from './types';
export {useAudioData} from './use-audio-data';
- export {visualizeAudio} from './visualize-audio';
+ export {
+ UseWindowedAudioDataOptions,
+ UseWindowedAudioDataReturnValue,
+ useWindowedAudioData,
+ } from './use-windowed-audio-data';
+ export {VisualizeAudioOptions, visualizeAudio} from './visualize-audio';
+export {visualizeAudioWaveform} from './visualize-audio-waveform';
diff --cc packages/studio/src/components/AudioWaveform.tsx
index 0000000000,fff32049c1..a5d666020a
mode 000000,100644..100644
--- a/packages/studio/src/components/AudioWaveform.tsx
+++ b/packages/studio/src/components/AudioWaveform.tsx
@@@ -1,0 -1,177 +1,179 @@@
+ import type {AudioData} from '@remotion/media-utils';
+ import {getAudioData, getWaveformPortion} from '@remotion/media-utils';
+ import React, {useEffect, useMemo, useRef, useState} from 'react';
+ import {Internals} from 'remotion';
+ import {LIGHT_TRANSPARENT} from '../helpers/colors';
+ import {
+ TIMELINE_BORDER,
+ TIMELINE_LAYER_HEIGHT,
+ } from '../helpers/timeline-layout';
+ import {
+ AudioWaveformBar,
+ WAVEFORM_BAR_LENGTH,
+ WAVEFORM_BAR_MARGIN,
+ } from './AudioWaveformBar';
+
+ const container: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'row',
+ alignItems: 'center',
+ position: 'absolute',
+ height: TIMELINE_LAYER_HEIGHT,
+ };
+ const errorMessage: React.CSSProperties = {
+ fontSize: 13,
+ paddingTop: 6,
+ paddingBottom: 6,
+ paddingLeft: 12,
+ paddingRight: 12,
+ alignSelf: 'flex-start',
+ maxWidth: 450,
+ opacity: 0.75,
+ };
+
+ const canvasStyle: React.CSSProperties = {
+ position: 'absolute',
+ };
+
+ export const AudioWaveform: React.FC<{
+ readonly src: string;
+ readonly visualizationWidth: number;
+ readonly startFrom: number;
+ readonly durationInFrames: number;
+ readonly setMaxMediaDuration: React.Dispatch<React.SetStateAction<number>>;
+ readonly volume: string | number;
+ readonly doesVolumeChange: boolean;
+ readonly playbackRate: number;
+ }> = ({
+ src,
+ startFrom,
+ durationInFrames,
+ visualizationWidth,
+ setMaxMediaDuration,
+ volume,
+ doesVolumeChange,
+ playbackRate,
+ }) => {
+ const [metadata, setMetadata] = useState<AudioData | null>(null);
+ const [error, setError] = useState<Error | null>(null);
+ const mountState = useRef({isMounted: true});
+ const vidConf = Internals.useUnsafeVideoConfig();
+ if (vidConf === null) {
+ throw new Error('Expected video config');
+ }
+
+ const canvas = useRef<HTMLCanvasElement>(null);
+
+ useEffect(() => {
+ const {current} = mountState;
+ current.isMounted = true;
+ return () => {
+ current.isMounted = false;
+ };
+ }, []);
+
+ useEffect(() => {
+ if (!canvas.current) {
+ return;
+ }
+
+ const context = canvas.current.getContext('2d');
+ if (!context) {
+ return;
+ }
+
+ context.clearRect(0, 0, visualizationWidth, TIMELINE_LAYER_HEIGHT);
+ if (!doesVolumeChange || typeof volume === 'number') {
+ // The volume is a number, meaning it could change on each frame-
+ // User did not use the (f: number) => number syntax, so we can't draw
+ // a visualization.
+ return;
+ }
+
+ const volumes = volume.split(',').map((v) => Number(v));
+ context.beginPath();
+ context.moveTo(0, TIMELINE_LAYER_HEIGHT);
+ volumes.forEach((v, index) => {
+ const x = (index / (volumes.length - 1)) * visualizationWidth;
+ const y = (1 - v) * (TIMELINE_LAYER_HEIGHT - TIMELINE_BORDER * 2) + 1;
+ if (index === 0) {
+ context.moveTo(x, y);
+ } else {
+ context.lineTo(x, y);
+ }
+ });
+ context.strokeStyle = LIGHT_TRANSPARENT;
+ context.stroke();
+ }, [visualizationWidth, metadata, startFrom, volume, doesVolumeChange]);
+
+ useEffect(() => {
+ setError(null);
+ getAudioData(src)
+ .then((data) => {
+ if (mountState.current.isMounted) {
+ setMaxMediaDuration(Math.floor(data.durationInSeconds * vidConf.fps));
+ setMetadata(data);
+ }
+ })
+ .catch((err) => {
+ if (mountState.current.isMounted) {
+ setError(err);
+ }
+ });
+ }, [setMaxMediaDuration, src, vidConf.fps]);
+
+ const normalized = useMemo(() => {
+ if (!metadata || metadata.numberOfChannels === 0) {
+ return [];
+ }
+
+ const numberOfSamples = Math.floor(
+ visualizationWidth / (WAVEFORM_BAR_LENGTH + WAVEFORM_BAR_MARGIN),
+ );
+
+ return getWaveformPortion({
+ audioData: metadata,
+ startTimeInSeconds: startFrom / vidConf.fps,
+ durationInSeconds: (durationInFrames / vidConf.fps) * playbackRate,
+ numberOfSamples,
++ channel: 0,
++ outputRange: 'zero-to-one',
+ });
+ }, [
+ durationInFrames,
+ vidConf.fps,
+ metadata,
+ playbackRate,
+ startFrom,
+ visualizationWidth,
+ ]);
+
+ if (error) {
+ return (
+ <div style={container}>
+ <div style={errorMessage}>
+ No waveform available. Audio might not support CORS.
+ </div>
+ </div>
+ );
+ }
+
+ if (!metadata) {
+ return null;
+ }
+
+ return (
+ <div style={container}>
+ {normalized.map((w) => {
+ return <AudioWaveformBar key={w.index} amplitude={w.amplitude} />;
+ })}
+
+ <canvas
+ ref={canvas}
+ style={canvasStyle}
+ width={visualizationWidth}
+ height={TIMELINE_LAYER_HEIGHT}
+ />
+ </div>
+ );
+ };