Skip to content

🎥 Make videos programmatically with React

almost done

JonnyBurgerc879446dce20
diff --git a/bun.lock b/bun.lock
index c18ff5c446..0f77705ed3 100644
--- a/bun.lock
+++ b/bun.lock
@@ -243,7 +243,6 @@
"@remotion/captions": "workspace:*",
"@remotion/media-parser": "workspace:*",
"@remotion/shapes": "workspace:*",
- "@remotion/webcodecs": "workspace:*",
"@remotion/whisper-web": "workspace:*",
"@vercel/remix": "^2.15.2",
"class-variance-authority": "^0.7.0",
diff --git a/packages/convert/app/components/AudioTrackOverview.tsx b/packages/convert/app/components/AudioTrackOverview.tsx
index 9e66de4bbb..7948b41fbd 100644
--- a/packages/convert/app/components/AudioTrackOverview.tsx
+++ b/packages/convert/app/components/AudioTrackOverview.tsx
@@ -1,17 +1,10 @@
-import type {
- MediaParserAudioTrack,
- MediaParserLocation,
- MediaParserMetadataEntry,
-} from '@remotion/media-parser';
+import type {InputAudioTrack} from 'mediabunny';
import {renderHumanReadableAudioCodec} from '~/lib/render-codec-label';
-import {MetadataDisplay} from './MetadataTable';
import {Table, TableBody, TableCell, TableRow} from './ui/table';
export const AudioTrackOverview: React.FC<{
- readonly track: MediaParserAudioTrack;
- readonly metadata: MediaParserMetadataEntry[] | null;
- location: MediaParserLocation | null;
-}> = ({track, metadata, location}) => {
+ readonly track: InputAudioTrack;
+}> = ({track}) => {
return (
<Table className="table-fixed">
<TableBody>
@@ -22,7 +15,7 @@ export const AudioTrackOverview: React.FC<{
<TableRow>
<TableCell className="font-brand">Codec</TableCell>
<TableCell className="text-right">
- {renderHumanReadableAudioCodec(track.codecEnum)}
+ {renderHumanReadableAudioCodec(track.codec)}
</TableCell>
</TableRow>
<TableRow>
@@ -37,11 +30,6 @@ export const AudioTrackOverview: React.FC<{
<TableCell className="font-brand">Sample Rate</TableCell>
<TableCell className="text-right">{track.sampleRate}</TableCell>
</TableRow>
- <MetadataDisplay
- location={location}
- metadata={metadata ?? []}
- trackId={track.trackId}
- />
</TableBody>
</Table>
);
diff --git a/packages/convert/app/components/ContainerOverview.tsx b/packages/convert/app/components/ContainerOverview.tsx
index 217b739d81..13d4321f30 100644
--- a/packages/convert/app/components/ContainerOverview.tsx
+++ b/packages/convert/app/components/ContainerOverview.tsx
@@ -1,33 +1,31 @@
import {Table, TableBody, TableCell, TableRow} from '@/components/ui/table';
import type {
- MediaParserContainer,
- MediaParserDimensions,
- MediaParserLocation,
- MediaParserMetadataEntry,
-} from '@remotion/media-parser';
-import type {InputAudioTrack, InputVideoTrack} from 'mediabunny';
+ InputAudioTrack,
+ InputFormat,
+ InputVideoTrack,
+ MetadataTags,
+} from 'mediabunny';
import React from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
import {formatBytes} from '~/lib/format-bytes';
import {formatSeconds} from '~/lib/format-seconds';
import {
renderHumanReadableAudioCodec,
- renderHumanReadableContainer,
renderHumanReadableVideoCodec,
} from '~/lib/render-codec-label';
import {MetadataDisplay} from './MetadataTable';
import {Skeleton} from './ui/skeleton';
export const ContainerOverview: React.FC<{
- readonly dimensions: MediaParserDimensions | null | undefined;
+ readonly dimensions: Dimensions | null | undefined;
readonly durationInSeconds: number | null | undefined;
readonly videoCodec: InputVideoTrack['codec'] | null;
readonly audioCodec: InputAudioTrack['codec'] | null | undefined;
readonly size: number | null;
readonly fps: number | null | undefined;
- readonly container: MediaParserContainer | null;
+ readonly container: InputFormat | null;
readonly isHdr: boolean | undefined;
- readonly metadata: MediaParserMetadataEntry[] | null;
- readonly location: MediaParserLocation | null;
+ readonly metadata: MetadataTags | null;
readonly isAudioOnly: boolean;
readonly sampleRate: number | null;
}> = ({
@@ -40,7 +38,6 @@ export const ContainerOverview: React.FC<{
fps,
isHdr,
metadata,
- location,
isAudioOnly,
sampleRate,
}) => {
@@ -51,7 +48,7 @@ export const ContainerOverview: React.FC<{
<TableCell className="font-brand">Container</TableCell>
<TableCell className="text-right">
{container ? (
- <>{renderHumanReadableContainer(container)}</>
+ container.name
) : (
<Skeleton className="h-3 w-[100px] inline-block" />
)}
@@ -155,11 +152,7 @@ export const ContainerOverview: React.FC<{
</TableCell>
</TableRow>
)}
- <MetadataDisplay
- location={location}
- metadata={metadata ?? []}
- trackId={null}
- />
+ {metadata ? <MetadataDisplay metadata={metadata} /> : null}
</TableBody>
</Table>
);
diff --git a/packages/convert/app/components/ConversionDone.tsx b/packages/convert/app/components/ConversionDone.tsx
index 6058d0fb17..1b07e4eff7 100644
--- a/packages/convert/app/components/ConversionDone.tsx
+++ b/packages/convert/app/components/ConversionDone.tsx
@@ -1,8 +1,5 @@
import React, {useCallback} from 'react';
-import {canUseOutputAsInput} from '~/lib/can-use-output-as-input';
import type {ConvertState, Source} from '~/lib/convert-state';
-import {getNewName} from '~/lib/generate-new-name';
-import type {OutputContainer} from '~/seo';
import {CloneIcon} from './icons/clone';
import {UndoIcon} from './icons/undo';
import {Button} from './ui/button';
@@ -10,24 +7,18 @@ import {Button} from './ui/button';
export const ConversionDone: React.FC<{
readonly state: ConvertState;
readonly setState: React.Dispatch<React.SetStateAction<ConvertState>>;
- readonly name: string | null;
- readonly container: OutputContainer;
readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
-}> = ({state, name, container, setState, setSrc}) => {
+}> = ({state, setState, setSrc}) => {
if (state.type !== 'done') {
throw new Error('Expected state to be done');
}
const onDownload = useCallback(async () => {
- if (!name) {
- throw new Error('Expected name to be set');
- }
-
try {
const file = await state.download();
const a = document.createElement('a');
a.href = URL.createObjectURL(file);
- a.download = getNewName(name, container);
+ a.download = state.newName;
a.click();
URL.revokeObjectURL(a.href);
} catch (e) {
@@ -35,7 +26,7 @@ export const ConversionDone: React.FC<{
console.error(e);
setState({type: 'error', error: e as Error});
}
- }, [container, name, setState, state]);
+ }, [setState, state]);
const useAsInput = useCallback(async () => {
const file = await state.download();
@@ -55,21 +46,19 @@ export const ConversionDone: React.FC<{
<Button className="block w-full" type="button" onClick={onDownload}>
Download
</Button>
- {canUseOutputAsInput(container) ? (
- <>
- <div className="h-2" />
- <Button
- variant="ghost"
- className="w-full flex flex-row justify-start"
- type="button"
- onClick={useAsInput}
- >
- <CloneIcon className="size-4" />
- <div className="w-2" />
- Use new video as input
- </Button>
- </>
- ) : null}
+ <>
+ <div className="h-2" />
+ <Button
+ variant="ghost"
+ className="w-full flex flex-row justify-start"
+ type="button"
+ onClick={useAsInput}
+ >
+ <CloneIcon className="size-4" />
+ <div className="w-2" />
+ Use as input
+ </Button>
+ </>
<Button
variant="ghost"
className="w-full flex flex-row justify-start"
diff --git a/packages/convert/app/components/ConvertProgress.tsx b/packages/convert/app/components/ConvertProgress.tsx
index bde7dd6439..cef8d535e4 100644
--- a/packages/convert/app/components/ConvertProgress.tsx
+++ b/packages/convert/app/components/ConvertProgress.tsx
@@ -2,13 +2,11 @@ import React, {createRef} from 'react';
import {formatBytes} from '~/lib/format-bytes';
import {formatElapsedTime} from '~/lib/format-elapsed-time';
import {formatSeconds} from '~/lib/format-seconds';
-import {getNewName} from '~/lib/generate-new-name';
import type {ConvertProgressType} from '~/lib/progress';
import {
useAddOutputFilenameToTitle,
useAddProgressToTitle,
} from '~/lib/title-context';
-import type {OutputContainer} from '~/seo';
import {AudioWaveForm, AudioWaveformContainer} from './AudioWaveform';
import {Card} from './ui/card';
import {Skeleton} from './ui/skeleton';
@@ -19,8 +17,7 @@ export const convertProgressRef = createRef<VideoThumbnailRef>();
export const ConvertProgress: React.FC<{
readonly state: ConvertProgressType;
- readonly name: string | null;
- readonly container: OutputContainer;
+ readonly newName: string | null;
readonly done: boolean;
readonly duration: number | null;
readonly isReencoding: boolean;
@@ -30,9 +27,8 @@ export const ConvertProgress: React.FC<{
readonly completedTime?: number;
}> = ({
state,
- name,
+ newName,
bars,
- container,
done,
isReencoding,
duration,
@@ -43,8 +39,6 @@ export const ConvertProgress: React.FC<{
const progress = done ? 1 : state.overallProgress;
useAddProgressToTitle(progress);
- const newName = name ? getNewName(name, container) : null;
-
useAddOutputFilenameToTitle(newName);
return (
@@ -83,7 +77,7 @@ export const ConvertProgress: React.FC<{
) : null}
<div className="p-2">
<div>
- {name ? (
+ {newName ? (
<strong className="font-brand ">{newName}</strong>
) : (
<Skeleton className="h-4 w-[200px]" />
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index da1ec578ed..8fc2743157 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -1,11 +1,11 @@
import {Button} from '@/components/ui/button';
import type {
- MediaParserAudioCodec,
- MediaParserContainer,
- MediaParserDimensions,
- MediaParserTrack,
-} from '@remotion/media-parser';
-import type {InputVideoTrack, Rotation} from 'mediabunny';
+ InputAudioTrack,
+ InputFormat,
+ InputTrack,
+ InputVideoTrack,
+ Rotation,
+} from 'mediabunny';
import {
ALL_FORMATS,
BlobSource,
@@ -16,15 +16,18 @@ import {
UrlSource,
} from 'mediabunny';
import React, {useCallback, useMemo, useState} from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
+import {calculateNewDimensionsFromRotateAndScale} from '~/lib/calculate-new-dimensions-from-dimensions';
import {canRotateOrMirror} from '~/lib/can-rotate-or-mirror';
import type {ConvertState, Source} from '~/lib/convert-state';
import type {ConvertSections, RotateOrMirrorState} from '~/lib/default-ui';
import {getOrderOfSections, isConvertEnabledByDefault} from '~/lib/default-ui';
+import {getNewName} from '~/lib/generate-new-name';
import {getActualVideoOperation} from '~/lib/get-audio-video-config-index';
+import {getDefaultOutputFormat} from '~/lib/get-default-output-format';
import {getInitialResizeSuggestion} from '~/lib/get-initial-resize-suggestion';
import {isReencoding} from '~/lib/is-reencoding';
import {isSubmitDisabled} from '~/lib/is-submit-enabled';
-import {generateOutputFilename} from '~/lib/make-output-filename';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
import {calculateMediabunnyResizeOption} from '~/lib/mediabunny-calculate-resize-option';
import {getMediabunnyOutput} from '~/lib/output-container';
@@ -38,7 +41,6 @@ import {ConvertProgress, convertProgressRef} from './ConvertProgress';
import {ConvertUiSection} from './ConvertUiSection';
import {ErrorState} from './ErrorState';
import {flipVideoFrame} from './flip-video';
-import {getDefaultContainerForConversion} from './guess-codec-from-source';
import {MirrorComponents} from './MirrorComponents';
import {PauseResumeAndCancel} from './PauseResumeAndCancel';
import {ResampleUi} from './ResampleUi';
@@ -73,18 +75,18 @@ const ConvertUI = ({
}: {
readonly src: Source;
readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
- readonly currentAudioCodec: MediaParserAudioCodec | null;
+ readonly currentAudioCodec: InputAudioTrack['codec'] | null;
readonly currentVideoCodec: InputVideoTrack['codec'] | null;
- readonly tracks: MediaParserTrack[] | null;
+ readonly tracks: InputTrack[] | null;
readonly videoThumbnailRef: React.RefObject<VideoThumbnailRef | null>;
- readonly unrotatedDimensions: MediaParserDimensions | null;
- readonly dimensions: MediaParserDimensions | null | undefined;
+ readonly unrotatedDimensions: Dimensions | null;
+ readonly dimensions: Dimensions | null | undefined;
readonly durationInSeconds: number | null;
readonly fps: number | null;
readonly rotation: number | null;
- readonly inputContainer: MediaParserContainer | null;
+ readonly inputContainer: InputFormat;
readonly action: RouteAction;
- readonly name: string | null;
+ readonly name: string;
readonly enableRotateOrMirror: RotateOrMirrorState;
readonly setEnableRotateOrMirror: React.Dispatch<
React.SetStateAction<RotateOrMirrorState | null>
@@ -97,8 +99,8 @@ const ConvertUI = ({
readonly setFlipVertical: React.Dispatch<React.SetStateAction<boolean>>;
readonly sampleRate: number | null;
}) => {
- const [outputContainer, setContainer] = useState<OutputContainer>(() =>
- getDefaultContainerForConversion(src, action),
+ const [outputContainer, setOutputContainer] = useState<OutputContainer>(() =>
+ getDefaultOutputFormat(inputContainer),
);
const [videoOperationSelection, setVideoOperationKey] = useState<
Record<number, string>
@@ -132,9 +134,8 @@ const ConvertUI = ({
useState(false);
const [resampleRate, setResampleRate] = useState<number>(16000);
- const canResample = useMemo(() => {
- return outputContainer === 'wav';
- }, [outputContainer]);
+ // TODO: No
+ const canResample = false;
const actualResampleRate = useMemo(() => {
if (!canResample) {
@@ -165,7 +166,7 @@ const ConvertUI = ({
videoConfigIndexSelection: videoOperationSelection,
operations: o.operations,
});
- return operation.type === 'reencode' && operation.videoCodec === 'h264';
+ return operation.type === 'reencode' && operation.videoCodec === 'avc';
});
const setVideoConfigIndex = useCallback((trackId: number, key: string) => {
@@ -208,12 +209,17 @@ const ConvertUI = ({
let cancelConversion = () => {};
const run = async () => {
- const filename = generateOutputFilename(src, outputContainer);
+ if (!outputContainer) {
+ throw new Error('No output container selected');
+ }
+
+ const outputFormat = getMediabunnyOutput(outputContainer);
+ const filename = getNewName(name, outputFormat);
const {getBlob, stream, getWrittenByteCount, close} =
await makeWebFsTarget(filename);
const output = new Output({
- format: getMediabunnyOutput(outputContainer),
+ format: outputFormat,
target: new StreamTarget(stream),
});
@@ -291,6 +297,7 @@ const ConvertUI = ({
onAbort: cancelConversion,
state: progress,
startTime,
+ newName: filename,
});
};
@@ -307,6 +314,7 @@ const ConvertUI = ({
state: progress,
startTime,
completedTime: Date.now(),
+ newName: filename,
});
};
@@ -319,10 +327,11 @@ const ConvertUI = ({
enableRotateOrMirror,
flipHorizontal,
flipVertical,
+ outputContainer,
+ name,
dimensions,
resizeOperation,
onWaveformBars,
- outputContainer,
src,
userRotation,
]);
@@ -366,7 +375,7 @@ const ConvertUI = ({
return null;
}
- return WebCodecsInternals.calculateNewDimensionsFromDimensions({
+ return calculateNewDimensionsFromRotateAndScale({
...unrotatedDimensions,
rotation: userRotation - (rotation ?? 0),
resizeOperation,
@@ -401,8 +410,7 @@ const ConvertUI = ({
<>
<ConvertProgress
state={state.state}
- name={name}
- container={outputContainer}
+ newName={state.newName}
done={false}
duration={durationInSeconds}
isReencoding={
@@ -429,8 +437,7 @@ const ConvertUI = ({
<ConvertProgress
done
state={state.state}
- name={name}
- container={outputContainer}
+ newName={state.newName}
duration={durationInSeconds}
isReencoding={
supportedConfigs !== null &&
@@ -486,7 +493,7 @@ const ConvertUI = ({
<ConvertForm
{...{
container: outputContainer,
- setContainer,
+ setContainer: setOutputContainer,
flipHorizontal,
flipVertical,
setFlipHorizontal,
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsx
index cffe6fefc9..9532afe5b3 100644
--- a/packages/convert/app/components/FileAvailable.tsx
+++ b/packages/convert/app/components/FileAvailable.tsx
@@ -1,10 +1,8 @@
-import type {ParseMediaOnProgress} from '@remotion/media-parser';
-import React, {useCallback, useMemo, useRef, useState} from 'react';
+import React, {useMemo, useRef, useState} from 'react';
import {normalizeVideoRotation} from '~/lib/calculate-new-dimensions-from-dimensions';
import type {Source} from '~/lib/convert-state';
import type {RotateOrMirrorState} from '~/lib/default-ui';
import {defaultRotateOrMirorState} from '~/lib/default-ui';
-import {formatBytes} from '~/lib/format-bytes';
import type {RouteAction} from '~/seo';
import {BackButton} from './BackButton';
import ConvertUI from './ConvertUi';
@@ -27,32 +25,11 @@ export const FileAvailable: React.FC<{
const videoThumbnailRef = useRef<VideoThumbnailRef>(null);
- const onProgress: ParseMediaOnProgress = useCallback(
- async ({bytes, percentage}) => {
- await new Promise((resolve) => {
- window.requestAnimationFrame(resolve);
- });
- const notDone = document.getElementById('not-done');
- if (notDone) {
- if (percentage === null) {
- notDone.innerHTML = `${formatBytes(bytes)} read`;
- } else {
- notDone.innerHTML = `${Math.round(
- percentage * 100,
- )}% read (${formatBytes(bytes)})`;
- }
- }
- },
- [],
- );
-
const [enableRotateOrMirrow, setEnableRotateOrMirror] =
useState<RotateOrMirrorState>(() => defaultRotateOrMirorState(routeAction));
const probeResult = useProbe({
src,
- logLevel: 'verbose',
- onProgress,
});
const [userRotation, setRotation] = useState(90);
@@ -86,7 +63,9 @@ export const FileAvailable: React.FC<{
mirrorVertical={flipVertical && enableRotateOrMirrow === 'mirror'}
/>
{routeAction.type !== 'generic-probe' &&
- routeAction.type !== 'transcribe' ? (
+ routeAction.type !== 'transcribe' &&
+ probeResult.container !== null &&
+ probeResult.name !== null ? (
<>
<div className="h-8 lg:h-0 lg:w-8" />
<div
diff --git a/packages/convert/app/components/MetadataTable.tsx b/packages/convert/app/components/MetadataTable.tsx
index 92b6c01a96..f17b2332f7 100644
--- a/packages/convert/app/components/MetadataTable.tsx
+++ b/packages/convert/app/components/MetadataTable.tsx
@@ -1,12 +1,8 @@
-import type {
- MediaParserLocation,
- MediaParserMetadataEntry,
-} from '@remotion/media-parser';
-import React, {useMemo} from 'react';
+import type {MetadataTags} from 'mediabunny';
+import React from 'react';
import {
renderMetadataLabel,
renderMetadataValue,
- sortMetadataByRelevance,
} from '~/lib/render-metadata-label';
import {TableCell, TableRow} from './ui/table';
@@ -22,37 +18,33 @@ const LimitedWidthLabel: React.FC<{
};
export const MetadataDisplay: React.FC<{
- readonly metadata: MediaParserMetadataEntry[];
- readonly trackId: number | null;
- readonly location: MediaParserLocation | null;
-}> = ({metadata, trackId, location}) => {
- const filtered = useMemo(() => {
- return sortMetadataByRelevance(metadata).filter((entry) => {
- return entry.trackId === trackId;
- });
- }, [metadata, trackId]);
-
+ readonly metadata: MetadataTags;
+}> = ({metadata}) => {
return (
<>
- {filtered.map((entry, i) => (
- // eslint-disable-next-line react/no-array-index-key
- <TableRow key={entry.key + i}>
- <TableCell className="font-brand">
- <LimitedWidthLabel alt={entry.key}>
- {renderMetadataLabel(entry.key)}
- </LimitedWidthLabel>
- </TableCell>
- <TableCell className="text-right">
- <LimitedWidthLabel alt={entry.key}>
- {renderMetadataValue({
- key: entry.key,
- value: entry.value,
- location,
- })}
- </LimitedWidthLabel>
- </TableCell>
- </TableRow>
- ))}
+ {Object.entries(metadata).map(([key, value]) => {
+ if (typeof value !== 'string' || typeof value !== 'number') {
+ return null;
+ }
+
+ return (
+ <TableRow key={key}>
+ <TableCell className="font-brand">
+ <LimitedWidthLabel alt={key}>
+ {renderMetadataLabel(key)}
+ </LimitedWidthLabel>
+ </TableCell>
+ <TableCell className="text-right">
+ <LimitedWidthLabel alt={key}>
+ {renderMetadataValue({
+ key,
+ value,
+ })}
+ </LimitedWidthLabel>
+ </TableCell>
+ </TableRow>
+ );
+ })}
</>
);
};
diff --git a/packages/convert/app/components/Probe.tsx b/packages/convert/app/components/Probe.tsx
index c948fec9b4..ba78a15974 100644
--- a/packages/convert/app/components/Probe.tsx
+++ b/packages/convert/app/components/Probe.tsx
@@ -97,9 +97,7 @@ export const Probe: React.FC<{
rotation,
error,
metadata,
- location,
keyframes,
- images,
sampleRate,
} = probeResult;
@@ -108,7 +106,7 @@ export const Probe: React.FC<{
}, [setProbeDetails]);
const sortedTracks = useMemo(
- () => (tracks ? tracks.slice().sort((a, b) => a.trackId - b.trackId) : []),
+ () => (tracks ? tracks.slice().sort((a, b) => a.id - b.id) : []),
[tracks],
);
@@ -123,7 +121,7 @@ export const Probe: React.FC<{
return sortedTracks[trackDetails];
}, [probeDetails, sortedTracks, trackDetails]);
- const isAudio = isAudioOnly({tracks, container});
+ const isAudio = isAudioOnly({tracks});
useAddFilenameToTitle(name);
useCopyThumbnailToFavicon(videoThumbnailRef);
@@ -203,23 +201,16 @@ export const Probe: React.FC<{
fps={fps}
metadata={metadata}
isHdr={isHdr}
- location={location}
sampleRate={sampleRate}
/>
- ) : selectedTrack.type === 'video' ? (
+ ) : selectedTrack.isVideoTrack() ? (
<VideoTrackOverview
- location={location}
- metadata={metadata}
track={selectedTrack}
keyframes={keyframes}
durationInSeconds={durationInSeconds ?? null}
/>
- ) : selectedTrack.type === 'audio' ? (
- <AudioTrackOverview
- location={location}
- metadata={metadata}
- track={selectedTrack}
- />
+ ) : selectedTrack.isAudioTrack() ? (
+ <AudioTrackOverview track={selectedTrack} />
) : null}
</ScrollArea>
<Separator orientation="horizontal" />
diff --git a/packages/convert/app/components/ResizeCorner.tsx b/packages/convert/app/components/ResizeCorner.tsx
index 8f57d755f4..c6a0faaa71 100644
--- a/packages/convert/app/components/ResizeCorner.tsx
+++ b/packages/convert/app/components/ResizeCorner.tsx
@@ -1,11 +1,11 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import React, {useCallback} from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
export const ResizeCorner: React.FC<{
- readonly innerDimensions: MediaParserDimensions;
- readonly outerDimensions: MediaParserDimensions;
- readonly videoDimensions: MediaParserDimensions;
+ readonly innerDimensions: Dimensions;
+ readonly outerDimensions: Dimensions;
+ readonly videoDimensions: Dimensions;
readonly setResizeMode: React.Dispatch<
React.SetStateAction<MediabunnyResize | null>
>;
diff --git a/packages/convert/app/components/ResizeShortcuts.tsx b/packages/convert/app/components/ResizeShortcuts.tsx
index 7febd08a20..fb2d625ace 100644
--- a/packages/convert/app/components/ResizeShortcuts.tsx
+++ b/packages/convert/app/components/ResizeShortcuts.tsx
@@ -1,5 +1,5 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import React, {useCallback, useMemo} from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
export const ResizeOption: React.FC<{
@@ -38,8 +38,8 @@ export const ResizeOption: React.FC<{
};
export const ResizeShortcuts: React.FC<{
- readonly originalDimensions: MediaParserDimensions;
- readonly resolvedDimensions: MediaParserDimensions;
+ readonly originalDimensions: Dimensions;
+ readonly resolvedDimensions: Dimensions;
readonly setResizeMode: React.Dispatch<
React.SetStateAction<MediabunnyResize | null>
>;
diff --git a/packages/convert/app/components/ResizeThumbnail.tsx b/packages/convert/app/components/ResizeThumbnail.tsx
index b8b29dba3e..8699bb2eaa 100644
--- a/packages/convert/app/components/ResizeThumbnail.tsx
+++ b/packages/convert/app/components/ResizeThumbnail.tsx
@@ -1,5 +1,5 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import React, {useCallback, useMemo, useRef, useState} from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
import {useThumbnailCopy} from '~/lib/use-thumbnail-copy';
import {ResizeCorner} from './ResizeCorner';
@@ -7,7 +7,7 @@ import type {VideoThumbnailRef} from './VideoThumbnail';
const MAX_THUMBNAIL_SIZE = 150;
-export const getThumbnailDimensions = (dimensions: MediaParserDimensions) => {
+export const getThumbnailDimensions = (dimensions: Dimensions) => {
if (dimensions.height > dimensions.width) {
return {
height: MAX_THUMBNAIL_SIZE,
@@ -26,8 +26,8 @@ export const getThumbnailDimensions = (dimensions: MediaParserDimensions) => {
};
export const ResizeThumbnail: React.FC<{
- readonly dimensions: MediaParserDimensions;
- readonly unrotatedDimensions: MediaParserDimensions;
+ readonly dimensions: Dimensions;
+ readonly unrotatedDimensions: Dimensions;
readonly thumbnailRef: React.RefObject<VideoThumbnailRef | null>;
readonly rotation: number;
readonly scale: number;
diff --git a/packages/convert/app/components/ResizeUi.tsx b/packages/convert/app/components/ResizeUi.tsx
index 6b9cac44e1..ef94f96ef7 100644
--- a/packages/convert/app/components/ResizeUi.tsx
+++ b/packages/convert/app/components/ResizeUi.tsx
@@ -1,5 +1,5 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import React, {useCallback, useMemo} from 'react';
+import type {Dimensions} from '~/lib/calculate-new-dimensions-from-dimensions';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
import {ResizeShortcuts} from './ResizeShortcuts';
import {getThumbnailDimensions, ResizeThumbnail} from './ResizeThumbnail';
@@ -36,8 +36,8 @@ const NumberInput: React.FC<{
};
export const ResizeUi: React.FC<{
- readonly dimensions: MediaParserDimensions;
- readonly originalDimensions: MediaParserDimensions;
+ readonly dimensions: Dimensions;
+ readonly originalDimensions: Dimensions;
readonly thumbnailRef: React.RefObject<VideoThumbnailRef | null>;
readonly rotation: number;
readonly setResizeMode: React.Dispatch<
diff --git a/packages/convert/app/components/TrackSelectionLabels.tsx b/packages/convert/app/components/TrackSelectionLabels.tsx
index e9165b8c1b..3dc16ed22a 100644
--- a/packages/convert/app/components/TrackSelectionLabels.tsx
+++ b/packages/convert/app/components/TrackSelectionLabels.tsx
@@ -1,4 +1,4 @@
-import type {MediaParserAudioCodec} from '@remotion/media-parser';
+import type {InputAudioTrack} from 'mediabunny';
import React from 'react';
import {renderHumanReadableAudioCodec} from '~/lib/render-codec-label';
import {Label} from './ui/label';
@@ -17,7 +17,7 @@ export const VideoTrackLabel: React.FC<{
export const AudioTrackLabel: React.FC<{
readonly trackId: number;
readonly totalAudioTracks: number;
- readonly audioCodec: MediaParserAudioCodec;
+ readonly audioCodec: InputAudioTrack['codec'];
}> = ({trackId, totalAudioTracks, audioCodec}) => {
if (totalAudioTracks === 1) {
return <Label htmlFor="audioCodec">Audio Codec</Label>;
diff --git a/packages/convert/app/components/TrackSwitcher.tsx b/packages/convert/app/components/TrackSwitcher.tsx
index 2d46494ec8..5538516147 100644
--- a/packages/convert/app/components/TrackSwitcher.tsx
+++ b/packages/convert/app/components/TrackSwitcher.tsx
@@ -1,10 +1,10 @@
-import type {MediaParserTrack} from '@remotion/media-parser';
+import type {InputTrack} from 'mediabunny';
import React from 'react';
import {Button} from './ui/button';
import {Separator} from './ui/separator';
export const TrackSwitcher: React.FC<{
- readonly sortedTracks: MediaParserTrack[];
+ readonly sortedTracks: InputTrack[];
readonly onTrack: (trackNumber: number | null) => void;
readonly selectedTrack: number | null;
}> = ({sortedTracks, onTrack, selectedTrack}) => {
@@ -26,15 +26,14 @@ export const TrackSwitcher: React.FC<{
</Button>
{sortedTracks.map((trk, i) => {
return (
- <React.Fragment key={trk.trackId}>
+ <React.Fragment key={trk.id}>
<Separator orientation="vertical" />
<Button
className="rounded-none"
variant={selectedTrack === i ? 'secondary' : 'ghost'}
onClick={() => onTrack(i)}
>
- Track {trk.trackId} (
- {trk.type === 'audio' ? 'Audio' : 'Video'})
+ Track {trk.id} ({trk.type === 'audio' ? 'Audio' : 'Video'})
</Button>
</React.Fragment>
);
diff --git a/packages/convert/app/components/VideoTrackOverview.tsx b/packages/convert/app/components/VideoTrackOverview.tsx
index 6ca2590592..0d12f13f83 100644
--- a/packages/convert/app/components/VideoTrackOverview.tsx
+++ b/packages/convert/app/components/VideoTrackOverview.tsx
@@ -1,22 +1,24 @@
import {Table, TableBody, TableCell, TableRow} from '@/components/ui/table';
-import type {
- MediaParserKeyframe,
- MediaParserLocation,
- MediaParserMetadataEntry,
- MediaParserVideoTrack,
-} from '@remotion/media-parser';
-import React from 'react';
+import type {MediaParserKeyframe} from '@remotion/media-parser';
+import type {InputVideoTrack} from 'mediabunny';
+import React, {useEffect, useState} from 'react';
import {renderHumanReadableVideoCodec} from '~/lib/render-codec-label';
import {KeyframesInfo} from './KeyframesInfo';
-import {MetadataDisplay} from './MetadataTable';
export const VideoTrackOverview: React.FC<{
- readonly track: MediaParserVideoTrack;
- readonly metadata: MediaParserMetadataEntry[] | null;
- readonly location: MediaParserLocation | null;
+ readonly track: InputVideoTrack;
readonly keyframes: MediaParserKeyframe[] | null;
readonly durationInSeconds: number | null;
-}> = ({track, metadata, location, keyframes, durationInSeconds}) => {
+}> = ({track, keyframes, durationInSeconds}) => {
+ const [colorSpace, setColorSpace] = useState<VideoColorSpaceInit | null>(
+ null,
+ );
+ useEffect(() => {
+ track.getColorSpace().then((space) => {
+ setColorSpace(space);
+ });
+ }, [track]);
+
return (
<Table className="table-fixed">
<TableBody>
@@ -27,7 +29,7 @@ export const VideoTrackOverview: React.FC<{
<TableRow>
<TableCell className="font-brand">Codec</TableCell>
<TableCell className="text-right">
- {renderHumanReadableVideoCodec(track.codecEnum)}
+ {renderHumanReadableVideoCodec(track.codec)}
</TableCell>
</TableRow>
<TableRow>
@@ -37,27 +39,18 @@ export const VideoTrackOverview: React.FC<{
<TableRow>
<TableCell className="font-brand">Dimensions</TableCell>
<TableCell className="text-right">
- {track.width}x{track.height}
+ {track.displayWidth}x{track.displayHeight}
</TableCell>
</TableRow>
<TableRow>
<TableCell className="font-brand">Timescale</TableCell>
- <TableCell className="text-right">
- {track.originalTimescale}
- </TableCell>
- </TableRow>
- <TableRow>
- <TableCell className="font-brand">Sample Aspect Ratio</TableCell>
- <TableCell className="text-right">
- {track.sampleAspectRatio.numerator}:
- {track.sampleAspectRatio.denominator}
- </TableCell>
+ <TableCell className="text-right">{track.timeResolution}</TableCell>
</TableRow>
{keyframes !== null ? (
<KeyframesInfo
durationInSeconds={durationInSeconds}
keyframes={keyframes}
- trackId={track.trackId}
+ trackId={track.id}
/>
) : null}
<TableRow>
@@ -70,41 +63,40 @@ export const VideoTrackOverview: React.FC<{
{track.codedWidth}x{track.codedHeight}
</TableCell>
</TableRow>
- <TableRow>
- <TableCell className="font-brand">Color Primaries</TableCell>
- <TableCell className="text-right">
- {track.colorSpace.primaries ?? 'N/A'}
- </TableCell>
- </TableRow>
- <TableRow>
- <TableCell className="font-brand">Color Matrix</TableCell>
- <TableCell className="text-right">
- {track.colorSpace.matrix ?? 'N/A'}
- </TableCell>
- </TableRow>
- <TableRow>
- <TableCell className="font-brand">
- Color Transfer Characteristics
- </TableCell>
- <TableCell className="text-right">
- {track.colorSpace.transfer ?? 'N/A'}
- </TableCell>
- </TableRow>
- <TableRow>
- <TableCell className="font-brand">Color Full Range</TableCell>
- <TableCell className="text-right">
- {track.colorSpace.fullRange
- ? 'Yes'
- : track.colorSpace.fullRange === false
- ? 'No'
- : 'N/A'}
- </TableCell>
- </TableRow>
- <MetadataDisplay
- location={location}
- metadata={metadata ?? []}
- trackId={track.trackId}
- />
+ {colorSpace ? (
+ <>
+ <TableRow>
+ <TableCell className="font-brand">Color Primaries</TableCell>
+ <TableCell className="text-right">
+ {colorSpace.primaries ?? 'N/A'}
+ </TableCell>
+ </TableRow>
+ <TableRow>
+ <TableCell className="font-brand">Color Matrix</TableCell>
+ <TableCell className="text-right">
+ {colorSpace.matrix ?? 'N/A'}
+ </TableCell>
+ </TableRow>
+ <TableRow>
+ <TableCell className="font-brand">
+ Color Transfer Characteristics
+ </TableCell>
+ <TableCell className="text-right">
+ {colorSpace.transfer ?? 'N/A'}
+ </TableCell>
+ </TableRow>
+ <TableRow>
+ <TableCell className="font-brand">Color Full Range</TableCell>
+ <TableCell className="text-right">
+ {colorSpace.fullRange
+ ? 'Yes'
+ : colorSpace.fullRange === false
+ ? 'No'
+ : 'N/A'}
+ </TableCell>
+ </TableRow>
+ </>
+ ) : null}
</TableBody>
</Table>
);
diff --git a/packages/convert/app/components/get-supported-configs.tsx b/packages/convert/app/components/get-supported-configs.tsx
index d43ae62820..cb92f3a518 100644
--- a/packages/convert/app/components/get-supported-configs.tsx
+++ b/packages/convert/app/components/get-supported-configs.tsx
@@ -1,4 +1,3 @@
-import type {MediaParserContainer} from '@remotion/media-parser';
import {
canCopyAudioTrack,
canCopyVideoTrack,
@@ -7,7 +6,7 @@ import {
getAvailableAudioCodecs,
getAvailableVideoCodecs,
} from '@remotion/webcodecs';
-import type {InputAudioTrack, InputTrack} from 'mediabunny';
+import type {InputAudioTrack, InputFormat, InputTrack} from 'mediabunny';
import type {AudioOperation, VideoOperation} from '~/lib/audio-operation';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
import type {OutputContainer, RouteAction} from '~/seo';
@@ -91,107 +90,108 @@ export const getSupportedConfigs = async ({
bitrate: number;
action: RouteAction;
userRotation: number;
- inputContainer: MediaParserContainer;
+ inputContainer: InputFormat;
resizeOperation: MediabunnyResize | null;
sampleRate: number | null;
}): Promise<SupportedConfigs> => {
const availableVideoCodecs = getAvailableVideoCodecs({container});
+ const availableAudioCodecs = getAvailableAudioCodecs({container});
+ const audioTrackOptions: AudioTrackOption[] = [];
const videoTrackOptions: VideoTrackOption[] = [];
const prioritizeCopyOverReencode =
shouldPrioritizeVideoCopyOverReencode(action);
- for (const track of tracks.filter((t) => t.type === 'video')) {
- const options: VideoOperation[] = [];
- const canCopy = canCopyVideoTrack({
- inputTrack: track,
- outputContainer: container,
- rotationToApply: userRotation,
- inputContainer,
- resizeOperation,
- outputVideoCodec: null,
- });
- if (canCopy && prioritizeCopyOverReencode) {
- options.push({
- type: 'copy',
- });
- }
-
- for (const outputCodec of availableVideoCodecs) {
- const canReencode = await canReencodeVideoTrack({
- videoCodec: outputCodec,
- track,
+ for (const track of tracks) {
+ if (track.isVideoTrack()) {
+ const options: VideoOperation[] = [];
+ const canCopy = canCopyVideoTrack({
+ inputTrack: track,
+ outputContainer: container,
+ rotationToApply: userRotation,
+ inputContainer,
resizeOperation,
- rotate: userRotation,
+ outputVideoCodec: null,
});
- if (canReencode) {
+ if (canCopy && prioritizeCopyOverReencode) {
options.push({
- type: 'reencode',
+ type: 'copy',
+ });
+ }
+
+ for (const outputCodec of availableVideoCodecs) {
+ const canReencode = await canReencodeVideoTrack({
videoCodec: outputCodec,
- resize: resizeOperation,
+ track,
+ resizeOperation,
+ rotate: userRotation,
+ });
+ if (canReencode) {
+ options.push({
+ type: 'reencode',
+ videoCodec: outputCodec,
+ resize: resizeOperation,
+ });
+ }
+ }
+
+ if (canCopy && !prioritizeCopyOverReencode) {
+ options.push({
+ type: 'copy',
});
}
- }
- if (canCopy && !prioritizeCopyOverReencode) {
options.push({
- type: 'copy',
+ type: 'drop',
+ });
+ videoTrackOptions.push({
+ trackId: track.id,
+ operations: options,
});
}
- options.push({
- type: 'drop',
- });
- videoTrackOptions.push({
- trackId: track.trackId,
- operations: options,
- });
- }
-
- const availableAudioCodecs = getAvailableAudioCodecs({container});
- const audioTrackOptions: AudioTrackOption[] = [];
-
- for (const track of tracks.filter((t) => t.type === 'audio')) {
- const audioTrackOperations: AudioOperation[] = [];
-
- const canCopy = canCopyAudioTrack({
- inputCodec: track.codecEnum,
- outputContainer: container,
- inputContainer,
- outputAudioCodec: null,
- });
-
- if (canCopy) {
- audioTrackOperations.push({type: 'copy'});
- }
+ if (track.isAudioTrack()) {
+ const audioTrackOperations: AudioOperation[] = [];
- for (const audioCodec of availableAudioCodecs) {
- const canReencode = await canReencodeAudioTrack({
- audioCodec,
- track,
- bitrate,
- sampleRate,
+ const canCopy = canCopyAudioTrack({
+ inputCodec: track.codec,
+ outputContainer: container,
+ inputContainer,
+ outputAudioCodec: null,
});
- if (canReencode) {
- audioTrackOperations.push({
- type: 'reencode',
+ if (canCopy) {
+ audioTrackOperations.push({type: 'copy'});
+ }
+
+ for (const audioCodec of availableAudioCodecs) {
+ const canReencode = await canReencodeAudioTrack({
audioCodec,
+ track,
bitrate,
sampleRate,
});
+
+ if (canReencode) {
+ audioTrackOperations.push({
+ type: 'reencode',
+ audioCodec,
+ bitrate,
+ sampleRate,
+ });
+ }
}
- }
- audioTrackOperations.push({
- type: 'drop',
- });
- audioTrackOptions.push({
- trackId: track.trackId,
- operations: audioTrackOperations,
- audioCodec: track.codecEnum,
- });
+ audioTrackOperations.push({
+ type: 'drop',
+ });
+ audioTrackOptions.push({
+ trackId: track.id,
+ operations: audioTrackOperations,
+ audioCodec: track.codec,
+ });
+ }
}
return {videoTrackOptions, audioTrackOptions};
diff --git a/packages/convert/app/components/guess-codec-from-source.ts b/packages/convert/app/components/guess-codec-from-source.ts
deleted file mode 100644
index 697753b919..0000000000
--- a/packages/convert/app/components/guess-codec-from-source.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-import type {MediaParserContainer} from '@remotion/media-parser';
-import type {Source} from '~/lib/convert-state';
-import type {OutputContainer, RouteAction} from '~/seo';
-
-const guessFromExtension = (src: string): MediaParserContainer => {
- if (src.endsWith('.webm')) {
- return 'webm';
- }
-
- if (src.endsWith('.mkv')) {
- return 'webm';
- }
-
- if (src.endsWith('.avi')) {
- return 'avi';
- }
-
- if (src.endsWith('.mp3')) {
- return 'mp3';
- }
-
- if (src.endsWith('.ts')) {
- return 'transport-stream';
- }
-
- if (src.endsWith('.m3u8')) {
- return 'm3u8';
- }
-
- if (src.endsWith('.wav') || src.endsWith('.wave')) {
- return 'wav';
- }
-
- if (src.endsWith('.flac')) {
- return 'flac';
- }
-
- if (src.endsWith('.mp3')) {
- return 'mp3';
- }
-
- return 'mp4';
-};
-
-export const guessContainerFromSource = (
- source: Source,
-): MediaParserContainer => {
- if (source.type === 'file') {
- return guessFromExtension(
- source.file instanceof File ? source.file.name : source.file.toString(),
- );
- }
-
- if (source.type === 'url') {
- return guessFromExtension(new URL(source.url).pathname);
- }
-
- throw new Error(`Unhandled source type: ${source satisfies never}`);
-};
-
-const shouldKeepSameContainerByDefault = (action: RouteAction) => {
- if (action.type === 'generic-convert') {
- return false;
- }
-
- if (action.type === 'generic-mirror') {
- return true;
- }
-
- if (action.type === 'generic-rotate') {
- return true;
- }
-
- if (action.type === 'mirror-format') {
- return true;
- }
-
- if (action.type === 'rotate-format') {
- return true;
- }
-
- if (action.type === 'convert') {
- return false;
- }
-
- if (action.type === 'generic-probe') {
- return false;
- }
-
- if (action.type === 'resize-format') {
- return true;
- }
-
- if (action.type === 'generic-resize') {
- return true;
- }
-
- if (action.type === 'report') {
- return true;
- }
-
- if (action.type === 'transcribe') {
- return false;
- }
-
- throw new Error(`Unhandled action type: ${action satisfies never}`);
-};
-
-export const getDefaultContainerForConversion = (
- source: Source,
- action: RouteAction,
-): OutputContainer => {
- const guessed = guessContainerFromSource(source);
- const keepSame = shouldKeepSameContainerByDefault(action);
-
- if (guessed === 'avi') {
- return 'mp4';
- }
-
- if (guessed === 'mp4') {
- return keepSame ? 'mp4' : 'webm';
- }
-
- if (guessed === 'webm') {
- return keepSame ? 'webm' : 'mp4';
- }
-
- if (guessed === 'transport-stream') {
- return 'mp4';
- }
-
- if (guessed === 'mp3') {
- return 'wav';
- }
-
- if (guessed === 'wav') {
- return 'wav';
- }
-
- if (guessed === 'aac') {
- return 'wav';
- }
-
- if (guessed === 'flac') {
- return 'wav';
- }
-
- if (guessed === 'm3u8') {
- return 'mp4';
- }
-
- throw new Error('Unhandled container ' + (guessed satisfies never));
-};
diff --git a/packages/convert/app/components/use-probe.ts b/packages/convert/app/components/use-probe.ts
index 3656b22180..8987d3d20f 100644
--- a/packages/convert/app/components/use-probe.ts
+++ b/packages/convert/app/components/use-probe.ts
@@ -1,9 +1,4 @@
-import type {
- MediaParserController,
- MediaParserDimensions,
- MediaParserKeyframe,
-} from '@remotion/media-parser';
-import {mediaParserController} from '@remotion/media-parser';
+import type {MediaParserKeyframe} from '@remotion/media-parser';
import type {
InputAudioTrack,
InputFormat,
@@ -13,6 +8,7 @@ import type {
} from 'mediabunny';
import {ALL_FORMATS, BlobSource, Input, UrlSource} 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';
export type ProbeResult = ReturnType<typeof useProbe>;
@@ -26,11 +22,11 @@ export const useProbe = ({src}: {src: Source}) => {
const [durationInSeconds, setDurationInSeconds] = useState<
number | null | undefined
>(undefined);
- const [dimensions, setDimensions] = useState<
- MediaParserDimensions | undefined | null
- >(undefined);
+ const [dimensions, setDimensions] = useState<Dimensions | undefined | null>(
+ undefined,
+ );
const [unrotatedDimensions, setUnrotatedDimensions] =
- useState<MediaParserDimensions | null>(null);
+ useState<Dimensions | null>(null);
const [name, setName] = useState<string | null>(null);
const [videoCodec, setVideoCodec] = useState<
InputVideoTrack['codec'] | undefined | null
@@ -47,10 +43,6 @@ export const useProbe = ({src}: {src: Source}) => {
const [done, setDone] = useState(false);
const [error, setError] = useState<Error | null>(null);
- const [controller] = useState<MediaParserController>(() =>
- mediaParserController(),
- );
-
const getStart = useCallback(() => {
// TODO: Name
// TODO: HDR
@@ -138,7 +130,6 @@ export const useProbe = ({src}: {src: Source}) => {
metadata,
keyframes,
unrotatedDimensions,
- controller,
sampleRate,
};
}, [
@@ -158,7 +149,6 @@ export const useProbe = ({src}: {src: Source}) => {
metadata,
keyframes,
unrotatedDimensions,
- controller,
sampleRate,
]);
};
diff --git a/packages/convert/app/components/use-supported-configs.ts b/packages/convert/app/components/use-supported-configs.ts
index efd8b7803f..ef2547b61c 100644
--- a/packages/convert/app/components/use-supported-configs.ts
+++ b/packages/convert/app/components/use-supported-configs.ts
@@ -1,7 +1,4 @@
-import type {
- MediaParserContainer,
- MediaParserTrack,
-} from '@remotion/media-parser';
+import type {InputFormat, InputTrack} from 'mediabunny';
import {useEffect, useState} from 'react';
import type {MediabunnyResize} from '~/lib/mediabunny-calculate-resize-option';
import type {OutputContainer, RouteAction} from '~/seo';
@@ -18,16 +15,20 @@ export const useSupportedConfigs = ({
sampleRate,
}: {
outputContainer: OutputContainer;
- tracks: MediaParserTrack[] | null;
+ tracks: InputTrack[] | null;
action: RouteAction;
userRotation: number;
resizeOperation: MediabunnyResize | null;
- inputContainer: MediaParserContainer | null;
+ inputContainer: InputFormat | null;
sampleRate: number | null;
}) => {
const [state, setState] = useState<
- Record<OutputContainer, SupportedConfigs | null>
- >({mp4: null, webm: null, wav: null});
+ Record<OutputContainer, SupportedConfigs | null | undefined>
+ >({
+ mp4: null,
+ webm: null,
+ wav: null,
+ });
useEffect(() => {
if (!tracks || !inputContainer) {
@@ -59,5 +60,5 @@ export const useSupportedConfigs = ({
sampleRate,
]);
- return state[outputContainer];
+ return state[outputContainer] ?? null;
};
diff --git a/packages/convert/app/lib/calculate-new-dimensions-from-dimensions.ts b/packages/convert/app/lib/calculate-new-dimensions-from-dimensions.ts
index 7bab17f33d..2abf0fe4fc 100644
--- a/packages/convert/app/lib/calculate-new-dimensions-from-dimensions.ts
+++ b/packages/convert/app/lib/calculate-new-dimensions-from-dimensions.ts
@@ -1,6 +1,6 @@
import type {MediabunnyResize} from './mediabunny-calculate-resize-option';
-type Dimensions = {
+export type Dimensions = {
width: number;
height: number;
};
diff --git a/packages/convert/app/lib/can-use-output-as-input.ts b/packages/convert/app/lib/can-use-output-as-input.ts
deleted file mode 100644
index e67584839b..0000000000
--- a/packages/convert/app/lib/can-use-output-as-input.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import type {OutputContainer} from '~/seo';
-
-export const canUseOutputAsInput = (container: OutputContainer) => {
- if (container === 'wav') {
- return true;
- }
-
- if (container === 'mp4') {
- return true;
- }
-
- if (container === 'webm') {
- return true;
- }
-
- throw new Error(`Unsupported container: ${container satisfies never}`);
-};
diff --git a/packages/convert/app/lib/convert-state.ts b/packages/convert/app/lib/convert-state.ts
index 2b19cee694..805462b3a2 100644
--- a/packages/convert/app/lib/convert-state.ts
+++ b/packages/convert/app/lib/convert-state.ts
@@ -19,6 +19,7 @@ export type ConvertState =
onAbort: () => void;
state: ConvertProgressType;
startTime: number;
+ newName: string;
}
| {
type: 'done';
@@ -26,6 +27,7 @@ export type ConvertState =
state: ConvertProgressType;
startTime: number;
completedTime: number;
+ newName: string;
}
| {
type: 'error';
diff --git a/packages/convert/app/lib/generate-new-name.ts b/packages/convert/app/lib/generate-new-name.ts
index be192fadc4..5600fc92fd 100644
--- a/packages/convert/app/lib/generate-new-name.ts
+++ b/packages/convert/app/lib/generate-new-name.ts
@@ -1,9 +1,9 @@
-import type {OutputContainer} from '~/seo';
+import type {OutputFormat} from 'mediabunny';
-export const getNewName = (name: string, newContainer: OutputContainer) => {
+export const getNewName = (name: string, newContainer: OutputFormat) => {
const parts = name.split('.');
parts.pop();
- return [...parts, newContainer].join('.');
+ return [...parts].join('.') + newContainer.fileExtension;
};
diff --git a/packages/convert/app/lib/get-default-output-format.ts b/packages/convert/app/lib/get-default-output-format.ts
new file mode 100644
index 0000000000..7f27fd98ba
--- /dev/null
+++ b/packages/convert/app/lib/get-default-output-format.ts
@@ -0,0 +1,18 @@
+import type {InputFormat} from 'mediabunny';
+import {Mp4InputFormat, WebMInputFormat} from 'mediabunny';
+import type {OutputContainer} from '~/seo';
+
+// TODO: Complete the list
+export const getDefaultOutputFormat = (
+ inputContainer: InputFormat,
+): OutputContainer => {
+ if (inputContainer instanceof Mp4InputFormat) {
+ return 'webm';
+ }
+
+ if (inputContainer instanceof WebMInputFormat) {
+ return 'mp4';
+ }
+
+ return 'mp4';
+};
diff --git a/packages/convert/app/lib/get-initial-resize-suggestion.ts b/packages/convert/app/lib/get-initial-resize-suggestion.ts
index 59a9aff1f8..2deaf4c7bc 100644
--- a/packages/convert/app/lib/get-initial-resize-suggestion.ts
+++ b/packages/convert/app/lib/get-initial-resize-suggestion.ts
@@ -1,8 +1,8 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
+import type {Dimensions} from './calculate-new-dimensions-from-dimensions';
import type {MediabunnyResize} from './mediabunny-calculate-resize-option';
export const getInitialResizeSuggestion = (
- rotatedDimensions: MediaParserDimensions | null,
+ rotatedDimensions: Dimensions | null,
): MediabunnyResize => {
if (rotatedDimensions === null) {
return {
diff --git a/packages/convert/app/lib/is-audio-container.ts b/packages/convert/app/lib/is-audio-container.ts
index fc87595c40..6a4b00474a 100644
--- a/packages/convert/app/lib/is-audio-container.ts
+++ b/packages/convert/app/lib/is-audio-container.ts
@@ -1,20 +1,7 @@
-import type {
- MediaParserContainer,
- MediaParserTrack,
-} from '@remotion/media-parser';
-
-export const isAudioOnly = ({
- tracks,
- container,
-}: {
- tracks: MediaParserTrack[] | null;
- container: MediaParserContainer | null;
-}) => {
- if (container === 'mp3') {
- return true;
- }
+import {type InputTrack} from 'mediabunny';
+export const isAudioOnly = ({tracks}: {tracks: InputTrack[] | null}) => {
return (
- (tracks && tracks.filter((t) => t.type === 'video').length === 0) ?? false
+ (tracks && tracks.filter((t) => t.isVideoTrack()).length === 0) ?? false
);
};
diff --git a/packages/convert/app/lib/mediabunny-calculate-resize-option.ts b/packages/convert/app/lib/mediabunny-calculate-resize-option.ts
index b9bb7dc990..96f51a84a7 100644
--- a/packages/convert/app/lib/mediabunny-calculate-resize-option.ts
+++ b/packages/convert/app/lib/mediabunny-calculate-resize-option.ts
@@ -1,5 +1,5 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import type {ConversionVideoOptions} from 'mediabunny';
+import type {Dimensions} from './calculate-new-dimensions-from-dimensions';
export type MediabunnyResize =
| {
@@ -17,7 +17,7 @@ export type MediabunnyResize =
export const calculateMediabunnyResizeOption = (
resizeOperation: MediabunnyResize | null,
- rotatedDimensions: MediaParserDimensions | null,
+ rotatedDimensions: Dimensions | null,
): ConversionVideoOptions => {
if (resizeOperation === null) {
return {};
diff --git a/packages/convert/app/lib/output-container.ts b/packages/convert/app/lib/output-container.ts
index 5f755ea94d..ebd6fac7af 100644
--- a/packages/convert/app/lib/output-container.ts
+++ b/packages/convert/app/lib/output-container.ts
@@ -16,19 +16,3 @@ export const getMediabunnyOutput = (container: OutputContainer) => {
throw new Error('Unsupported mime type: ' + container);
};
-
-export const getExtension = (container: OutputContainer) => {
- if (container === 'mp4') {
- return 'mp4';
- }
-
- if (container === 'webm') {
- return 'webm';
- }
-
- if (container === 'wav') {
- return 'wav';
- }
-
- throw new Error('Unsupported container: ' + container);
-};
diff --git a/packages/convert/app/lib/render-codec-label.ts b/packages/convert/app/lib/render-codec-label.ts
index 782087a9fb..0985a6f9b2 100644
--- a/packages/convert/app/lib/render-codec-label.ts
+++ b/packages/convert/app/lib/render-codec-label.ts
@@ -1,5 +1,5 @@
import type {InputAudioTrack, InputVideoTrack} from 'mediabunny';
-import type {OutputContainer} from '~/seo';
+import type {InputContainer, OutputContainer} from '~/seo';
export const renderHumanReadableAudioCodec = (
codec: InputAudioTrack['codec'],
@@ -137,7 +137,9 @@ export const renderHumanReadableVideoCodec = (
throw new Error(`Unknown video codec ${codec satisfies never}`);
};
-export const renderHumanReadableContainer = (container: OutputContainer) => {
+export const renderHumanReadableContainer = (
+ container: InputContainer | OutputContainer,
+) => {
if (container === 'webm') {
return '.webm';
}
@@ -150,28 +152,12 @@ export const renderHumanReadableContainer = (container: OutputContainer) => {
return '.wav';
}
- if (container === 'avi') {
- return '.avi';
- }
-
- if (container === 'mp3') {
- return '.mp3';
- }
-
- if (container === 'aac') {
- return '.aac';
- }
-
- if (container === 'transport-stream') {
- return '.ts';
- }
-
- if (container === 'flac') {
- return '.flac';
+ if (container === 'mov') {
+ return '.mov';
}
- if (container === 'm3u8') {
- return '.m3u8';
+ if (container === 'mkv') {
+ return '.mkv';
}
throw new Error(`Unknown container ${container satisfies never}`);
diff --git a/packages/convert/app/lib/render-metadata-label.ts b/packages/convert/app/lib/render-metadata-label.ts
index 0fa37548df..eee8f85ad5 100644
--- a/packages/convert/app/lib/render-metadata-label.ts
+++ b/packages/convert/app/lib/render-metadata-label.ts
@@ -1,8 +1,3 @@
-import type {
- MediaParserLocation,
- MediaParserMetadataEntry,
-} from '@remotion/media-parser';
-
export const renderMetadataLabel = (key: string) => {
if (key === 'com.apple.quicktime.location.accuracy.horizontal') {
return 'Location Accuracy (Horizontal)';
@@ -191,86 +186,6 @@ export const renderMetadataLabel = (key: string) => {
return key;
};
-export const sortMetadataByRelevance = (
- metadata: MediaParserMetadataEntry[],
-) => {
- const metadataKeys = [
- // General metadata sorted by relevance
- 'title',
- 'artist',
- 'album',
- 'releaseDate',
- 'genre',
- 'composer',
- 'writer',
- 'director',
- 'producer',
- 'description',
- 'duration',
- 'comment',
- 'encoder',
- 'copyright',
-
- // Apple-specific metadata sorted by relevance
- 'com.apple.quicktime.creationdate', // Relevant: useful for sorting by creation date
- 'com.apple.quicktime.make', // Relevant: manufacturer information
- 'com.apple.quicktime.model', // Relevant: device information can be interesting
- 'com.apple.quicktime.camera.lens_model', // Relevant: for photography enthusiasts
- 'com.apple.quicktime.camera.focal_length.35mm_equivalent', // Relevant: for photography enthusiasts
- 'com.apple.quicktime.software', // Less relevant: technical detail
- 'com.apple.quicktime.location.ISO6709', // Relevant: location information can be useful
- 'com.apple.quicktime.location.accuracy.horizontal', // Relevant: complements location data
- 'com.apple.quicktime.content.identifier', // Less relevant: unique identifier
- 'com.apple.quicktime.information', // Less relevant: technical detail
- 'com.apple.quicktime.live-photo.vitality-score', // Less relevant: specific to live photos
- 'com.apple.quicktime.live-photo.vitality-scoring-version', // Less relevant: specific to live photos
- 'com.apple.quicktime.live-photo.auto', // Less relevant: specific to live photos
- 'com.apple.quicktime.full-frame-rate-playback-intent', // Less relevant: playback detail
- 'major_brand',
- 'minor_version',
- 'compatible_brands',
- 'handler_name',
- 'TIT2',
- 'TPE1',
- 'TALB',
- 'TCON',
- 'TCOM',
- 'TCMP',
- 'COMM',
- 'TYER',
- ];
-
- return metadata.slice().sort((a, b) => {
- const aIndex = metadataKeys.indexOf(a.key);
- const bIndex = metadataKeys.indexOf(b.key);
-
- if (aIndex === -1 && bIndex === -1) {
- return a.key.localeCompare(b.key);
- }
-
- if (aIndex === -1) {
- return 1;
- }
-
- if (bIndex === -1) {
- return -1;
- }
-
- return aIndex - bIndex;
- });
-};
-
-export function displayLocationData(location: MediaParserLocation): string {
- const {latitude, longitude, altitude} = location;
-
- return [
- `${latitude.toFixed(4)}°, ${longitude.toFixed(4)}°`,
- altitude !== null ? `Altitude ${altitude.toFixed(2)}m` : null,
- ]
- .filter(Boolean)
- .join('\n');
-}
-
function formatDateString(dateString: string): string {
// Parse the date string into a Date object
const date = new Date(dateString);
@@ -297,17 +212,11 @@ function formatDateString(dateString: string): string {
export const renderMetadataValue = ({
key,
value,
- location,
}: {
key: string;
value: string | number;
- location: MediaParserLocation | null;
}) => {
if (key === 'com.apple.quicktime.location.ISO6709') {
- if (location) {
- return displayLocationData(location);
- }
-
return String(value);
}
diff --git a/packages/convert/app/lib/use-thumbnail-copy.ts b/packages/convert/app/lib/use-thumbnail-copy.ts
index 75fd814b5a..ab474f3d3b 100644
--- a/packages/convert/app/lib/use-thumbnail-copy.ts
+++ b/packages/convert/app/lib/use-thumbnail-copy.ts
@@ -1,6 +1,6 @@
-import type {MediaParserDimensions} from '@remotion/media-parser';
import {useCallback, useEffect, useState} from 'react';
import type {VideoThumbnailRef} from '~/components/VideoThumbnail';
+import type {Dimensions} from './calculate-new-dimensions-from-dimensions';
export const useThumbnailCopy = ({
sourceRef,
@@ -9,7 +9,7 @@ export const useThumbnailCopy = ({
}: {
sourceRef: React.RefObject<VideoThumbnailRef | null>;
targetRef: React.RefObject<HTMLCanvasElement | null> | null;
- dimensions: MediaParserDimensions;
+ dimensions: Dimensions;
}) => {
const [drawn, setDrawn] = useState(
() => sourceRef.current?.hasBitmap ?? false,
diff --git a/packages/convert/app/seo.ts b/packages/convert/app/seo.ts
index 5e4bd3eb42..5653133cb7 100644
--- a/packages/convert/app/seo.ts
+++ b/packages/convert/app/seo.ts
@@ -1,9 +1,9 @@
-import type {MediaParserContainer} from '@remotion/media-parser';
import {renderHumanReadableContainer} from './lib/render-codec-label';
-export const inputContainers: MediaParserContainer[] = ['mp4', 'webm', 'avi'];
+export const inputContainers = ['mp4', 'webm', 'mov', 'mkv'] as const;
export const outputContainers = ['mp4', 'webm', 'wav'] as const;
+export type InputContainer = (typeof inputContainers)[number];
export type OutputContainer = (typeof outputContainers)[number];
export const parseConvertRouteAction = (action: string) => {
@@ -17,7 +17,7 @@ export const parseConvertRouteAction = (action: string) => {
}
return {
- input: split[0] as OutputContainer,
+ input: split[0] as InputContainer,
output: split[1] as OutputContainer,
};
};
@@ -25,7 +25,7 @@ export const parseConvertRouteAction = (action: string) => {
export type RouteAction =
| {
type: 'convert';
- input: OutputContainer | MediaParserContainer;
+ input: InputContainer;
output: OutputContainer;
}
| {
@@ -36,14 +36,14 @@ export type RouteAction =
}
| {
type: 'rotate-format';
- format: MediaParserContainer | OutputContainer;
+ format: OutputContainer;
}
| {
type: 'generic-mirror';
}
| {
type: 'mirror-format';
- format: MediaParserContainer | OutputContainer;
+ format: OutputContainer;
}
| {
type: 'generic-resize';
@@ -53,7 +53,7 @@ export type RouteAction =
}
| {
type: 'resize-format';
- format: MediaParserContainer | OutputContainer;
+ format: OutputContainer;
}
| {
type: 'generic-probe';