Skip to content

🎥 Make videos programmatically with React

make it work

Jonny Burger0d755c544c2e
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index a2ec503377..e92ae9bd39 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -11,7 +11,9 @@ import {webFileReader} from '@remotion/media-parser/web-file';
import {convertMedia, ConvertMediaContainer} from '@remotion/webcodecs';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {ConvertState, Source} from '~/lib/convert-state';
+import {isConvertEnabledByDefault} from '~/lib/default-ui';
import {isDroppingEverything, isReencoding} from '~/lib/is-reencoding';
+import {RouteAction} from '~/seo';
import {ConversionDone} from './ConversionDone';
import {ConvertForm} from './ConvertForm';
import {ConvertProgress, convertProgressRef} from './ConvertProgress';
@@ -31,6 +33,7 @@ export default function ConvertUI({
setSrc,
duration,
logLevel,
+ action,
}: {
readonly src: Source;
readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
@@ -39,6 +42,7 @@ export default function ConvertUI({
readonly tracks: TracksField | null;
readonly duration: number | null;
readonly logLevel: LogLevel;
+ readonly action: RouteAction;
}) {
const [container, setContainer] = useState<ConvertMediaContainer>(() =>
getDefaultContainerForConversion(src),
@@ -53,7 +57,9 @@ export default function ConvertUI({
const [name, setName] = useState<string | null>(null);
const [flipHorizontal, setFlipHorizontal] = useState(true);
const [flipVertical, setFlipVertical] = useState(false);
- const [enableConvert, setEnableConvert] = useState(true);
+ const [enableConvert, setEnableConvert] = useState(() =>
+ isConvertEnabledByDefault(action),
+ );
const [enableRotateOrMirrow, setEnableRotateOrMirror] = useState<
'rotate' | 'mirror' | null
>(null);
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsx
index 6512e3f0d0..1b2b76776d 100644
--- a/packages/convert/app/components/FileAvailable.tsx
+++ b/packages/convert/app/components/FileAvailable.tsx
@@ -2,6 +2,7 @@ import {ParseMediaOnProgress} from '@remotion/media-parser';
import React, {useCallback, useRef, useState} from 'react';
import {Source} from '~/lib/convert-state';
import {formatBytes} from '~/lib/format-bytes';
+import {RouteAction} from '~/seo';
import ConvertUI from './ConvertUi';
import {Footer} from './Footer';
import {Probe} from './Probe';
@@ -12,7 +13,8 @@ import {useProbe} from './use-probe';
export const FileAvailable: React.FC<{
readonly src: Source;
readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
-}> = ({src, setSrc}) => {
+ readonly routeAction: RouteAction;
+}> = ({src, setSrc, routeAction}) => {
const [probeDetails, setProbeDetails] = useState(false);
const clear = useCallback(() => {
@@ -93,6 +95,7 @@ export const FileAvailable: React.FC<{
setSrc={setSrc}
duration={probeResult.durationInSeconds ?? null}
logLevel="verbose"
+ action={routeAction}
/>
</div>
</div>
diff --git a/packages/convert/app/components/Main.tsx b/packages/convert/app/components/Main.tsx
index db4450f1b4..23c64f328b 100644
--- a/packages/convert/app/components/Main.tsx
+++ b/packages/convert/app/components/Main.tsx
@@ -1,13 +1,13 @@
import {useLocation} from '@remix-run/react';
import React, {useEffect, useState} from 'react';
import {Source} from '~/lib/convert-state';
+import {getHeaderTitle, getPageTitle, RouteAction} from '~/seo';
import {FileAvailable} from './FileAvailable';
import {PickFile} from './PickFile';
export const Main: React.FC<{
- readonly headerTitle: string;
- readonly pageTitle: string;
-}> = ({headerTitle, pageTitle}) => {
+ readonly routeAction: RouteAction;
+}> = ({routeAction}) => {
const location = useLocation();
const [url] = useState(new URLSearchParams(location.search));
@@ -16,19 +16,20 @@ export const Main: React.FC<{
);
useEffect(() => {
- document.title = pageTitle;
- }, [pageTitle]);
+ document.title = getPageTitle(routeAction);
+ }, [routeAction]);
return (
<div className="font-sans min-h-screen ">
{src ? (
<FileAvailable
key={src.type === 'url' ? src.url : src.file.name}
+ routeAction={routeAction}
src={src}
setSrc={setSrc}
/>
) : (
- <PickFile setSrc={setSrc} title={headerTitle} />
+ <PickFile setSrc={setSrc} title={getHeaderTitle(routeAction)} />
)}
</div>
);
diff --git a/packages/convert/app/lib/default-ui.ts b/packages/convert/app/lib/default-ui.ts
new file mode 100644
index 0000000000..c51ee8b515
--- /dev/null
+++ b/packages/convert/app/lib/default-ui.ts
@@ -0,0 +1,19 @@
+import {RouteAction} from '~/seo';
+
+export const isConvertEnabledByDefault = (action: RouteAction) => {
+ if (action.type === 'convert') {
+ return true;
+ }
+
+ if (action.type === 'generic-convert') {
+ return true;
+ }
+
+ if (action.type === 'generic-rotate') {
+ return false;
+ }
+
+ throw new Error(
+ 'Convert is not enabled by default ' + (action satisfies never),
+ );
+};
diff --git a/packages/convert/app/routes/_index.tsx b/packages/convert/app/routes/_index.tsx
index 429d9f06e4..bf58e9901f 100644
--- a/packages/convert/app/routes/_index.tsx
+++ b/packages/convert/app/routes/_index.tsx
@@ -1,10 +1,12 @@
import {Main} from '~/components/Main';
-import {getHeaderTitle, getPageTitle} from '~/seo';
+import {RouteAction} from '~/seo';
+
+const action: RouteAction = {
+ type: 'generic-convert',
+};
const Index = () => {
- return (
- <Main headerTitle={getHeaderTitle(null)} pageTitle={getPageTitle(null)} />
- );
+ return <Main routeAction={action} />;
};
export default Index;
diff --git a/packages/convert/app/routes/convert.$action.tsx b/packages/convert/app/routes/convert.$action.tsx
index fbff7b2966..4266b1400f 100644
--- a/packages/convert/app/routes/convert.$action.tsx
+++ b/packages/convert/app/routes/convert.$action.tsx
@@ -1,16 +1,22 @@
import {useParams} from '@remix-run/react';
+import {useMemo} from 'react';
import {Main} from '~/components/Main';
-import {getHeaderTitle, getPageTitle, parseRouteAction} from '~/seo';
+import {parseRouteAction, RouteAction} from '~/seo';
const Index = () => {
- const {input, output} = parseRouteAction(useParams().action as string);
+ const action = useParams().action as string;
- return (
- <Main
- pageTitle={getPageTitle({input, output, type: 'convert'})}
- headerTitle={getHeaderTitle({input, output, type: 'convert'})}
- />
- );
+ const routeAction: RouteAction = useMemo(() => {
+ const {input, output} = parseRouteAction(action);
+
+ return {
+ type: 'convert',
+ input,
+ output,
+ };
+ }, [action]);
+
+ return <Main routeAction={routeAction} />;
};
export default Index;
diff --git a/packages/convert/app/routes/convert._index.tsx b/packages/convert/app/routes/convert._index.tsx
index f9728c86e6..bf58e9901f 100644
--- a/packages/convert/app/routes/convert._index.tsx
+++ b/packages/convert/app/routes/convert._index.tsx
@@ -1,13 +1,12 @@
import {Main} from '~/components/Main';
-import {getHeaderTitle, getPageTitle} from '~/seo';
+import {RouteAction} from '~/seo';
+
+const action: RouteAction = {
+ type: 'generic-convert',
+};
const Index = () => {
- return (
- <Main
- headerTitle={getHeaderTitle({type: 'generic-convert'})}
- pageTitle={getPageTitle({type: 'generic-convert'})}
- />
- );
+ return <Main routeAction={action} />;
};
export default Index;
diff --git a/packages/convert/app/routes/rotate._index.tsx b/packages/convert/app/routes/rotate._index.tsx
index e47f4e3674..c710eaa298 100644
--- a/packages/convert/app/routes/rotate._index.tsx
+++ b/packages/convert/app/routes/rotate._index.tsx
@@ -1,13 +1,12 @@
import {Main} from '~/components/Main';
-import {getHeaderTitle, getPageTitle} from '~/seo';
+import {RouteAction} from '~/seo';
+
+const action: RouteAction = {
+ type: 'generic-rotate',
+};
const Index = () => {
- return (
- <Main
- headerTitle={getHeaderTitle({type: 'generic-rotate'})}
- pageTitle={getPageTitle({type: 'generic-rotate'})}
- />
- );
+ return <Main routeAction={action} />;
};
export default Index;