🎥 Make videos programmatically with React
Use createInputFrom across the monorepo for HLS compatibility
Jonny Burgerb741ac0056ce
diff --git a/packages/convert/app/components/use-probe.ts b/packages/convert/app/components/use-probe.tsindex fc1c23a3d5..3dd3cf8374 100644--- a/packages/convert/app/components/use-probe.ts+++ b/packages/convert/app/components/use-probe.ts@@ -5,7 +5,7 @@ import type {InputVideoTrack,MetadataTags,} from 'mediabunny';-import {ALL_FORMATS, BlobSource, Input, UrlSource} from 'mediabunny';+import {ALL_FORMATS, createInputFrom} from 'mediabunny';import {useCallback, useEffect, useMemo, useState} from 'react';import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';import type {Source} from '~/lib/convert-state';@@ -41,11 +41,10 @@ export const useProbe = ({src}: {src: Source}) => {const [error, setError] = useState<Error | null>(null);const input = useMemo(() => {- return new Input({- formats: ALL_FORMATS,- source:- src.type === 'file' ? new BlobSource(src.file) : new UrlSource(src.url),- });+ return createInputFrom(+ src.type === 'file' ? src.file : src.url,+ ALL_FORMATS,+ );}, [src]);const getStart = useCallback(() => {diff --git a/packages/example/src/get-media-metadata.ts b/packages/example/src/get-media-metadata.tsindex af72ee3da4..4a42075cba 100644--- a/packages/example/src/get-media-metadata.ts+++ b/packages/example/src/get-media-metadata.ts@@ -1,11 +1,8 @@-import {ALL_FORMATS, Input, UrlSource} from 'mediabunny';+import {ALL_FORMATS, createInputFrom} from 'mediabunny';export const getMediaMetadata = async (src: string) => {- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(src, {- getRetryDelay: () => null,- }),+ const input = createInputFrom(src, ALL_FORMATS, {+ getRetryDelay: () => null,});const durationInSeconds = await input.computeDuration();diff --git a/packages/media-utils/src/use-windowed-audio-data.ts b/packages/media-utils/src/use-windowed-audio-data.tsindex 6ac1df2aab..062b938685 100644--- a/packages/media-utils/src/use-windowed-audio-data.ts+++ b/packages/media-utils/src/use-windowed-audio-data.ts@@ -1,11 +1,11 @@import type {InputAudioTrack} from 'mediabunny';+import type {Input} from 'mediabunny';import {ALL_FORMATS,- Input,InputDisposedError,MATROSKA,- UrlSource,WEBM,+ createInputFrom,} from 'mediabunny';import {useCallback,@@ -102,10 +102,7 @@ export const useWindowedAudioData = ({signal.addEventListener('abort', cont, {once: true});- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(src),- });+ const input = createInputFrom(src, ALL_FORMATS);const onAbort = () => {input.dispose();diff --git a/packages/studio/src/components/CurrentAsset.tsx b/packages/studio/src/components/CurrentAsset.tsxindex 003e7f6b27..43c1bdf380 100644--- a/packages/studio/src/components/CurrentAsset.tsx+++ b/packages/studio/src/components/CurrentAsset.tsx@@ -1,5 +1,5 @@import {formatBytes} from '@remotion/studio-shared';-import {ALL_FORMATS, Input, UrlSource} from 'mediabunny';+import {ALL_FORMATS, createInputFrom} from 'mediabunny';import React, {useContext, useEffect, useMemo, useState} from 'react';import {Internals, staticFile} from 'remotion';import {BACKGROUND, BORDER_COLOR} from '../helpers/colors';@@ -88,10 +88,7 @@ export const CurrentAsset: React.FC = () => {}const url = staticFile(assetName);- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(url),- });+ const input = createInputFrom(url, ALL_FORMATS);Promise.all([input.computeDuration(),diff --git a/packages/studio/src/components/load-waveform-peaks.ts b/packages/studio/src/components/load-waveform-peaks.tsindex 0796507f52..248ecb3041 100644--- a/packages/studio/src/components/load-waveform-peaks.ts+++ b/packages/studio/src/components/load-waveform-peaks.ts@@ -1,4 +1,4 @@-import {ALL_FORMATS, AudioSampleSink, Input, UrlSource} from 'mediabunny';+import {ALL_FORMATS, AudioSampleSink, createInputFrom} from 'mediabunny';const TARGET_SAMPLE_RATE = 100;@@ -13,10 +13,7 @@ export async function loadWaveformPeaks(const cached = peaksCache.get(url);if (cached) return cached;- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(url),- });+ const input = createInputFrom(url, ALL_FORMATS);try {const audioTrack = await input.getPrimaryAudioTrack();diff --git a/packages/studio/src/helpers/extract-frames.ts b/packages/studio/src/helpers/extract-frames.tsindex aefa3671d5..6dc55f4d34 100644--- a/packages/studio/src/helpers/extract-frames.ts+++ b/packages/studio/src/helpers/extract-frames.ts@@ -1,10 +1,9 @@import type {VideoSample} from 'mediabunny';import {ALL_FORMATS,- Input,InputDisposedError,- UrlSource,VideoSampleSink,+ createInputFrom,} from 'mediabunny';type Options = {@@ -30,10 +29,7 @@ export async function extractFrames({onVideoSample,signal,}: ExtractFramesProps): Promise<void> {- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(src),- });+ const input = createInputFrom(src, ALL_FORMATS);const dispose = () => {input.dispose();diff --git a/packages/studio/src/helpers/use-max-media-duration.ts b/packages/studio/src/helpers/use-max-media-duration.tsindex 26b43f747e..62320d76ff 100644--- a/packages/studio/src/helpers/use-max-media-duration.ts+++ b/packages/studio/src/helpers/use-max-media-duration.ts@@ -1,5 +1,5 @@import {getVideoMetadata} from '@remotion/media-utils';-import {ALL_FORMATS, Input, InputDisposedError, UrlSource} from 'mediabunny';+import {ALL_FORMATS, InputDisposedError, createInputFrom} from 'mediabunny';import {useEffect, useState} from 'react';import {type TSequence} from 'remotion';@@ -29,10 +29,7 @@ export const useMaxMediaDuration = (s: TSequence, fps: number) => {return;}- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(src),- });+ const input = createInputFrom(src, ALL_FORMATS);input.computeDuration().then((duration) => {diff --git a/packages/template-music-visualization/src/Root.tsx b/packages/template-music-visualization/src/Root.tsxindex a0c31ee366..991df3c7cd 100644--- a/packages/template-music-visualization/src/Root.tsx+++ b/packages/template-music-visualization/src/Root.tsx@@ -1,4 +1,4 @@-import { ALL_FORMATS, Input, UrlSource } from "mediabunny";+import { ALL_FORMATS, createInputFrom } from "mediabunny";import { Composition, staticFile } from "remotion";import { Visualizer } from "./Visualizer/Main";import { visualizerCompositionSchema } from "./helpers/schema";@@ -35,11 +35,8 @@ export const RemotionRoot: React.FC = () => {}}// Determine the length of the video based on the duration of the audio filecalculateMetadata={async ({ props }) => {- const input = new Input({- source: new UrlSource(props.audioFileUrl, {- getRetryDelay: () => null,- }),- formats: ALL_FORMATS,+ const input = createInputFrom(props.audioFileUrl, ALL_FORMATS, {+ getRetryDelay: () => null,});const durationInSeconds = await input.computeDuration();diff --git a/packages/template-recorder/src/helpers/convert-in-browser.ts b/packages/template-recorder/src/helpers/convert-in-browser.tsindex 75edb345f8..d6c257a0d0 100644--- a/packages/template-recorder/src/helpers/convert-in-browser.ts+++ b/packages/template-recorder/src/helpers/convert-in-browser.ts@@ -1,10 +1,9 @@import {ALL_FORMATS,- BlobSource,BufferTarget,Conversion,- Input,Output,+ createInputFrom,} from "mediabunny";import { getMediabunnyOutput } from "./find-good-supported-codec";@@ -17,10 +16,7 @@ export const convertInBrowser = async ({onProgress: (progress: number, abort: () => void) => void;mimeType: string;}) => {- const input = new Input({- formats: ALL_FORMATS,- source: new BlobSource(src),- });+ const input = createInputFrom(src, ALL_FORMATS);const output = new Output({format: getMediabunnyOutput(mimeType),target: new BufferTarget(),diff --git a/packages/template-three/src/helpers/get-media-metadata.ts b/packages/template-three/src/helpers/get-media-metadata.tsindex e3dbb33393..b883b70d6d 100644--- a/packages/template-three/src/helpers/get-media-metadata.ts+++ b/packages/template-three/src/helpers/get-media-metadata.ts@@ -1,11 +1,8 @@-import { ALL_FORMATS, Input, UrlSource } from "mediabunny";+import { ALL_FORMATS, createInputFrom } from "mediabunny";export const getMediaMetadata = async (src: string) => {- const input = new Input({- formats: ALL_FORMATS,- source: new UrlSource(src, {- getRetryDelay: () => null,- }),+ const input = createInputFrom(src, ALL_FORMATS, {+ getRetryDelay: () => null,});const durationInSeconds = await input.computeDuration();