Skip to content

🎥 Make videos programmatically with React

alright

Jonny Burger3e57bc3d501c
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index 460ef21031..30a8a40440 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -10,6 +10,7 @@ import {fetchReader} from '@remotion/media-parser/fetch';
import {webFileReader} from '@remotion/media-parser/web-file';
import {convertMedia, ConvertMediaContainer} from '@remotion/webcodecs';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
+import {canRotateOrMirror} from '~/lib/can-rotate-or-mirror';
import {ConvertState, Source} from '~/lib/convert-state';
import {
ConvertSections,
@@ -17,7 +18,8 @@ import {
isConvertEnabledByDefault,
RotateOrMirrorState,
} from '~/lib/default-ui';
-import {isDroppingEverything, isReencoding} from '~/lib/is-reencoding';
+import {isReencoding} from '~/lib/is-reencoding';
+import {isSubmitDisabled} from '~/lib/is-submit-enabled';
import {RouteAction} from '~/seo';
import {ConversionDone} from './ConversionDone';
import {ConvertForm} from './ConvertForm';
@@ -39,7 +41,7 @@ export default function ConvertUI({
duration,
logLevel,
action,
- enableRotateOrMirrow,
+ enableRotateOrMirror,
setEnableRotateOrMirror,
userRotation,
setRotation,
@@ -56,7 +58,7 @@ export default function ConvertUI({
readonly duration: number | null;
readonly logLevel: LogLevel;
readonly action: RouteAction;
- readonly enableRotateOrMirrow: RotateOrMirrorState;
+ readonly enableRotateOrMirror: RotateOrMirrorState;
readonly setEnableRotateOrMirror: React.Dispatch<
React.SetStateAction<RotateOrMirrorState | null>
>;
@@ -120,8 +122,8 @@ export default function ConvertUI({
onVideoFrame: ({frame}) => {
const flipped = flipVideoFrame({
frame,
- horizontal: flipHorizontal && enableRotateOrMirrow === 'mirror',
- vertical: flipVertical && enableRotateOrMirrow === 'mirror',
+ horizontal: flipHorizontal && enableRotateOrMirror === 'mirror',
+ vertical: flipVertical && enableRotateOrMirror === 'mirror',
});
if (videoFrames % 15 === 0) {
// TODO: Pass rotation that was applied
@@ -142,7 +144,7 @@ export default function ConvertUI({
},
});
},
- container: container as 'webm',
+ container,
signal: abortController.signal,
fields: {
name: true,
@@ -224,7 +226,7 @@ export default function ConvertUI({
supportedConfigs,
audioConfigIndex,
videoConfigIndex,
- enableRotateOrMirrow,
+ enableRotateOrMirror,
logLevel,
]);
@@ -321,17 +323,18 @@ export default function ConvertUI({
);
}
- const disableSubmit =
- !supportedConfigs ||
- isDroppingEverything({
- audioConfigIndex,
- supportedConfigs,
- videoConfigIndex,
- });
+ const disableSubmit = isSubmitDisabled({
+ audioConfigIndex,
+ supportedConfigs,
+ videoConfigIndex,
+ enableConvert,
+ enableRotateOrMirror,
+ });
- const canPixelManipulate =
- (supportedConfigs && isReencoding({supportedConfigs, videoConfigIndex})) ??
- false;
+ const canPixelManipulate = canRotateOrMirror({
+ supportedConfigs,
+ videoConfigIndex,
+ });
return (
<>
@@ -376,12 +379,12 @@ export default function ConvertUI({
return (
<div key="mirror">
<ConvertUiSection
- active={enableRotateOrMirrow === 'mirror'}
+ active={enableRotateOrMirror === 'mirror'}
setActive={onMirrorClick}
>
Mirror
</ConvertUiSection>
- {enableRotateOrMirrow === 'mirror' ? (
+ {enableRotateOrMirror === 'mirror' ? (
<MirrorComponents
canPixelManipulate={canPixelManipulate}
flipHorizontal={flipHorizontal}
@@ -398,12 +401,12 @@ export default function ConvertUI({
return (
<div key="rotate">
<ConvertUiSection
- active={enableRotateOrMirrow === 'rotate'}
+ active={enableRotateOrMirror === 'rotate'}
setActive={onRotateClick}
>
Rotate
</ConvertUiSection>
- {enableRotateOrMirrow === 'rotate' ? (
+ {enableRotateOrMirror === 'rotate' ? (
<RotateComponents
canPixelManipulate={canPixelManipulate}
rotation={userRotation}
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsx
index 9e7ef0bbc5..c13a6891c0 100644
--- a/packages/convert/app/components/FileAvailable.tsx
+++ b/packages/convert/app/components/FileAvailable.tsx
@@ -118,7 +118,7 @@ export const FileAvailable: React.FC<{
duration={probeResult.durationInSeconds ?? null}
logLevel="verbose"
action={routeAction}
- enableRotateOrMirrow={enableRotateOrMirrow}
+ enableRotateOrMirror={enableRotateOrMirrow}
setEnableRotateOrMirror={setEnableRotateOrMirror}
userRotation={actualUserRotation}
setRotation={setRotation}
diff --git a/packages/convert/app/lib/can-rotate-or-mirror.ts b/packages/convert/app/lib/can-rotate-or-mirror.ts
new file mode 100644
index 0000000000..b12fea7b27
--- /dev/null
+++ b/packages/convert/app/lib/can-rotate-or-mirror.ts
@@ -0,0 +1,15 @@
+import {SupportedConfigs} from '~/components/get-supported-configs';
+import {isReencoding} from './is-reencoding';
+
+export const canRotateOrMirror = ({
+ supportedConfigs,
+ videoConfigIndex,
+}: {
+ supportedConfigs: SupportedConfigs | null;
+ videoConfigIndex: Record<number, number>;
+}) => {
+ return (
+ (supportedConfigs && isReencoding({supportedConfigs, videoConfigIndex})) ??
+ false
+ );
+};
diff --git a/packages/convert/app/lib/is-submit-enabled.ts b/packages/convert/app/lib/is-submit-enabled.ts
new file mode 100644
index 0000000000..adc1258882
--- /dev/null
+++ b/packages/convert/app/lib/is-submit-enabled.ts
@@ -0,0 +1,44 @@
+import {SupportedConfigs} from '~/components/get-supported-configs';
+import {canRotateOrMirror} from './can-rotate-or-mirror';
+import {RotateOrMirrorState} from './default-ui';
+import {isDroppingEverything} from './is-reencoding';
+
+export const isSubmitDisabled = ({
+ supportedConfigs,
+ audioConfigIndex,
+ videoConfigIndex,
+ enableConvert,
+ enableRotateOrMirror,
+}: {
+ supportedConfigs: SupportedConfigs | null;
+ audioConfigIndex: Record<number, number>;
+ videoConfigIndex: Record<number, number>;
+ enableConvert: boolean;
+ enableRotateOrMirror: RotateOrMirrorState;
+}) => {
+ if (!supportedConfigs) {
+ return true;
+ }
+
+ const allActionsDisabled = !enableConvert && enableRotateOrMirror === null;
+
+ if (allActionsDisabled) {
+ return true;
+ }
+
+ const isRotatingOrMirroring =
+ enableRotateOrMirror !== null &&
+ canRotateOrMirror({
+ supportedConfigs,
+ videoConfigIndex,
+ });
+ const isConverting =
+ enableConvert &&
+ !isDroppingEverything({
+ audioConfigIndex,
+ supportedConfigs,
+ videoConfigIndex,
+ });
+
+ return !(isRotatingOrMirroring || isConverting);
+};